Internet PLC Forum
General => Technical support => Topic started by: garysdickinson on June 11, 2019, 05:22:29 PM
-
I am presenting the code that I have been using for the last 5 years as an alternative to the TBASIC ReadModbus, ReadMB2, WriteModbus and WriteMB2.
This code is supports all possible Modbus function codes.
This code is non-blocking. The PLC does not lock up waiting for a response from the slave device.
This code is an example of a user written communication protocol
This code allows you to see both the Modbus response packet and every byte received from the Modbus slave. This allows you tremendous debug capability that is not available with the TBASIC Modbus support.
I will post the PLC code and the documentation in pieces to keep them under 200KB
Regards
Gary Dickinson
-
Variations of this Modbus RTU code is currently running 24/7 on over 40 PLCs. Some of these installations date back 5 years. This is why I am convinced that the code is reliable.
I extracted the Modbus RTU code out of running production code. I simplified this code for use as a demo.
I needed to test the demo code against a real Modbus RTU slave device. I decided to use a spare TRI PLC as the slave. This choice solved my my need to test the code and provided an opportunity to explain how the low-level TRI handles Modbus RTU requests.
This posting is the PLC program that I am running on the slave PLC. This code initializes the serial port on the slave and writes data patterns into DM[] and some of the PLC RELAYS.
The data patterns are used to help me verify that my code running on the master PLC is reading/writing the correct registers in the slave.
The slave PLC responds to the Modbus RTU requests using the TRI written firmware. My software on the slave PLC is NOT handling the Modbus requests.
Have fun,
Gary D*ckinson
-
This is the PDF version of the documentation.
-
Thanks for the great contribution to the community!
-
Thanks,
I try to periodically post PLC software that illustrates an approach to PLC programming that solves a complicated problem without a lot of programming.
As always, I invite people to use this or any other examples that I have posted.
Best regards,
Gary D*ckinson