Skip to content

Commit 2ada5c1

Browse files
karlpdhoomakethu
authored andcommitted
other: fix report slave id improper fallback to default
Wrongly attempted to treat the object as a dict, needs to check if the property is there at all. Fixes: 042458b: other: reportSlaveId: allow slaves to provide custom responses Signed-off-by: Karl Palsson <[email protected]>
1 parent f2fe48e commit 2ada5c1

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pymodbus/other_message.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,15 @@ def execute(self, context=None):
364364
365365
:returns: The populated response
366366
'''
367-
information = DeviceInformationFactory.get(_MCB)
368-
identifier = "-".join(information.values()).encode()
369-
identifier = identifier or b'Pymodbus'
370-
return ReportSlaveIdResponse(identifier)
367+
reportSlaveIdData = None
368+
if context:
369+
reportSlaveIdData = getattr(context, 'reportSlaveIdData', None)
370+
if not reportSlaveIdData:
371+
information = DeviceInformationFactory.get(_MCB)
372+
identifier = "-".join(information.values()).encode()
373+
identifier = identifier or b'Pymodbus'
374+
reportSlaveIdData = identifier
375+
return ReportSlaveIdResponse(reportSlaveIdData)
371376

372377
def __str__(self):
373378
''' Builds a representation of the request

0 commit comments

Comments
 (0)