Tellurian.Trains.Adapters.LocoNet 1.8.0

Prefix Reserved
dotnet add package Tellurian.Trains.Adapters.LocoNet --version 1.8.0
                    
NuGet\Install-Package Tellurian.Trains.Adapters.LocoNet -Version 1.8.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Tellurian.Trains.Adapters.LocoNet" Version="1.8.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tellurian.Trains.Adapters.LocoNet" Version="1.8.0" />
                    
Directory.Packages.props
<PackageReference Include="Tellurian.Trains.Adapters.LocoNet" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Tellurian.Trains.Adapters.LocoNet --version 1.8.0
                    
#r "nuget: Tellurian.Trains.Adapters.LocoNet, 1.8.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Tellurian.Trains.Adapters.LocoNet@1.8.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Tellurian.Trains.Adapters.LocoNet&version=1.8.0
                    
Install as a Cake Addin
#tool nuget:?package=Tellurian.Trains.Adapters.LocoNet&version=1.8.0
                    
Install as a Cake Tool

Tellurian.Trains.Adapters.LocoNet

A .NET adapter for LocoNet-based command stations via serial port, TCP (LoconetOverTcp), or UDP multicast, providing a high-level API for locomotive control, accessory switching, and decoder programming.

Features

  • Locomotive Control (ILoco): Speed, direction, function control (F0-F12), and state query
  • Accessory Control (IAccessory): Set and query accessory states
  • Turnout Control (ITurnout): Convenient throw/close/off operations for turnouts
  • Decoder Programming (IDecoder): CV read/write operations on the programming track

Usage

// Create serial port adapter
var serialPort = new SerialPortAdapter("COM3", 57600);

// Create LocoNet framer
var framer = new LocoNetFramer();

// Create communication channel
var channel = new SerialDataChannel(serialPort, framer, logger);

// Create adapter
await using var adapter = new Adapter(channel, logger);

// Start receiving
await adapter.StartReceiveAsync();

// Control a locomotive
var address = Address.From(999);
var drive = new Drive
{
    Direction = Direction.Forward,
    Speed = Speed.Set126(50)
};
await adapter.DriveAsync(address, drive);

// Query current locomotive state from the command station
var info = await adapter.GetLocoInfoAsync(address);
if (info is not null)
{
    // Returns speed, direction, and function states F0-F8
    // (F9-F28 are not available via LocoNet slot data)
    Console.WriteLine($"Speed: {info.Speed.CurrentStep}, Direction: {info.Direction}");
}

// Control a switch
var switchAddress = Accessories.Address.From(1);
await adapter.SetThrownAsync(switchAddress);

Slot Management

LocoNet uses a slot-based architecture where each locomotive is assigned to a slot (0-119). This adapter handles slot management automatically:

  1. When you control a locomotive, the adapter requests a slot for the address
  2. The slot assignment is cached for subsequent operations
  3. Slots are automatically managed for the lifetime of the adapter

Notifications

Subscribe to receive state change notifications:

adapter.Subscribe(new NotificationObserver());

class NotificationObserver : IObserver<Notification>
{
    public void OnNext(Notification notification)
    {
        // Handle notification
    }

    public void OnError(Exception error) { }
    public void OnCompleted() { }
}

Transport Options

The adapter works with any ICommunicationsChannel. Choose the transport that matches your hardware:

// Serial — direct connection via LocoBuffer-USB
var channel = new SerialDataChannel(new SerialPortAdapter("COM3"), new LocoNetFramer(), logger);

// TCP — LoconetOverTcp (LbServer, JMRI, Rocrail on port 1234)
var channel = new TcpLocoNetChannel(new TcpStreamAdapter("192.168.1.100", 1234), logger);

// UDP — loconetd (multicast 225.0.0.2, listen 4501, send to gateway on 4500)
var udpAdapter = new UdpLocoNetAdapter(
    IPAddress.Parse("225.0.0.2"), 4501,
    new IPEndPoint(IPAddress.Parse("192.168.1.50"), 4500));
var channel = new UdpLocoNetChannel(udpAdapter, logger);

// UDP — GCA101 LocoBuffer-UDP (multicast 224.0.0.1, port 1235)
var gca101 = new UdpLocoNetAdapter(
    IPAddress.Parse("224.0.0.1"), 1235,
    new IPEndPoint(IPAddress.Parse("192.168.0.200"), 1235));
var channel = new UdpLocoNetChannel(gca101, logger);

Requirements

  • LocoNet interface connected via serial port, TCP server, or UDP multicast gateway
  • .NET 10.0 or later
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.8.0 169 4/17/2026
1.7.15 124 4/16/2026
1.7.14 114 4/16/2026
1.7.13 117 4/16/2026
1.7.12 121 4/16/2026
1.7.11 127 4/15/2026
1.7.10 117 4/15/2026
1.7.9 122 4/15/2026
1.7.8 118 4/15/2026
1.7.7 121 4/15/2026
1.7.6 129 4/15/2026
1.7.5 118 4/15/2026
1.7.4 126 4/15/2026
1.7.3 237 3/28/2026
1.7.2 125 3/28/2026
1.7.1 129 3/27/2026
1.7.0 144 3/16/2026
1.6.1 143 2/22/2026
1.6.0 125 2/19/2026
1.5.0 130 2/11/2026
Loading failed