24/7
Thiago, Great work on openPLC! Just got back from DEF CON and noticed I missed your presentation!  I'd like to set up an openPLC with a PiCAN shield on a Raspberry PI for a project and a talk.  Do you know of any starter code I can use to add a new canbus.cpp file in addition to modbus.cpp?

Since the Raspberry PI uses socketCAN natively, I thought maybe I can use portions of this code adapted to look similar modbus.cpp:  https://github.com/carloop/carloop-library/blob/master/examples/socketcan_serial/socketcan_serial.cpp

Do you think that is a good starting point?

Thanks!
thiagoralves
Hi there! It should be possible to use that code as a start. The right path to follow if you're using OpenPLC v3 is to create a task (thread) on the main.cpp file for your CAN interface. The task will only call the main function on your canbus.cpp file, which should run forever. Also, you will need to add a service on the interactive_server.cpp file to be able to stop and start your CAN task. Then, when OpenPLC quits, it will be able to gracefully stop all running tasks before killing itself. If you don't create this service on interactive_server, your task will force quit when OpenPLC quits, which can cause problems. Just copy the code from the modbus server and modify accordingly for your CAN task.
Reply 0 0
skv
BTW Beremiz (project PLCOpenEditor comes from) does have CANOpen support. See canopen_master and canopen_slave examples.
But because you've just came from DEFCON, I think you probably want to hack on the car. :-)
Reply 0 0
24/7
skv wrote:
BTW Beremiz (project PLCOpenEditor comes from) does have CANOpen support. See canopen_master and canopen_slave examples.
But because you've just came from DEFCON, I think you probably want to hack on the car. :-)

@skv thanks so much, for referring me to the Beremiz project!  I am definitely interested in CANOpen support and if it works natively, I would love to use just that.  I am not at all familiar with PLCOpenEditor so I'm not sure how to leverage that Bitbucket repo

Thiago, SKV, I found this very exciting canfestival module in the PLCOpen Editor zip file: https://bitbucket.org/automforge/beremiz/src/52afa2dec4fb89ec2ebb3284a618ad3852b71d84/canfestival/?at=default

If i just run that, would it work in OPenPLC?  I'm a total n00b so any help is welcome!
Reply 0 0
skv
24/7 wrote:

@skv thanks so much, for referring me to the Beremiz project!  I am definitely interested in CANOpen support and if it works natively, I would love to use just that.  I am not at all familiar with PLCOpenEditor so I'm not sure how to leverage that Bitbucket repo.


PLCOpenEditor is part of Beremiz project. Beremiz is PLC IDE and runtime with a lot of extensions.
You can read more about on Beremiz website.


24/7 wrote:

If i just run that, would it work in OPenPLC? I'm a total n00b so any help is welcome!

Thiago, SKV, I found this very exciting canfestival module in the PLCOpen Editor zip file


No, it will not work in OpenPLC. To run extension you have to use Beremiz IDE and not just PLCOpenEditor.
Beremiz IDE = PLCOpenEditor + extensions + compile tools + PLC control/communication/debugging.
To use Beremiz IDE you need hardware platform where you can run Beremiz runtime.

The easiest way is to use some Linux capable single board computer and of course for CANOpen you need supported by Linux kernel CAN interface.
What hardware you are going to use?
Reply 0 0
24/7
skv wrote:

The easiest way is to use some Linux capable single board computer and of course for CANOpen you need supported by Linux kernel CANinterface.
What hardware you are going to use?

I have a working version of OpenPLC v3 running on a Raspberry PI with a PICAN2 Shield.

skv wrote:

No, it will not work in OpenPLC. To run extension you have to use Beremiz IDE and not just PLCOpenEditor.

To make sure I understand you correctly, do you mean that if I follow the instructions from http://www.openplcproject.com/plcopen-editor
and download all python dependencies on my Raspberry PI, I will not be able to compile canfestival into an executable for OpenPLCv3?

Goal for my talk
Show a demo of a Raspberry PI + PICAN2 Shield running OpenPLCv3 and being able to send CAN messages using CANOpen protocol from Raspberry PI. What is the simplest way to achieve this?
Reply 0 0
thiagoralves
24/7 wrote:

To make sure I understand you correctly, do you mean that if I follow the instructions from http://www.openplcproject.com/plcopen-editor
and download all python dependencies on my Raspberry PI, I will not be able to compile canfestival into an executable for OpenPLCv3?

Goal for my talk
Show a demo of a Raspberry PI + PICAN2 Shield running OpenPLCv3 and being able to send CAN messages using CANOpen protocol from Raspberry PI. What is the simplest way to achieve this?


PLCOpenEditor is the base of both Beremiz and OpenPLC projects, but in the end, Beremiz and OpenPLC are different things. Beremiz has its own runtime, which is different than OpenPLC runtime. I don't know exactly how to work with Beremiz because, unfortunately, most of their documentation is in Russian. But apparently you will have to install just Beremiz runtime on your Pi (instead of running OpenPLC v3 runtime), and install Beremiz IDE on your computer (instead of running plain PLCOpenEditor). Beremiz IDE looks for a device running the runtime on the network. Once it finds one, you can decide to connect to it. Then you can just create your program on Beremiz IDE, add CAN extensions to it, and hopefully it will just work.
Reply 0 0
skv
24/7 wrote:

To make sure I understand you correctly, do you mean that if I follow the instructions from http://www.openplcproject.com/plcopen-editor
and download all python dependencies on my Raspberry PI, I will not be able to compile canfestival into an executable for OpenPLCv3?

Goal for my talk
Show a demo of a Raspberry PI + PICAN2 Shield running OpenPLCv3 and being able to send CAN messages using CANOpen protocol from Raspberry PI. What is the simplest way to achieve this?


As Thiago said, canfestival and Beremiz CANOpen extension will not work with OpenPLCv3 runtime. You have to use Beremiz for that.
canfestival - is free software CANOpen stack. CANOpen is protocol running on CAN bus. CANOpen is high level protocol, it uses low level CAN messages for communication.
You will not be able to send random CAN messages using CANOpen. Do you want to use CANOpen or low level CAN messages or you just want to show CAN bus working on RPi3?


Thiago, there are a lot of screencasts , and design documents about Beremiz in other languages (mostly English). See documentation section. I think it should be enough to start using Beremiz.
For questions as you know there is active mailing list.
But you are correct the best and comprehensive *user* documentation is so far in Russian. But this is not a problem actually in modern times.
It's pretty good readable IMHO using google or yandex translator: check it. This document contains some sections about INEUM's products, but we are preparing (almost ready, rst is already available) version described purely upstream Beremiz functionality.
Reply 0 0
24/7
skv wrote:

You will not be able to send random CAN messages using CANOpen. Do you want to use CANOpen or low level CAN messages or you just want to show CAN bus working on RPi3?


Hey SKV, sorry for the delay, I was on vacation.  I am pretty flexible, I already have a Raspberry PI sending raw CAN messages using the PI CAN 2 shield and can-utils.  My goal is to use OpenPLC to send CAN messages with as little modification as possible.  Since there seems to be a CANOpen module for Beremiz, I thought I could just "port" that to the OpenPLC runtime and start sending messages using that.  

Apparently, it is not that simple to install CAN festival on OpenPLCv3 runtime.  Do you have any ideas of an easy way to port CAN festival for OpenPLCv3?
Reply 0 0
thiagoralves
You don't have to port it to OpenPLC. You can use Beremiz instead of OpenPLC to send CANOpen messages. You will just have to find your way to work with Beremiz, skv might be able to help you with that.

But if you want to use OpenPLC, another route would be to integrate can-utils with OpenPLC runtime. It should be pretty straightforward, as OpenPLC already has 2 protocols it supports (Modbus and DNP3). You can just build your can-utils module alongside the Modbus and DNP3 modules on OpenPLC. Can I see your can-utils code that sends your CAN messages?
Reply 0 0
Jaya

Hello Thiago,
 digging this thread after years. So I do have a raspberry Pi 4 with gpio which I can control via open plc. I have a can bus HAT, which I would like to integrate with the OpenPLC platform. How could I establish a connection after making modifications with the interactive server and adding the can bus serial cpp? 

 I had worked mostly with PLC and it’s my first time with Raspberry Pi and Open PLC 

Reply 0 0
thiagoralves
If you follow the pattern of the modbus_master.cpp, you will have to add you own canbus .cpp code, call its initialization function from main.cpp and then build a web UI for it on the webserver (for configurations, parameters, etc) similar to what was done to Modbus on the Slave Devices tab. It is not a straightforward task
Reply 0 0
Robbudge

I was also looking for the same and possibly Ethernet IP. 


I have both connections working in Python so was considering a simple ModBus TCP to CanBus or EthernetIP python program. I could simply launch that on startup to act as a gateway. I already do the same with cloud reporting. 

man external Pyhton program that reads data from  OpenPLC then published to the cloud to be displayed in Grafana. 

The configuration address & cloud Tag are simply stored in an external file. 


obviously this approach would only work on a PI or similar. 

but certainly an option. 

Reply 0 0
thiagoralves
You could also use PSM to integrate your python Canbus or EthernetIP implementations directly to OpenPLC core. 
Reply 0 0
Robbudge

That did actually cross my mind but was concerned with the individual reads and writes to the PLC.
I was looking for a block read and write. 

An external python client could handle, what 128? Words per ModBus request ?? 

compared to PSM requesting single registers ??


Reply 0 0
Reply