Starts the Loconet service and connects to the serial port.

Namespace: RRAutoLib.Loconet
Assembly: RRAutoLib (in RRAutoLib.dll) Version: 1.4.4420.16901

Syntax

C#
public void Start()
Visual Basic
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 context to the SyncContext property.

CopyVB.NET
Imports RRAutoLib.Loconet
Imports RRAutoLib.Common

Public Class Sample

    Private WithEvents _objLoconetService As New LoconetService

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

        'the creation of the SyncContext object on the UI thread allows events 
        'coming from the Loconet service to be synchronized back to this thread
        _objLoconetService.SyncContext = New SyncContext()

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

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

    Private Sub RxPacket(ByVal objPacket As Packet) Handles _objLoconetService.RxPacketOnSyncThread
        'display Loconet events
        Console.WriteLine(objPacket.Description)
    End Sub

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

End Class

See Also