Skip to content

Commit d4f5f9e

Browse files
authored
Merge pull request #562 from etactica/reportslaveid
other: reportSlaveId: allow slaves to provide custom responses
2 parents 93306bc + 042458b commit d4f5f9e

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

pymodbus/other_message.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -360,21 +360,26 @@ def decode(self, data):
360360
pass
361361

362362
def execute(self, context=None):
363-
''' Run a read exeception status request against the store
363+
''' Run a report slave id request against the store
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 = context.reportSlaveIdData
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
374379
375380
:returns: The string representation of the request
376381
'''
377-
return "ResportSlaveIdRequest(%d)" % self.function_code
382+
return "ReportSlaveIdRequest(%d)" % self.function_code
378383

379384

380385
class ReportSlaveIdResponse(ModbusResponse):
@@ -430,7 +435,7 @@ def __str__(self):
430435
:returns: The string representation of the response
431436
'''
432437
arguments = (self.function_code, self.identifier, self.status)
433-
return "ResportSlaveIdResponse(%s, %s, %s)" % arguments
438+
return "ReportSlaveIdResponse(%s, %s, %s)" % arguments
434439

435440
#---------------------------------------------------------------------------#
436441
# TODO Make these only work on serial

0 commit comments

Comments
 (0)