LocoMotion – the build : CS3 *UPDATED INFO*

I finally unraffeled the “mistery” of communicating with the CS3.
This page is dedicated to all this information 🙂

First of all, both CS2 and CS3 speaks the same language. They both use the CANbus to setup communication between different components, and even use the CANbus protocol over TCP !
Here is an English version of the official Märklin cs2CAN-Protokoll document

The CS3 does have a few tricks upon it sleeve, that can be accessed via a browser on a pc/tablet/smartphone.
Simply open a browser, and type, eeh voila !
( needs to be replaced by the IP-address of your CS3, when connected to your network)

URLExplanation front page of the CS3 Web file contains a list of all defined locomotives, with address, loc-image, functions etc …
See page 50 in the above document. all info about magnet decoders and adresssing.
See page 53 in the above document. of the magnet decoders, and their location.
See page 55 in the above document. is the description of the switchboard itself.
See page 57 in the above document. the lokomotive.cs2, a description of the locomotive image is included. If you take this name, and replace “picture” in the left URL, you will have a direct link to the icon of the actual image of the locomotive. X by the icon number you need
Numbers go from 0 to 112
For numbers from 150 on, you should deduct 128 to get the correct icon. = white / GE + yellow / GR = gray = Active / I = Inactive

Communication via network can be done by setting up a TCP connection to port 15731 of the CS3.
For incoming data, the data is grouped by 13 bytes. (data start with index 0, last index is 12)
(So, all data that is longer or shorter then 13 bytes, should be ignored)
All byte-definitions are the same, as in the “pure” CAN-bus communication.
Not used bytes, need to be send as 0x00.

Byte 0 = Priority
Byte 1 = Command
Byte 2 & 3 = Hash (use 0x47 & 0x11 or 0x2f & 0x6c) see page 49 for hash calculation)

Some examples (check the protocol description file, above):

Data (index)Result
1 = 0x00 / 9 = 0x00STOP
1 = 0x00 / 9 = 0x01GO
1= 0x00 / 1= 0x08Speed change (next bytes = speed itself, check document)
0 = 0x00 / 1 = 0x0A Direction change (0x00 and 0x01 in byte 10, indicate direction)
0 = 0x00 / 1 = 0x0CFunction key (next bytes indicate function index and value)
0 = 0x00 / 1= 0x16 (0x17)solenoids and other decoder items

This table should get you started !
Sending data back, uses the same data-format.

The following piece of Python code, listens to incoming data, and prints the hex value of each byte on the screen. Next,
it sets a solenoid to the left, waits one second, and turns it back to the right, and starts listening again for incoming data.

import socket
import sys
import time

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

while True:
    data = sock.recv(13)
    if data:
        if (data[1] == 0x00 and data[9] == 0x00):
        if (data[1] == 0x00 and data[9] == 0x01):
        if (data[0] == 0x00 and data[1] == 0x08):
            print("Speed Change")
        if (data[0] == 0x00 and data[1] == 0x0A):
            print("Direction change")
        if (data[0] == 0x00 and data[1] == 0x0C):
            print("Function key")

        for x in range(13):
            print("0x%02x" % data[x],end="|")

        tmp = (b"\x00\x16\x2f\x6c\x06\x00\x00\x30\x00\x01\x01\x00\x00")

        tmp = (b"\x00\x16\x2f\x6c\x06\x00\x00\x30\x00\x00\x01\x00\x00")

This entry was posted in Blog, LocoMotion, Railroading. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *