LoconetServiceStart Method |
Namespace: RRAutoLib.Loconet
Note: In this example the RxPacket method is executed on the UI thread, because we passed its dispatcher to the SyncContext property.
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