Skip to content

Commit 2780e23

Browse files
authored
Add identity argument to ModbusSerialServer (#670)
It is passed in by StartSerialServer but no argument of the constructor accepts it, resulting in a runtime failure: File ".../site-packages/pymodbus/server/async_io.py", line 932, in StartSerialServer server = ModbusSerialServer(context, framer, identity, **kwargs) TypeError: __init__() takes from 2 to 3 positional arguments but 4 were given
1 parent 7b68c37 commit 2780e23

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pymodbus/server/async_io.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,12 +712,13 @@ class ModbusSerialServer(object):
712712

713713
handler = None
714714

715-
def __init__(self, context, framer=None, **kwargs): # pragma: no cover
715+
def __init__(self, context, framer=None, identity=None, **kwargs): # pragma: no cover
716716
""" Overloaded initializer for the socket server
717-
If the identify structure is not passed in, the ModbusControlBlock
717+
If the identity structure is not passed in, the ModbusControlBlock
718718
uses its own empty structure.
719719
:param context: The ModbusServerContext datastore
720720
:param framer: The framer strategy to use
721+
:param identity: An optional identify structure
721722
:param port: The serial port to attach to
722723
:param stopbits: The number of stop bits to use
723724
:param bytesize: The bytesize of the serial messages
@@ -753,6 +754,10 @@ def __init__(self, context, framer=None, **kwargs): # pragma: no cover
753754
self.decoder = ServerDecoder()
754755
self.context = context or ModbusServerContext()
755756
self.response_manipulator = kwargs.get("response_manipulator", None)
757+
self.control = ModbusControlBlock()
758+
if isinstance(identity, ModbusDeviceIdentification):
759+
self.control.Identity.update(identity)
760+
756761
self.protocol = None
757762
self.transport = None
758763

0 commit comments

Comments
 (0)