kortenbach
How can I build (binary) function-blocks that contain (hidden) c-code?
If this would be possible then people could write blocks that perform complex functions like:
- http server
- serial communication
- bluetooth
- Watchdog triggering
- etc.
Maybe this is possible by using structured text?
Reply 1 0
Nemo
Hi. It is written above that the control program written in LD/ST/FBD in OpenPLC is not actually executed on the MCU (for example, Arduino Mega).
The MCU board will only work for input/output of information from the control object.
My PC or other host under Windows/Linux will work as a PLC, but not the Arduino board (or another one).
Do I understand correctly?
Is that right?
Reply 0 0
thiagoralves
That information is outdated. Current version of the editor is capable of programming the board to run independently of another host.
Reply 0 0
kortenbach
Hi Thiagor,
 
Did you make any progress to get c / c++ running inside an FB?
That would be sooo nice...
 
Bert
Reply 0 0
thiagoralves
You can write C code in Structured Text using pragmas. Anything you write inside { } is considered C code and is totally skipped from the ST compiler. Check the random number generator example to get an idea of how that works
Reply 0 0
Nemo
That information is outdated. Current version of the editor is capable of programming the board to run independently of another host.
Thank you, this is good news.
Reply 0 0
kortenbach
Hi Thiagor,
 
"Anything you write inside { } is considered C code"
Does this mean that I can make an FB that encapsulates functionality for interacting with any library (I2c, SPI, serial ports, ethernet etc)?
Last time we spoke about this, you mentioned that this was not possible due to the fact that the "ladder compiler" doesn't compile c++. only c.
I was wondering if that has changed in the mean while.
 
Bert
Reply 0 0
Nemo
Page  https://autonomylogic.com/docs/3-3-adding-new-blocks-to-openplc-editors-library/  describes the process of adding a new function block to the Open PLC library. Including for a block written in C/C++.
Is this information relevant?
Reply 0 0
kortenbach
Although relevant, the method described is quite complex. Just putting the code between {} would be so much easier.
Reply 0 0
thiagoralves
Yes, that's still the same. The code inside { } is just C and can only use libraries that are already included. You cannot add a library inside { }. However, I'm working on an Arduino extension that will allow you to add Arduino sketches to your PLC program. This will bring a lot of flexibility to the programming.
Reply 2 0
kortenbach
Nice! That would make OpenPLC so much more versatile!
Reply 0 0
Nemo
Yes, that's still the same. The code inside { } is just C and can only use libraries that are already included. You cannot add a library inside { }. However, I'm working on an Arduino extension that will allow you to add Arduino sketches to your PLC program. This will bring a lot of flexibility to the programming.

That would be great. The fact is that some tasks are more convenient (clearer) to solve on IEC 61131-3. And some tasks require programming in C/C++. Open PLC can become a universal tool not only for Arduino. Thank you for your work.

Reply 1 0
kortenbach
Just thinking... One could even make a dynamic HAL instead of the static one currently used. If one would create an FB that has the physical IO's one needs as it's in-and outputs.  All the code for accessing the physical IO would reside inside this FB...
Or a webserver in an FB with in- and outputs interacting with the ladder program...
Endless possibilities :-)
Reply 0 0
thiagoralves
I did it! Update your editors and check out the new Arduino extension feature 🙂
Reply 1 0
kortenbach
Do you mean that now it's actually possible to use Arduino (C++) code inside of an FB? So you can just import the standard libraries for any kind of sensor? All by just using {}?
Reply 0 0
thiagoralves
No, better than that (in my opinion). Now you can create an Arduino sketch that runs in parallel with your PLC programs. Variables created in the variable table at your Arduino sketch are shared with your PLC programs. Then you can go about building your PLC logic, and when you need anything from the Arduino (C++) side just access the shared variables.
 
The update comes with several examples of the functionality. Update your editor and check the examples.
Reply 4 0
Reply