Skip to content

Commit

Permalink
Feature/simulator addressing (#2258)
Browse files Browse the repository at this point in the history
  • Loading branch information
Esco441-91 authored Jul 23, 2024
1 parent 1b2cb7e commit d329475
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/source/library/simulator/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ The entry “framer” allows the following values:
- “tls” to use :class:`pymodbus.framer.ModbusTlsFramer`,
- “socket” to use :class:`pymodbus.framer.ModbusSocketFramer`.

Optional entry "device_id" will limit server to only accept a single id. If
not set, the server will accept all device id.

.. warning::

not all "framer" types can be used with all “comm” types.
Expand Down
9 changes: 8 additions & 1 deletion pymodbus/server/simulator/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,14 @@ def __init__(
self.datastore_context = ModbusSimulatorContext(
device, custom_actions_dict or {}
)
datastore = ModbusServerContext(slaves=self.datastore_context, single=True)
datastore = None
if "device_id" in server:
# Designated ModBus unit address. Will only serve data if the address matches
datastore = ModbusServerContext(slaves={int(server["device_id"]): self.datastore_context}, single=True)
else:
# Will server any request regardless of addressing
datastore = ModbusServerContext(slaves=self.datastore_context, single=True)

comm = comm_class[server.pop("comm")]
framer = server.pop("framer")
if "identity" in server:
Expand Down

0 comments on commit d329475

Please sign in to comment.