Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pymodbus/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class Defaults(Singleton):
Parity = 'N'
Bytesize = 8
Stopbits = 1
ignore_undefined_slaves = False


class ModbusStatus(Singleton):
Expand Down
12 changes: 10 additions & 2 deletions pymodbus/server/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def setup(self):
self.running = True
self.framer = self.server.framer(self.server.decoder)
self.server.threads.append(self)
self.ignore_undefined_slaves = self.server.ignore_undefined_slaves

def finish(self):
''' Callback for when a client disconnects
Expand All @@ -58,8 +59,11 @@ def execute(self, request):
context = self.server.context[request.unit_id]
response = request.execute(context)
except Exception, ex:
_logger.debug("Datastore unable to fulfill request: %s; %s", ex, traceback.format_exc() )
response = request.doException(merror.SlaveFailure)
if 'slave does not exist' in str(ex) and self.ignore_undefined_slaves:
return
else:
_logger.debug("Datastore unable to fulfill request: %s" % ex, traceback.format_exc() )
response = request.doException(merror.SlaveFailure)
response.transaction_id = request.transaction_id
response.unit_id = request.unit_id
self.send(response)
Expand Down Expand Up @@ -336,6 +340,8 @@ def __init__(self, context, framer=None, identity=None, **kwargs):
:param parity: Which kind of parity to use
:param baudrate: The baud rate to use for the serial device
:param timeout: The timeout to use for the serial device
:param ignore_undefined_slaves: False (default): an error response is emitted
True (standard): the request is ignored

'''
self.threads = []
Expand All @@ -356,6 +362,8 @@ def __init__(self, context, framer=None, identity=None, **kwargs):
self.socket = None
self._connect()
self.is_running = True
self.ignore_undefined_slaves = kwargs.get('ignore_undefined_slaves',
Defaults.ignore_undefined_slaves)

def _connect(self):
''' Connect to the serial server
Expand Down