Forward Port to Modbus TCP


#1

Hello all, I have a Modbus device capable to connect to a remote IP/Port. I would like to to connect it to Node-Red and bind this port to Modbus TCP.

I did a connection to Node-Red TCP listener, but I do not know how to read it from Modbus.

Any idea is welcome.


#2

Hello @workano, welcome to Node-RED forum.

You can do that very easily by installing and using the node-red-contrib-mobus.


#3

Hi Andrei, thank you for your quick answer. I am using node-red-contrib-mobus, I can read and write to the device from Node-Red but could not "listen" for a connection from device.

I have connected the device via TCP Listen but did not realize how to bind this connection to Modbus.

Is it possible for you to send a flow or tell me how should I procede?
Thank you so much for your help.


#4

Please share more information on how you configured the TCP node and what happened. Knowing what failed may help us to find a solution. The two most common issues when trying to connect a device with TCP is permission issues when using ports below 1024 and missing to add line feed when sending commands to the device. What is the model of the device you are trying to connect to?


#6

Do you mean you want the device running node-red to act as a modbus server rather than client?


#7

No, I just want to bind two TCP ports.
Eg. My device will conect to the port 8502 and Node-Red will connect to the port 8505.
I want to bind these two ports so Node-Red could pool the device.


#8

OK, so you want the node red device to listen on port 8502 using TCP? You can use the TCP In node for that. That is one of the built-in nodes.


#9

Yes, I did that. I do not know how to bind the two ports.


#10

Can you share a picture from your flow ? I wanted to understand what you mean by "Node-RED TCP listener". I dont understand if you are trying to use a TCP node or using only Modbus contrib node. It would be easy to help you if we have a clear picture of what you already did instead of trying to guess.

Anyway...a new guess on my side. As you are configuring you modbus gateway as a TCP client then you may want to use the Modbus server for testing the connection with your gateway device. Have you already tried this node ?

r-01


#12

I already use this function on ScadaBR. It has Modbus Listener option.
It just waits for a connection and then start the modbus pooling.


#14

Are all the node-red elements in that diagram in the same computer?
Also where is the modbus server in this?


#15

No, PLC is a phisical device, it is the server.
Node-red elements are the TCP listeners and the Modbus-read.


#16

But you have the plc labelled as a modbus client, not a modbus server. Redraw it with extra lines round the physical devices and draw the arrows client > server.


#18

Yes, I believe so, thank you so much for your help.


#19

So is that three separate devices running node-red?
The modbus client is the one that issues, for example, coil read requests. The Server is the one that provides the coil data back to the client. So who in the diagram is asking for the data and who is providing the data?


#20

You still haven't explained fully which is the modbus server/master (the one providing the data) and what is asking for the data.
You can carry on editing the previous post.
If the PLC/Gateway is actually the master then which port is it listening on?


#21

I have just looked back at your earlier posts. You said that if you configure the gateway as a server then you can read and write to it from node-red. In this situation presumably you are reading data that is in the PLC (which is the actual server, the gateway is just a gateway to that server).
Why do you want to change the gateway to be a client? Surely that is only valid if the PLC is operating as a client.

[Edit] I have been blocked too now, for posting too many without a reply.

You mean you want the node-red device to operate as a router? Passing any data it receives on one port to the other?


#23

Sorry, I don't know how to make a router with node red.
So I think what you are actually trying to do is connect a modbus read node to an incoming connection, but I don't know any other way of doing that either.
Perhaps someone with more knowledge of networking can help.


#24

I'm not sure I fully understand what is desired here, but as far as forwarding TCP requests, I was able to do this using:

TCP In (stream of buffers) -> TCP request to Modbus server (return after timeout) -> TCP out (Reply to TCP)

In my setup, I had Node-RED listen (the TCP In) on port 7000, and the TCP request went to a local Modbus server running on port 7001. You'd then have to decode the responses from the TCP request node.

You could also decompose the incoming request, compose a new request with a Modbus node, and then compose the response needed for the TCP out. Doesn't really look like there's an elegant solution here without getting dirty.