arumade1990
In the past I've used the arduino extension with ladder logic and Open PLC with the ESP Now protocol with great success. However, when trying to use it in v4 I'm having some weird issues I can't quite figure out.
 
The main error I'm getting is:
 
[12-03-26 10:00:02] [ERROR]: Compilation failed with code 1
[12-03-26 10:00:02] [ERROR]: C:\Users\bigbl\Desktop\OpenPLC Projects\Arcade Logic\Stepper Motor Test v4\build\ESP32 WROOM\examples\Baremetal\c_blocks_code.cpp:60:25: error: expected ')' before '->' token
[12-03-26 10:00:02] [ERROR]: 60 | #define HORZ_OUT (*(vars->HORZ_OUT))
[12-03-26 10:00:02] [ERROR]: | ~ ^~
 
 
What I've tried so far:
 
Updating to the latest OpenPLC version.
Adding the function block I/O variables into the global resources list.
Changing the name of the variable. (Thought I may have accidentally invoked something in the backend as a bug.)
Commenting out the variables to see if it makes a difference since I think I'm able to call the variable directly from the table.
 
What made it compile:
 
Removing the c++ function block altogether and try to compile. (This successfully compiled and uploaded to the controller)
 
 
I've also tried variations on these for the last two days and have gotten essentially nowhere.
 
I've attached the .zip file of my project and the and .txt of the console log. for reference.
 
If you or someone could take a look at the project I'd really appreciate it.
 
Also this is a work in progress, so the logic is still pretty messy and I apologize. I just need it to compile.
Reply 0 0
thiagoralves
A few issues:
  1. You have several duplicated variables definitions for HORZ_OUT and VERT_OUT. Remove all duplicate definitions (on the C code, on Resources as global, etc) and leave them defined only on the variables table of the block
  2. PLC variables defined in the variables table are only accessible from setup() and loop() functions. You're using them on the OnDataRecv callback and that's why the code breaks. You can declare a local C variable for the callback and then synchronize this local C variable with the block variable on the block loop() function.
Reply 0 0
arumade1990
Oh ok! I see now. That makes sense. I didn't realize they were only accessible from the setup() and loop() sections. That shouldn't be too bad to fix then.
 
And by duplicate variables of the two you mentioned, do you mean to just remove the declaration altogether (as well as the other locations you mentioned) where I have it before the setup() and other functions then only call in by name once I need it in either the setup() or loop() since its only available to the PLC code there?
 
Just want to make sure I understand it's functionality correctly.
 
Also just a side note, the way these C++ extensions are implemented is a really slick idea and once I get the hang of it, it's going to be indispensable. Honestly I don't know why other mainstream PLC manufacturers don't do this. I work with Allen Bradley PLCs on a daily basis (Toyopuc a bit too), and there are times where it would be handy to just write a block in c++ to do something.
Reply 0 0
thiagoralves
And by duplicate variables of the two you mentioned, do you mean to just remove the declaration altogether (as well as the other locations you mentioned) where I have it before the setup() and other functions then only call in by name once I need it in either the setup() or loop() since its only available to the PLC code there?
Yes. Remove everything and leave only one declaration of the variable on the variable table of the C block. No need to declare again in the C body, neither on Resources or globals.
Honestly I don't know why other mainstream PLC manufacturers don't do this.
Great question. I was about to say that the reason is because they are too “old school”, but actually C was invented in 1973…
Reply 1 0
arumade1990
Yes. Remove everything and leave only one declaration of the variable on the variable table of the C block. No need to declare again in the C body, neither on Resources or globals.
 
Great question. I was about to say that the reason is because they are too “old school”, but actually C was invented in 1973…
Awesome. Thank you!
 
And I bet that in the coming decade or so we may finally start to see something like this become more mainstream as younger generations begin to enter this field. However this project with OpenPLC is definitely on the cutting edge of that in my opinion since it offers a unique and incredibly useful feature.
Reply 0 0
arumade1990
Yes. Remove everything and leave only one declaration of the variable on the variable table of the C block. No need to declare again in the C body, neither on Resources or globals.
 
Great question. I was about to say that the reason is because they are too “old school”, but actually C was invented in 1973…
Hey just wanted to write back that I followed what you said and everything uploaded perfectly fine on the first go. I think my code is slightly broken, but thats a whole other thing altogether lol.
 
Thanks again!
Reply 1 0
Write a reply...
Reply