A library to easily communicate with the ECoS command station.


import 'package:ecos_communicator/ecos_communicator.dart';
import 'package:ecos_communicator/src/connection/connectionSettings.dart';

void main() async {
  // Create a connection
  final connection = Connection(ConnectionSettings(address: ''));

  print('Create new locomotive');

  // Send a create request
  final reply = await connection.send(Request.create(10, {
    Argument.native('addr', '10'),
    Argument.string('name', 'Test'),
    Argument.native('protocol', 'DCC128'),

  // Get the id of the newly created locomotive
  final newId = int.parse(reply.entries.first.argument.value);

  print('New locomotive id: $newId');
  print('Set speed to 126');

  // Set speed of new locomotive
  await connection
      .send(Request.set(newId, {Argument.native('speedstep', '126')}));

  print('Delete created loco');

  // Send delete request
  await connection.send(Request.delete(newId));

  print('Deleted locomotive');

  try {
    // Send command which will result in an error
    await connection.send(Request.get(20000, {Argument.name('status')}));
  } on ReplyError catch (e) {
    print('ReplyError: $e');

  // Close the connection
  await connection.close();


The example can be run with

dart ecos_communicator_example.dart <ip address> [<id: 20000>].

Will only work on turnouts with 2 states (normal turnouts)

This will connect to the ECoS and present a cli interface. Updated on the turnout state will be printed in this way:

Switch: straight or Switch: curved

Usable commands:

  • s: Will switch the turnout
  • c: Will disconnect the listener on turnout updates
  • m: Will reconnect the listener on turnout updates
  • close: Will close the connection and stop the program

Features and bugs

Please file feature requests and bugs at the issue tracker.


This library supports the easy communication with the ECoS control station