Skip to content

Commit

Permalink
Fix for issue #21
Browse files Browse the repository at this point in the history
  • Loading branch information
bashwork committed Jul 15, 2013
1 parent ea19769 commit 1d4aa0a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions pymodbus/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ class Defaults(Singleton):
The default number of times a client should retry the given
request before failing (3)
.. attribute:: RetryOnEmpty
A flag indicating if a transaction should be retried in the
case that an empty response is received. This is useful for
slow clients that may need more time to process a requst.
.. attribute:: Timeout
The default amount of time a client should wait for a request
Expand Down Expand Up @@ -73,6 +79,7 @@ class Defaults(Singleton):
'''
Port = 502
Retries = 3
RetryOnEmpty = False
Timeout = 3
Reconnects = 0
TransactionId = 0
Expand Down
9 changes: 7 additions & 2 deletions pymodbus/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ class ModbusTransactionManager(object):
This module helps to abstract this away from the framer and protocol.
'''

def __init__(self, client):
def __init__(self, client, **kwargs):
''' Initializes an instance of the ModbusTransactionManager
:param client: The client socket wrapper
:param retry_on_empty: Should the client retry on empty
'''
self.tid = Defaults.TransactionId
self.client = client
self.retry_on_empty = kwargs.get('retry_on_empty', Defaults.RetryOnEmpty)

def execute(self, request):
''' Starts the producer to send the next request to
Expand All @@ -62,6 +64,9 @@ def execute(self, request):
# as this may not read the full result set, but right now
# it should be fine...
result = self.client._recv(1024)
if not result and self.retry_on_empty:
retries -= 1
continue
self.client.framer.processIncomingPacket(result, self.addTransaction)
break;
except socket.error, msg:
Expand Down Expand Up @@ -132,7 +137,7 @@ def __iter__(self):
:returns: An iterator of the managed transactions
'''
return self.transactions.iterkeys()
return iter(self.transactions.keys())

def addTransaction(self, request, tid=None):
''' Adds a transaction to the handler
Expand Down

0 comments on commit 1d4aa0a

Please sign in to comment.