Skip to content

jazzman55/z21-lan-client

Repository files navigation

Z21 LAN Client

.NET Core & nanoFramework library for communication with Z21 DCC command station.

Description

  • Based on Z21 LAN Protocol Specification
  • Uses UDP for network communication to Z21
  • Not all features of Z21 protocol are implemented, however you can drive trains and do most useful things on model railway :)

Notes

Due to code sharing between .NET Core and nanoFramework implementation, some nice C# language features had to be sacrificed (like generics).

Usage

nanoFramework:

WifiNetworkHelper.ConnectDhcp(Ssid, Password, requiresDateTime: false);

//Create client instance
var client = new Z21CommandStation(new NanoUdpClient(new DebugLogger(nameof(NanoUdpClient))), new DebugLogger(nameof(Z21CommandStation)));

//Subscribe to received messages
client.LocoInfoReceived += Client_LocoInfoReceived;
client.StatusChangedReceived += Client_StatusChangedReceived;
client.SystemStateChangedReceived += Client_SystemStateChangedReceived;

client.Connect("192.168.4.111");

//Drive train
client.Send(new SetLocoDrive(3, Direction.Forward, 10));

[...]

private static void Client_LocoInfoReceived(object sender, EventArgs e)
{
    var data = e as LocoInfoEventArgs;
    Debug.WriteLine($"{data.Address} {data.Direction} {data.Speed}");
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages