Aurentaico
Hello @thiagoralves, I am trying to add new function blocks to OpenPLC editor and I got some errors. 

I tried these steps. I could'nt find how to create an .st file without body. I create a new program you can see it in the photo.
[203128%2F8771782%2Fmceclip0]
I added new function block. And choose language as FBD.
[203128%2F8771783%2Fmceclip0]
When I add the variables as in photo. I got an error named as the No body defined in "STM32CAN_CONF" POU but I don't know how to create a body for CAN communication. I am planning to handle it in code part.
[203128%2F8771791%2Fmceclip0]

Can anyone help me about it? How can I add a custom function block without body or which body should I use? I read adding new blocks to openplc's library but I stuck at the beginning. 
Reply 0 0
thiagoralves
You cannot create an empty program like this. You must add at least one instruction to the function block or program that you're creating.
Reply 0 0
Aurentaico
Does it matter what did I entered inside the function block because I am going to code it anyway. @thiagoralves
Reply 0 0
thiagoralves
I usually like to add as much code as I can to the function block because that will be converted to C anyway by the compiler, so it saves me work and headache of dealing with IEC variables in C. So things like input validation (if input is out of range set error output), keeping state, logic, etc are some good things to add there in Structured Text or your favorite IEC language. Then you just fill in the bowels of it with C.
Reply 0 0
Aurentaico
Okay thank you so much @thiagoralves. If there is a change could you share the logic behind the ARDUINOCAN function blocks I found the xml codes and the other codes about arduinocan I am planning to copy it for STM32 family with different CAN library that's why I need to understand how can I create my function blocks like ARDUINOCAN. I am trying to make it for STM32 family.  I have one more question what is that languages where can I learn about them?
Reply 0 0
Aurentaico
Hello @thiagoralves could you give me more informations when you are available this is my task at work and I need to do it as soon as possible?
Reply 0 0
thiagoralves
I don’t know how the ARDUINOCAN blocks work. I did not create them. It was someone inside Arduino that created them and added into OpenPLC sources.
 
About the IEC languages, there are five of them. But if your goal is to write custom blocks I would say focus on Structured Text. It is quite similar to C and Pascal. You can find information about these languages on books and articles online, and on manuals for other PLC vendors compatible with IEC 61131-3 like Codesys, beckhoff, Siemens TIA Portal, etc… Particularly on ST, I usually go after this vendor’s manual:  https://www.fernhillsoftware.com/help/iec-61131/structured-text/index.html
Reply 0 0
Aurentaico
Hello @thiagoralves,

I manage the add STM32CAN blocks and I manage the coppy arduinocan function blocks but I got this error that I mentioned before. [203128%2F8773123%2Fmceclip0]
Could you check the python version because I thing thats the problem. 
Reply 0 0
thiagoralves
No, the problem is because your implementation is incomplete. You must add references to those missing functions at the Editor’s MatIEC according to the documentation here:  https://autonomylogic.com/docs/3-3-adding-new-blocks-to-openplc-editors-library/
Reply 0 0
Aurentaico
No, the problem is because your implementation is incomplete. You must add references to those missing functions at the Editor’s MatIEC according to the documentation here:  https://autonomylogic.com/docs/3-3-adding-new-blocks-to-openplc-editors-library/
Okay @thiagoralves I am going to check again but I got same error when I tried to use arduinocan blocks still got same error but this time it is undefined referance to 'init_arduinocan' and 'write_arduinocan'
Reply 0 0
thiagoralves
Exactly. This means that the functions 'init_ardunocan' and 'write_arduinocan' are not defined in the Editor's simulator MatIEC. In your case, since you're doing your own implementation from scratch, you must define your functions as well.
Reply 0 0
thiagoralves
Here is the commit where Arduino brought in all the Arduino CAN code on the old Python 2 editor: https://github.com/thiagoralves/OpenPLC_Editor/commit/a8c4f052fb36ade6f072055d0b0bf4e0b336cbc3
Reply 0 0
Aurentaico
Hi again @thiagoralves, 

I checked the previous repo that you send and also I check it with DS18B20 everything is same. I add my function block in arduino text file like arduinocan or cloud or ds18b20. Is there any difference that can cause this If you want I can upload the photos where did I add the functions and the other stuff. My code is same with https://github.com/thiagoralves/OpenPLC_Editor/commit/a8c4f052fb36ade6f072055d0b0bf4e0b336cbc3 this repo just named as STM32CAN thats all. I add it in python code also. I am adding the photos in attachement could you check them please? Or could you fix the error for arduinocan.[203128%2F8773197%2Fmceclip0]
Reply 0 0
thiagoralves
I took a quick look at the Arduino implementation of those blocks. Indeed their implementation is incorrect, that's why the blocks don't work. On the simulator MatIEC (the one at OpenPLC_Editor/matiec/lib/C) you should not have any function declaration or implementation, as those blocks are architecture specific and should be defined in the Arduino MatIEC only. As it is stated in the documentation I sent you earlier, for blocks like those, the simulator MatIEC implementation must be blank (dummy), just to allow the compiler to compile. In other words, the blocks won't work on the simulator - you should expect that as the block is for Arduino boards, not for your PC - it will just be empty. I'm pushing the changes that will make the code compile at least. If the blocks will work in fact on the Arduino board, I don't know.
Reply 1 0
thiagoralves
Reply 1 0
Reply