Author Topic: How to make a single PLC respond as multiple Modbus RTU Slave Devices  (Read 13590 times)

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
I have run into the need to simulate multiple Modbus RTU devices while working on PLC projects.  

As an example one of my customers is using from 1 to 16 Modbus RTU pressure sensors and from 1 to 8 Modbus RTU totalizers. So, for him, I might need 24 Modbus devices in my office to be able to test his PLC code.

I have come up with a simple solution to the problem.  I am using a spare, cheap, single Nano-10 to emulate the behavior of all 24 devices.  Oh and while I am at it, I can program the Nano-10 to create all sorts of test patterns for the sensors to verify my PLC code.  

I simply wrote my own Modbus RTU code and asked the PLC to not respond to Modbus on the RS485 port.

I have attached a very simple PC6 file that shows how I emulate a single Modbus device. In this example I am emulating a Modbus connected motor speed controller. The reason I had to emulate this device is that my client didn't have a spare motor speed controller to loan me and even if he did, I didn't have the a way to power up the device.  My office is not wired for 460 VAC, 60 Hz, 3-phase power!

I'll post a bit of the ladder logic to pique your interest.

If you have any questions about this sort of thing, just ask.

You are more than welcome to use and hack up this code. Have at it!

Gary D*ickinson
« Last Edit: February 04, 2016, 06:50:25 PM by garysdickinson »

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:How to make a single PLC respond as multiple Modbus RTU Slave Devices
« Reply #1 on: February 04, 2016, 06:49:29 PM »
This is the whole ladder logic bit of the program.  The first few rungs are the simulation of the TECO N3 Inverter (motor speed control).  The other few rungs are the logic to support the Modbus RTU slave protocol.

There isn't much too it.

Gary D*ickinson

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:How to make a single PLC respond as multiple Modbus RTU Slave Devices
« Reply #2 on: February 05, 2016, 12:51:31 PM »
That is a very interesting application of using the TBASIC language to implement your own customized Modbus RTU protocol handler.

... I simply wrote my own Modbus RTU code and asked the PLC to not respond to Modbus on the RS485 port.

I think you are referring to using the SETPROTOCOL 1,10 to set the RS485 port to "NO PROTOCOL" so that it does not auto-respond to Modbus command, but instead allowing your TBASIC code to send the response for those IDs that it recognizes.

You could also try SETPROTOCOL 1,5  which allows the PLC to still respond to Hostlink command (except point to point protocol so "IR*" will not work as it must have an ID) but will not respond to RTU protocol. That way TLServer can still comm with the PLC's RS485 port when not using the Modbus simulation.

By the way, congratulation to your new status as an Expert Member of this forum! Thank you for all your contribution to the community.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS