logo Welcome, Guest. Please Login or Register.
June 24, 2019, 08:05:51 PM
Home Help Search Login Register
 News: You can search the forum for answers to your question in a previous discussion. Please click on the "Search" button above and enter the keyword to search. To get to the full discussion of a listed message, please click on the TITLE of the message listed in the search listing.

  Internet PLC Forum
  General
  Technical support
(Moderator: support)
  User written Modbus RTU example code
? previous next ?
Pages: [1] Go Down Reply Notify of replies Send the topic Print
   Author  Topic: User written Modbus RTU example code  (Read 88 times)
garysdickinson
Expert Member
****

Posts: 441



Old PLC Coder

View Profile E-Mail
User written Modbus RTU example code
« on: June 11, 2019, 08:22:29 PM »
Reply with quote

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 D*ckinson
 ModbusMaster_V2.PC6
« Last Edit: June 12, 2019, 02:25:56 PM by garysdickinson »
Report to moderator   Logged
garysdickinson
Expert Member
****

Posts: 441



Old PLC Coder

View Profile E-Mail
Slave PLC code for test
« Reply #1 on: June 11, 2019, 08:28:35 PM »
Reply with quote

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
 PLCTestPatterns.PC6
« Last Edit: June 19, 2019, 01:27:59 PM by garysdickinson »
Report to moderator   Logged
garysdickinson
Expert Member
****

Posts: 441



Old PLC Coder

View Profile E-Mail
Documentation
« Reply #2 on: June 11, 2019, 08:32:47 PM »
Reply with quote

This is the PDF version of the documentation.
 Simple_Modbus_RTU_Master_v2.pdf
« Last Edit: June 12, 2019, 02:28:05 PM by garysdickinson »
Report to moderator   Logged
support
Global Moderator
*****

Posts: 3090





View Profile WWW E-Mail
Re:User written Modbus RTU example code
« Reply #3 on: June 19, 2019, 11:14:39 AM »
Reply with quote

Thanks for the great contribution to the community!
Report to moderator   Logged

Email: support@triplc.com
Tel: 1-877-TRI-PLCS
garysdickinson
Expert Member
****

Posts: 441



Old PLC Coder

View Profile E-Mail
Re:User written Modbus RTU example code
« Reply #4 on: June 19, 2019, 01:45:06 PM »
Reply with quote

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
Report to moderator   Logged
Pages: [1] Go Up Reply Notify of replies Send the topic Print 
? previous next ?
Jump to: 


Login with username, password and session length

Powered by MySQL Powered by PHP Internet PLC Forum | Powered by YaBB SE
© 2001-2004, YaBB SE Dev Team. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!