News:

  • October 13, 2025, 11:12:16 AM

Login with username, password and session length

Author Topic: How to setup Modbus TCP connection  (Read 9120 times)

PLCwannabe

  • Hero Member
  • *****
  • Posts: 197
How to setup Modbus TCP connection
« on: May 06, 2022, 12:28:42 AM »
I need to retrieve values from a power quality meter, that is connected via ethernet to the same network as my brx Plc. I'm trying to use an MRX instruction to read the values via Modbus/TCP, but having no success. The MRX never sets success or failure bits, it seems like its locked up. When I do a program/ run transition, then the mrx error bit sets.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3601
  • Darth Ladder
Re: How to setup Modbus TCP connection
« Reply #1 on: May 06, 2022, 12:57:45 AM »
If you try to poll the monitor with another client, such as Modbus Poll from your PC, can you get it to respond?  Do you get a valid read?
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

RBPLC

  • Hero Member
  • *****
  • Posts: 585
Re: How to setup Modbus TCP connection
« Reply #2 on: May 06, 2022, 03:29:25 AM »
Have you tried reading "Input Registers" instead of "Holding Registers"?

PLCwannabe

  • Hero Member
  • *****
  • Posts: 197
Re: How to setup Modbus TCP connection
« Reply #3 on: May 06, 2022, 09:32:42 AM »
I haven't tried much of anything yet. I'm pretty proficient now at Modbus RTU, but this is my first crack at Modbus Tcp, I was hoping that I was doing something totally wrong, like using the wrong instruction. Is it really as simple as putting the IP address of the slave device into an MRX instruction, and it's supposed to worK?

RBPLC

  • Hero Member
  • *****
  • Posts: 585
Re: How to setup Modbus TCP connection
« Reply #4 on: May 06, 2022, 09:48:33 AM »
I haven't tried much of anything yet. I'm pretty proficient now at Modbus RTU, but this is my first crack at Modbus Tcp, I was hoping that I was doing something totally wrong, like using the wrong instruction. Is it really as simple as putting the IP address of the slave device into an MRX instruction, and it's supposed to worK?

Yes.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6126
  • Yes Pinky, Do-more will control the world!
Re: How to setup Modbus TCP connection
« Reply #5 on: May 06, 2022, 11:04:19 AM »
I haven't tried much of anything yet. I'm pretty proficient now at Modbus RTU, but this is my first crack at Modbus Tcp, I was hoping that I was doing something totally wrong, like using the wrong instruction. Is it really as simple as putting the IP address of the slave device into an MRX instruction, and it's supposed to worK?

In your image, the Modbus program blocks are disabled. Make sure they are running the entire time you are doing Modbus comms.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

PLCwannabe

  • Hero Member
  • *****
  • Posts: 197
Re: How to setup Modbus TCP connection
« Reply #6 on: May 06, 2022, 11:49:30 AM »
Those modbus blocks are for the onboard serial port communicating with a genset, which is working well.
   So now I'm trying to poll another BRX Plc (IP 192.168.1.72) and that isn't working either. The MHR 1-10 on the server Plc are set to random numbers, Modbus Tcp server is enabled. Could you post a couple example rungs for the Modbus TCP Client plc, that would read MHR1-10 from the server plc?

 

jrayb

  • Full Member
  • ***
  • Posts: 46
Re: How to setup Modbus TCP connection
« Reply #7 on: May 06, 2022, 12:25:27 PM »
Are you able to ping the modbuss address from your PC? Does the unit need to have its modbus server enabled? I had this issue with a unit that I was trying to communicate with. I had to enable the modubus server on the unit itself.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3761
    • Host Engineering
Re: How to setup Modbus TCP connection
« Reply #8 on: May 06, 2022, 12:35:04 PM »
I noticed the device IP Address was 192.168.1.60, but the MRX is using 192.168.1.72?

Realize TCP timeouts are LONG (much longer than 1 second), so driving your MRX using ST4 is not going to do what you think it's doing if the comm is not going to "queue up" requests.  If the cable is disconnected, it won't report an error for 30(?) seconds.  It won't hurt anything to attempt to re-fire an MRX that is still working on a previous comm, but it's not going to do anything until it finishes the previous one.

PLCwannabe

  • Hero Member
  • *****
  • Posts: 197
Re: How to setup Modbus TCP connection
« Reply #9 on: May 07, 2022, 03:15:40 PM »
I was able to get 2 BRX plc to communicate via Modbus tcp, though I had to update the client PLC  OS to 2.9.3 to get it to work. Not sure why it wouldn't work with OS 2.8.6.
  When trying to connect with the power quality meter now, I get Exception code 4 every time, within 1 second. What does this indicate?

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6126
  • Yes Pinky, Do-more will control the world!
Re: How to setup Modbus TCP connection
« Reply #10 on: May 07, 2022, 03:45:24 PM »
I was able to get 2 BRX plc to communicate via Modbus tcp, though I had to update the client PLC  OS to 2.9.3 to get it to work. Not sure why it wouldn't work with OS 2.8.6.
  When trying to connect with the power quality meter now, I get Exception code 4 every time, within 1 second. What does this indicate?

That is a standard Modbus "device failure" exception. Don't know what would cause your device to return that. We don't every return it from our server.

Don't know specifically why you were having issues, but there were some issues with Modbus TCP on 2.8.x. They were fairly rare and generally a result of unstable networks, but if you are point to point it should just work.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

PLCwannabe

  • Hero Member
  • *****
  • Posts: 197
Re: How to setup Modbus TCP connection
« Reply #11 on: May 07, 2022, 05:34:23 PM »
Well, I'm not exactly point to point, as there are a few unmanaged ethernet switches, and a couple of wifi radios in the link between the plcs. However, just one ethernet switch between the Brx and the power meter device.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6126
  • Yes Pinky, Do-more will control the world!
Re: How to setup Modbus TCP connection
« Reply #12 on: May 07, 2022, 06:10:40 PM »
Well, I'm not exactly point to point, as there are a few unmanaged ethernet switches, and a couple of wifi radios in the link between the plcs. However, just one ethernet switch between the Brx and the power meter device.

2.9.x resolved those issues and should work work much better in unreliable networks.

The issue in 2.8.x got by us because we weren't testing in unreliable networks. We were able to easily dupe the problem, fix it, and prove we'd fixed it, once we started doing hateful things to the network infrastructure.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

PLCwannabe

  • Hero Member
  • *****
  • Posts: 197
Re: How to setup Modbus TCP connection
« Reply #13 on: May 08, 2022, 05:45:51 PM »
If you try to poll the monitor with another client, such as Modbus Poll from your PC, can you get it to respond?  Do you get a valid read?
I downloaded Modbus Poll on my PC, and I can read 100 registers every 500Ms, with no issues, from the power meter. But still no luck with my Brx.  How can I troubleshoot this further?

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3601
  • Darth Ladder
Re: How to setup Modbus TCP connection
« Reply #14 on: May 08, 2022, 05:57:03 PM »
Make your PC the target for the read and using Wireshark, capture the BRXs request packets.

Also record the successful queries from when the pc is the client.
« Last Edit: May 08, 2022, 06:02:56 PM by Controls Guy »
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.