granitesmasher has asked for the wisdom of the Perl Monks concerning the following question:

I am starting a project where I am using CANBUS connected actuated valves. I can operate the valves in Windows using the USBTinViewer and Thomas Fischl's CANBUS adapter. I can also operate the valves in Linux using can-tools (candump and cansend) which are based on SocketCAN and some cheap Chinese MCP2515 based interfaces. This is my starting point.

I want to write my application in Perl on Linux because that is the language and environment I enjoy and I will use the MCP2515 interface because it is cheap and supported. End result of the whole project is the automation of a solar radiant heating system and the valves will dynamically control the zoned hot water flow through the Pex tubing in my floors.

What I cannot find is an example of a Perl script using SocketCAN. There was one mention on the Web of an IO::Socket::CAN module being developed but I cannot find this or any module on CPAN for using SocketCAN or anything CANBUS for that matter. What would I have to do to use SocketCAN in Perl? Would I need to develop a new module? If so, how does one go about this?

Another option I see is to use the socketcand daemon (which I just found and started reading about while writing this post) and connect to this daemon using Perl. Would that be a good or maybe even the best option? Please help to send me down the right path.

Steve

  • Comment on SocketCAN - Anyone been there? Where do I start?

Replies are listed 'Best First'.
Re: SocketCAN - Anyone been there? Where do I start?
by afoken (Chancellor) on May 03, 2017 at 05:48 UTC

    No experience with SocketCAN, but hopefully a good guess: SocketCAN is basically a socket (see Wikipedia article), but with a new protocol family, CAN. Perl can work fine with sockets, you "just" need to find a way to create a CAN socket instead of an IPv4, IPv6, or Unix domain socket. The Wikipedia article contains a very stripped down example in C that sets up a CAN socket. A little bit of messing with pack and unpack should be sufficient to call socket with the parameters required for a CAN socket. Reading from and writing to CAN devices requires another round of pack and unpack. Required constants and structures should be in linux/can.h and linux/can/raw.h.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: SocketCAN - Anyone been there? Where do I start?
by karlgoethebier (Abbot) on May 03, 2017 at 06:46 UTC
    "...Anyone been there?"

    Sorry, no. But let me add some links for the uninitiated: CAN Bus, Valve Actuator, MCP2515 Interface.

    BTW, what is this project about? Cruise Missile, UAV, the ultimate fly fishing reel or perhaps some high tech airgun ;-)

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    Furthermore I consider that Donald Trump must be impeached as soon as possible

      BTW, what is this project about?

      The OP tells:

      End result of the whole project is the automation of a solar radiant heating system and the valves will dynamically control the zoned hot water flow through the Pex tubing in my floors.
      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

        He,he! I guess that you actually wanted to say something like: "Reading (the whole post) helps, Karl!". Thanks for saying it so kind. Best regards, Karl

        «The Crux of the Biscuit is the Apostrophe»

        Furthermore I consider that Donald Trump must be impeached as soon as possible