Click or drag to resize

LoconetServiceStart Method

Starts the Loconet service and connects to the serial port.

Namespace:  RRAutoLib.Loconet
Assembly:  RRAutoLib (in RRAutoLib.dll) Version: 4.0.8678.28884
Syntax
Public Sub Start
Remarks
The Loconet service must be started before it can process packet transfers.
Examples
The following example performs the following:
  • Starts the Loconet service.
  • Sends a packet to turn on track power.
  • Listens for and displays incoming Loconet packets.

Note: In this example the RxPacket method is executed on the UI thread, because we passed its dispatcher to the SyncContext property.

VB
Imports RRAutoLib.Loconet

Public Class Sample

    Private WithEvents locServ As New LoconetService

    Public Sub Initialize()
        'set up serial communication parameters
        locServ.BaudRate = BaudRate._57600
        locServ.ComPort = 1
        locServ.FlowControl = True

        'pass the UI dispatcher to the LoconetService
        locServ.SyncContext = Dispatcher.CurrentDispatcher

        'start the Loconet service
        Try
            locServ.Start()
        Catch ex As Exception
            Console.WriteLine(ex.Message)
            Exit Sub
        End Try

        'send a power-on packet
        locServ.TxPacket(New PkSetPowerOn)
    End Sub

    Private Sub RxPacket(pk As Packet) Handles locServ.RxPacketOnSyncThread
        'display Loconet events
        Console.WriteLine(pk.Description)
    End Sub

    Public Sub Dispose()
        locServ.Stop()
    End Sub

End Class
See Also