ryannn
Hi ThiagoAlves,
I am considering a secondary development for OPENPLC on MicroController. Specifically, I want to add the functionality to read Modbus TCP/IP sensor data within the updateInputBuffers() function. This should be similar to the functionality in modbus_master.cpp in OPENPLC on PC.
I am using an Arduino DUE, and I understand that there is an ArduinoModbus library that provides Modbus Client functionality. I plan to use this library to implement the secondary development I mentioned.
Do you have any suggestions on this? For example, do you recommend using the ArduinoModbus library for this development? If not, what alternative methods would you recommend? Also, do you think there could be any issues with the idea of adding Modbus TCP/IP sensor data reading to OpenPLC on MicroController?
I look forward to your constructive feedback!
thiagoralves
In my opinion, the best way to implement Modbus master is to implement them on new function blocks that the user can call as needed. Implement it directly in the runtime code is cumbersome, hard to configure from a user perspective, and can cause slowdowns as read/write requests are sent every scan cycle.
Reply 0 0
ryannn
In my opinion, the best way to implement Modbus master is to implement them on new function blocks that the user can call as needed. Implement it directly in the runtime code is cumbersome, hard to configure from a user perspective, and can cause slowdowns as read/write requests are sent every scan cycle.
That makes sense, thank you for your advice.
Reply 0 0
ryannn
In my opinion, the best way to implement Modbus master is to implement them on new function blocks that the user can call as needed. Implement it directly in the runtime code is cumbersome, hard to configure from a user perspective, and can cause slowdowns as read/write requests are sent every scan cycle.
Hi Thiago,
I plan to follow what you mentioned and implement them in new function blocks. I also found your documentation on "3.3 Adding new blocks to OpenPLC Editor’s library" in the OPENPLC Documentation.
Now, my question is: I feel that the IEC 61131-3 languages do not support implementing the Modbus protocol stack, right? So, should I use the Arduino Extension to create the function block? For example, the TCP_CONNECT and other function blocks you have already implemented—were they created using the Arduino Extension to make the function block?
Reply 0 0
thiagoralves
You will have to use C to implement this on the function blocks. Ideally you should have the function blocks call library functions that perform the low-level protocol actions. Then the block can be portable to other platforms by just implementing the low-level calls.
Reply 0 0
ryannn
You will have to use C to implement this on the function blocks. Ideally you should have the function blocks call library functions that perform the low-level protocol actions. Then the block can be portable to other platforms by just implementing the low-level calls.
Do you recommend writing C code in Structured Text using pragmas, or fully utilizing the new Arduino extension feature to create the functional blocks I need?
Also, do you still have the prototypes of functional blocks like TCP_CONNECT? I think using them as a reference would be very helpful for me.
Reply 0 0
thiagoralves
You can’t use Arduino extension inside function blocks. It’s best to write C code directly instead of using pragmas. Most likely you will have to write code as an Arduino module (check for the modules folder inside Baremetal) and then make calls to the functions in the Arduino module from the C code in your function blocks.
Reply 0 0
ryannn
Oh, I see now—I misunderstood what you meant by the function block. Please forgive me for even forgetting about the modules folder inside Baremetal earlier. Thank you for the reminder, I think you’re right. I’ll look into it.😁
Reply 0 0
ryannn
You can’t use Arduino extension inside function blocks. It’s best to write C code directly instead of using pragmas. Most likely you will have to write code as an Arduino module (check for the modules folder inside Baremetal) and then make calls to the functions in the Arduino module from the C code in your function blocks.
Hi Thiago,
If I want to use the Arduino Ethernet Shield 2 on an Arduino DUE to implement both MODBUS Master and Slave simultaneously. Will there be any conflicts? Since both functionalities use the same hardware (Arduino Ethernet Shield 2) and the Ethernet.h library, I’m concerned that their respective network data might overwrite each other.
Reply 0 0
thiagoralves
This should not be an issue. Modbus master is a TCP client, while Modbus slave is a TCP server. And even if both of them were servers, you could still have them both as long as they operated in different ports.
Reply 0 0
ryannn
This should not be an issue. Modbus master is a TCP client, while Modbus slave is a TCP server. And even if both of them were servers, you could still have them both as long as they operated in different ports.
Okay, thank you!
Reply 0 0
Reply