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 http://192.168.123.45, eeh voila !
(192.168.123.45 needs to be replaced by the IP-address of your CS3, when connected to your network)
|http://192.168.123.45/||The front page of the CS3 Web|
|http://192.168.123.44/config/lokomotive.cs2||This file contains a list of all defined locomotives, with address, loc-image, functions etc …|
See page 50 in the above document.
|http://192.168.123.44/config/magnetartikel.cs2||Contains all info about magnet decoders and adresssing.|
See page 53 in the above document.
|http://192.168.123.44/config/fahrstrasse.cs2||Description of the magnet decoders, and their location.|
See page 55 in the above document.
|http://192.168.123.44/config/gleisbild.cs2||This is the description of the switchboard itself.|
See page 57 in the above document.
|http://192.168.123.44/app/assets/lok/picture.png||In 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.|
|http://192.168.123.44/fcticons/FktIcon_a_we_X.png||Replace 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.
|http://192.168.123.44/fcticons/FktIcon_a_ge_X.png||WE = white / GE + yellow / GR = gray|
|http://192.168.123.44/fcticons/FktIcon_i_we_20.png||A = 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):
|1 = 0x00 / 9 = 0x00||STOP|
|1 = 0x00 / 9 = 0x01||GO|
|1= 0x00 / 1= 0x08||Speed change (next bytes = speed itself, check document)|
|0 = 0x00 / 1 = 0x0A||Direction change (0x00 and 0x01 in byte 10, indicate direction)|
|0 = 0x00 / 1 = 0x0C||Function 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) sock.connect(("192.168.123.44",15731)) while True: data = sock.recv(13) if data: if (data == 0x00 and data == 0x00): print("STOP") if (data == 0x00 and data == 0x01): print("GO") if (data == 0x00 and data == 0x08): print("Speed Change") if (data == 0x00 and data == 0x0A): print("Direction change") if (data == 0x00 and data == 0x0C): print("Function key") for x in range(13): print("0x%02x" % data[x],end="|") print("*") tmp = (b"\x00\x16\x2f\x6c\x06\x00\x00\x30\x00\x01\x01\x00\x00") sock.sendall(tmp) print("left") time.sleep(1) tmp = (b"\x00\x16\x2f\x6c\x06\x00\x00\x30\x00\x00\x01\x00\x00") sock.sendall(tmp) print("rechts") time.sleep(1) connection.close()