How to set a slave ID for ModbusSimulator context? #2040
-
Greetings! Many real-life Modbus devices need a slave ID to be connected with. That is why we need When I try to build Modbus Simulator with JSON & ModbusSimulatorContext, I do not provide in the config any slave ID under which this simulator will be available - in this case, every client's request done on any address will be successful, because the simulator works on broadcast mode & every slave ID returns the same context. I have read from the docs that it is possible to change that in ModbusServerContext - I can set The point is, I have the task of writing a simulator of a real device, and this real device always works under a specific slave ID. I expect that in this case the client will receive a response from the server-simulator only when I provide the correct slave ID in the client and not for any random slave. I have noticed that ModbusServerContext has a method My current code is simple, based on ModbusSimulator examples:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Simulator datastore simulates 1 slave therefore the slave id is not needed. Unless you want to simulate a multidrop line, you can just use that context. In all other cases it does not produce problems that the simulator responds to to any id. You can probably combine ModbusServerContext and ModbusSimulatorStore to create a multidrop line, but I have never tried it. |
Beta Was this translation helpful? Give feedback.
-
You can see in our examples how to make a server context with multiple slaves (multiple can also be just one). |
Beta Was this translation helpful? Give feedback.
-
Just checked. You can define 1 or multiple ModbusSimulatorContext, and assign them with slave ids to the server. There are several examples of how to assign multiple contexts with slave ids to a server, have a look. |
Beta Was this translation helpful? Give feedback.
Just checked.
You can define 1 or multiple ModbusSimulatorContext, and assign them with slave ids to the server.
There are several examples of how to assign multiple contexts with slave ids to a server, have a look.