Gleisbox on Raspberry Pi via CAN

Moderator: Moderators

Gleisbox on Raspberry Pi via CAN

Postby moritzmhmk » 06.02.2015, 12:08

Hi

I do currently set up my model railway and plan to use a Märklin Gleisbox connected to a Raspberry Pi running Rocrail.

Currently I have the Gleisbox connected to the Pi via a MCP2515 and MCP2562 as described at http://lnxpps.de/rpie/. I am using the can2udp software (from http://lnxpps.de/rpie/ as well) to use the CAN interface in Rocrail and did wonder if there would be interest in having support for using the CAN bus directly in Rocrail (currently we have UDP and CAN via Serial).

It shouldn't be much programming effort - in case someone from the developer team is interested in adding this, I did write a srcp server in python some time ago that did use the following class to connect to a Gleisbox via udp or can https://gist.github.com/moritzmhmk/c83ea57dd124ea79b997 which could be helpfull in figuring this out (especially the different self.can_frame_format values for udp and can).

PS how does one contribute to the project? On the github page it says "Forking this project is not permitted." :coding:
moritzmhmk
 

Re: Gleisbox on Raspberry Pi via CAN

Postby rjversluis » 06.02.2015, 12:17

Hi,
moritzmhmk wrote: and did wonder if there would be interest in having support for using the CAN bus directly in Rocrail (currently we have UDP and CAN via Serial).

directly supporting CAN is very hardware dependent and therefor not a good idea.
The UDP and Serial are OK and will work on all Platforms.
In short: I will not support this idea.
Best Regards, Rob.
:!: PS: Do not forget to attach the usual files.
:!: PS: Nicht vergessen die übliche Dateien an zu hängen.
[ macOS - Linux] - [ N: CBus - CAN-GCA ] - [ 0: RocNetNode - GCA-Pi ]
rjversluis
Site Admin
 

Re: Gleisbox on Raspberry Pi via CAN

Postby moritzmhmk » 06.02.2015, 13:23

rjversluis wrote:directly supporting CAN is very hardware dependent and therefor not a good idea.


On Linux the hardware dependence is managed by a kernel module / driver - the software will only see an interface "can0" just like "eth0" is for TCP/IP.
So one could use
Code: Select all
socket(AF_CAN, SOCK_RAW, CAN_RAW)

I have no idea how this works on windows ;)

If I find the time to implement this for linux how could I contribute this to Rocrail?

Where in the source code will I find the definition of what is offered in Rocview when choosing gbox or cs2 (currently ehternet and serial) - I found the cs2 and gbox implementations as well usocket.c but wasn't able to find the definition of available options :?
moritzmhmk
 

Re: Gleisbox on Raspberry Pi via CAN

Postby bertc3p0 » 06.02.2015, 16:28

Hi Moritz (?),

with can2udp you don't need to write any code if you setup the CAN as SockeCAN interface. It's already working fine with Rocrails mgbox using ethernet as interface. Thx to Berts and Robs awesome work. The benefit of using can2udp is, that you can split the Rocrail server and the can2udp "server". I have written the can2udp with low end systems in mind (low speed and small memory footprint). So the benefit of using CAN directly is not that huge.

BTW: can2lan aims to be even more like the CS2 CAN gateway. Try this with Rocrails mcs2 module when you also want to use M*rklin PC-Software and/or M*rklinApp at the same time.

Regards

Gerd
bertc3p0
 

Re: Gleisbox on Raspberry Pi via CAN

Postby moritzmhmk » 06.02.2015, 19:17

Hi Gerd,

I currently have time for my model railway and since http://moritzmhmk.de/srcp.js is quite usable already I was looking for another improvement of my setup and did write an web based Rocrail client which I use to display the layout fullscreen on the Pi [not published yet] and now thought about adding CAN support to Rocrail since I had that in my old srcp server which I replaced with Rocrail some time ago (my server didn't have automation etc... :P)

can2udp is working fine - I just thought that simplifying the setup would be nice and wanted to know if there is demand for such a feature. As it doesn't seem like that I will finish some other model railway related projects first ;)


Regards
Moritz
moritzmhmk
 

Re: Gleisbox on Raspberry Pi via CAN

Postby Richard-TX » 06.02.2015, 22:08

rjversluis wrote:directly supporting CAN is very hardware dependent and therefor not a good idea.
The UDP and Serial are OK and will work on all Platforms.
In short: I will not support this idea.


I agree with Rob. CAN bus, while it sounds like a good idea, really isn't. Using TCP/IP over Ethernet is much better. It is hard to beat 1 gigabit speeds.
Richard
Dallas/Fort Worth
Texas USA
Richard-TX
 

Re: Gleisbox on Raspberry Pi via CAN

Postby bertc3p0 » 09.02.2015, 11:19

Hi,
Richard-TX wrote:
rjversluis wrote:directly supporting CAN is very hardware dependent and therefor not a good idea.
The UDP and Serial are OK and will work on all Platforms.
In short: I will not support this idea.


I agree with Rob. CAN bus, while it sounds like a good idea, really isn't. Using TCP/IP over Ethernet is much better. It is hard to beat 1 gigabit speeds.

but there is an API called SocketCAN (using BSD-Sockets) which is quite easy to use. Most Linux CAN-Interfaces supporting this API and the number of CAN-Interfaces is growing. BTW: The SLCAN interface already supported by Rocrail is also supported by SocketCAN. For Linux that would mean only one CAN driver.

And that's why Moritz idea isn't that bad. Nevertheless you could use my can2udp or can2lan, which is the glue between Linux CAN interfaces and Rocrail.

@Moritz,

interesting project :-) Need to dig into it deeper ...

Regards

Gerd
bertc3p0
 


Return to DIY Hardware

cron