bob123456678 / TrainControl

Software to conveniently control & fully automate large Marklin CS2/CS3 layouts using your computer / keyboard. Designed for users with many trains and accessories where two knobs just aren't enough. Includes an extensive GUI and Java API.
GNU General Public License v3.0
18 stars 3 forks source link

Train Control interface CS3 with CBUS? #2

Open hicksan opened 2 months ago

hicksan commented 2 months ago

I am working on a G scale layout that has CS3 as its controller. We are adding a second unconnected circuit and some storage loops for each circuit, plus train-on-track detectors, train position sensors and servo point control. Rather than using the DCC/MFX route we are installing a MERG CBUS control bus for all the accessories and sensors. CBUS is pretty universal, based also on CAN BUS, with connections to PCs, Raspberry Pis or Arduinos, and can be remote operated using JMRI, for example. But it is not directly compatible with the Marklin system, so some kind of interface is needed.

What I would like to do is substitute these external sensors and accessories for the Marklin ones on the CS3 panel, which would be dummy icons only. That way if operated on the CS3 panel or in Train Control software it would instead trigger the CBUS event to operate the accessory. Similarly a train triggering a CBUS sensor would indicate on the CS3 panel as if an S88 input had been activated. JMRI offers limited connectivity to CS2 in being able to receive and send Marklin CANBUS events in HEX form. I do not know if this will work with CS3 but assume it probably will. I would ideally like to have Train Control in overall command, interfacing with both systems; CS3 and CBUS, and tying them together in the common GUI.

I am happy to do whatever coding for this, and your system looks like a perfect starting point, but would appreciate any help or pointers you might be able to offer as to where to start. Thank you.

bob123456678 commented 2 months ago

It should be possible to modify TrainControl to talk to CBUS or any other CAN interface. You would need to add a USB/CAN listener in addition to the current IP interface, and potentially make changes to the CS2Message class if you want to bridge messages between the two systems.

Attached is an example of how one user modified the software to connect to a USB CAN bus, to which the Marklin Mobile Station 2 can be directly connected- thus bypassing the CS3 entirely. The main change was to add the full CAN header on top of what the CS3 normally broadcasts over the network.

In the future, I could envision a choice of interface becoming a standard part of TrainCcontrol. It's just hard to test with so many different systems/interfaces out there. A good starting point might be a generic way to customize the interface, which is currently hard-coded to the Marklin one. That could then easily enable contributions from the community.

TrainControl_Changes.zip

hicksan commented 2 months ago

Thank you that is very helpful. I'll update you with progress once I get started.