Skip to content

Commit

Permalink
#60 Check for slave unit id before processing the request for serial …
Browse files Browse the repository at this point in the history
…servers
  • Loading branch information
dhoomakethu committed Oct 26, 2017
1 parent 576b61a commit 8681db9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion pymodbus/server/async.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def dataReceived(self, data):
if _logger.isEnabledFor(logging.DEBUG):
_logger.debug(' '.join([hex(byte2int(x)) for x in data]))
if not self.factory.control.ListenOnly:
self.framer.processIncomingPacket(data, self._execute)
unit_address = byte2int(data[0])
if unit_address in self.factory.store:
self.framer.processIncomingPacket(data, self._execute)

def _execute(self, request):
''' Executes the request and returns the result
Expand Down
9 changes: 6 additions & 3 deletions pymodbus/server/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ def handle(self):
if data:
if _logger.isEnabledFor(logging.DEBUG):
_logger.debug(" ".join([hex(byte2int(x)) for x in data]))
self.framer.processIncomingPacket(data, self.execute)
unit_address = byte2int(data[0])
if unit_address in self.server.context:
self.framer.processIncomingPacket(data, self.execute)
except Exception as msg:
# since we only have a single socket, we cannot exit
# Clear frame buffer
Expand Down Expand Up @@ -198,14 +200,15 @@ class ModbusDisconnectedRequestHandler(ModbusBaseRequestHandler):
only difference is that we have to specify who to send the
resulting packet data to.
'''
socket = None

def handle(self):
''' Callback when we receive any data
'''
reset_frame = False
while self.running:
try:
data, self.request = self.request
data, self.socket = self.request
if not data:
self.running = False
if _logger.isEnabledFor(logging.DEBUG):
Expand Down Expand Up @@ -236,7 +239,7 @@ def send(self, message):
pdu = self.framer.buildPacket(message)
if _logger.isEnabledFor(logging.DEBUG):
_logger.debug('send: %s' % b2a_hex(pdu))
return self.request.sendto(pdu, self.client_address)
return self.socket.sendto(pdu, self.client_address)


#---------------------------------------------------------------------------#
Expand Down

0 comments on commit 8681db9

Please sign in to comment.