News:

  • October 13, 2025, 09:30:48 AM

Login with username, password and session length

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

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6126
  • Yes Pinky, Do-more will control the world!
Re: How to setup Modbus TCP connection
« Reply #15 on: May 08, 2022, 07:06:08 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?

Modpoll uses 0-based addresses. Do-more uses 1-based. Make sure you are using the correct address.
"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 #16 on: May 09, 2022, 01:27:51 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.
Here are a few wireshark screen shots of my PC (192.168.1.50) successfully polling the power meter (192.168.1.60) for register 2200.
Also a couple screenshots of my BRX (192.168.1.75) polling the PC (192.168.1.50) unsuccessfully for register 2200. Hope someone can make sense of this.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6126
  • Yes Pinky, Do-more will control the world!
Re: How to setup Modbus TCP connection
« Reply #17 on: May 09, 2022, 01:33:51 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.
Here are a few wireshark screen shots of my PC (192.168.1.50) successfully polling the power meter (192.168.1.60) for register 2200.
Also a couple screenshots of my BRX (192.168.1.75) polling the PC (192.168.1.50) unsuccessfully for register 2200. Hope someone can make sense of this.

Don't know why, but it's never getting to the Modbus portion of the transaction. The device is never answering the request to open the connection.
"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 #18 on: May 09, 2022, 02:29:19 PM »
There isn't a Modbus slave device set up on my pc, maybe that is why the connection is never made. I just hoped that by looking at the read request from the BRX to the PC as compared to the read request from the PC to the power meter, someone could point out what the BRX is doing "wrong". Can you recommend a modbus slave simulator that I could install on my PC?

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6126
  • Yes Pinky, Do-more will control the world!
Re: How to setup Modbus TCP connection
« Reply #19 on: May 09, 2022, 02:36:07 PM »
There isn't a Modbus slave device set up on my pc, maybe that is why the connection is never made. I just hoped that by looking at the read request from the BRX to the PC as compared to the read request from the PC to the power meter, someone could point out what the BRX is doing "wrong". Can you recommend a modbus slave simulator that I could install on my PC?

I don't see evidence that BRX is doing anything wrong. The device isn't answering, but the SYN request appears to be correct. If you want to email the captures to support@hosteng.com, we'll look closer to see if anything is obvious.

The BRX simulator works great as a Modbus slave.
"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

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3601
  • Darth Ladder
Re: How to setup Modbus TCP connection
« Reply #20 on: May 09, 2022, 03:06:21 PM »
There isn't a Modbus slave device set up on my pc, maybe that is why the connection is never made. I just hoped that by looking at the read request from the BRX to the PC as compared to the read request from the PC to the power meter, someone could point out what the BRX is doing "wrong". Can you recommend a modbus slave simulator that I could install on my PC?

Sounds more like it doesn't like incoming connections.   Maybe a firewall thing?  Also, the reason I suggested using your PC as a server target was so you could see the BRX request traffic.   Another option is that you can spy on the real comms with the monitor in-circuit with a mirroring switch like a Netgear GS10xE.   Then you can let the BRX talk to the power monitor as normal and still be able to see the conversation via Wireshark on your PC.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3601
  • Darth Ladder
Re: How to setup Modbus TCP connection
« Reply #21 on: May 09, 2022, 03:40:27 PM »
The BRX simulator works great as a Modbus slave.

That's a really slick idea -- never thought of that!   :o
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6126
  • Yes Pinky, Do-more will control the world!
Re: How to setup Modbus TCP connection
« Reply #22 on: May 09, 2022, 04:20:55 PM »
The BRX simulator works great as a Modbus slave.

That's a really slick idea -- never thought of that!   :o

And it's even got a built-in scripting engine for simulating device behavior! Sorta kinda.
"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

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3601
  • Darth Ladder
Re: How to setup Modbus TCP connection
« Reply #23 on: May 09, 2022, 04:45:17 PM »
Man, is there anything it doesn't do?   With that you can really do more!
« Last Edit: May 09, 2022, 05:10:32 PM by Controls Guy »
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

PLCwannabe

  • Hero Member
  • *****
  • Posts: 197
Re: How to setup Modbus TCP connection
« Reply #24 on: May 09, 2022, 09:35:01 PM »
     Turns out I didn't have the device ID set correctly. When I first started this thread, I had tried setting the device ID to 1, but for whatever reason, before I updated the PLC Oss, it still didn't work. Then when I was doing the communication between the two BRX plcs, it didn't seem to matter that device ID was left at default 255, so I wrongly assumed that it never mattered with Modbus Tcp. As  soon as I set ID to 1, i could read all the power meter values with the simulator, and then also with the plc.
  I guess the lesson here for me is to keep it simple, and never assume anything.
« Last Edit: May 09, 2022, 09:40:55 PM by PLCwannabe »

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3601
  • Darth Ladder
Re: How to setup Modbus TCP connection
« Reply #25 on: May 10, 2022, 01:06:30 AM »
Good catch.  I think most TCP devices ignore it, but once in a while one cares.  One legitimate use case for it is when you have a TCP gateway with a bunch of RTU devices on the other side.  For individual devices though I don't see that if makes much sense.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3761
    • Host Engineering
Re: How to setup Modbus TCP connection
« Reply #26 on: May 10, 2022, 08:43:56 AM »
     Turns out I didn't have the device ID set correctly. When I first started this thread, I had tried setting the device ID to 1, but for whatever reason, before I updated the PLC Oss, it still didn't work. Then when I was doing the communication between the two BRX plcs, it didn't seem to matter that device ID was left at default 255, so I wrongly assumed that it never mattered with Modbus Tcp. As  soon as I set ID to 1, i could read all the power meter values with the simulator, and then also with the plc.
  I guess the lesson here for me is to keep it simple, and never assume anything.

Which ID did you set to 1?  The one in the MRX/MWX instruction and/or the one in the power meter?  Regardless, I'm wondering why the other clients worked?

PLCwannabe

  • Hero Member
  • *****
  • Posts: 197
Re: How to setup Modbus TCP connection
« Reply #27 on: May 10, 2022, 07:13:39 PM »
The power meter by default is 1. The MRX had to have the id set to 1 as well. This meter also has terminals for a serial Modbus connection, maybe that has something to do with it.
 The Modbus Poll software default slave id is also 1, that is why it worked right away.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6126
  • Yes Pinky, Do-more will control the world!
Re: How to setup Modbus TCP connection
« Reply #28 on: May 10, 2022, 07:29:08 PM »
The ID is generally unused in Modbus/TCP. When used, it generally addresses sub-devices, like through a gateway.
"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