Skip to content
Merged
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
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
version 2.5.2
----------------------------------------------------------
* Add kwarg `reset_socket` to control closing of the socket on read failures (set to `True` by default).
* Add `--reset-socket/--no-reset-socket` to REPL client.

version 2.5.1
----------------------------------------------------------
* Bug fix TCP Repl server.
Expand Down
6 changes: 4 additions & 2 deletions pymodbus/repl/client/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,10 @@ def _process_args(args, string=True):
@click.option("--retry-on-error", is_flag=True, default=False,
help="Retry on error response")
@click.option("--retries", default=3, help="Retry count")
@click.option("--reset-socket/--no-reset-socket", default=True, help="Reset client socket on error")
@click.pass_context
def main(ctx, verbose, broadcast_support, retry_on_empty,
retry_on_error, retries):
retry_on_error, retries, reset_socket):
if verbose:
global log
import logging
Expand All @@ -248,7 +249,8 @@ def main(ctx, verbose, broadcast_support, retry_on_empty,
"broadcast": broadcast_support,
"retry_on_empty": retry_on_empty,
"retry_on_invalid": retry_on_error,
"retries": retries
"retries": retries,
"reset_socket": reset_socket
}


Expand Down
19 changes: 11 additions & 8 deletions pymodbus/repl/server/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
| ___< | |/ \ / _ \ / __ | | __ \| | \/ ___/ \_____ \_/ __ \_ __ \ \/ // __ \_ __ \\
| | \___ | Y Y ( <_> ) /_/ | | \_\ \ | /\___ \ / \ ___/| | \/\ /\ ___/| | \/
|____| / ____|__|_| /\____/\____ | |___ /____//____ > /_______ /\___ >__| \_/ \___ >__|
\/ \/ \/ \/ \/ \/ \/ \/"""
\/ \/ \/ \/ \/ \/ \/ \/
"""

SMALL_TITLE = "Pymodbus server..."
BOTTOM_TOOLBAR = HTML('(MODBUS SERVER) <b><style bg="ansired">Press Ctrl+C or '
Expand Down Expand Up @@ -80,7 +81,9 @@


def info(message):
click.secho(str(message), fg="green")
if not isinstance(message, str):
message = str(message)
click.secho(message, fg="green")


def warning(message):
Expand Down Expand Up @@ -191,12 +194,12 @@ async def interactive_shell(server):


async def main(server):
with patch_stdout():
try:
await interactive_shell(server)
finally:
pass
warning("Bye Bye!!!")
# with patch_stdout():
try:
await interactive_shell(server)
finally:
pass
warning("Bye Bye!!!")


async def run_repl(server):
Expand Down
10 changes: 7 additions & 3 deletions pymodbus/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def __init__(self, client, **kwargs):
self.retry_on_invalid = kwargs.get('retry_on_invalid',
Defaults.RetryOnInvalid)
self.retries = kwargs.get('retries', Defaults.Retries) or 1
self.reset_socket = kwargs.get('reset_socket', True)
self._transaction_lock = RLock()
self._no_response_devices = []
if client:
Expand Down Expand Up @@ -217,7 +218,8 @@ def execute(self, request):
"/Unable to decode response")
response = ModbusIOException(last_exception,
request.function_code)
self.client.close()
if self.reset_socket:
self.client.close()
if hasattr(self.client, "state"):
_logger.debug("Changing transaction state from "
"'PROCESSING REPLY' to "
Expand All @@ -230,7 +232,8 @@ def execute(self, request):
# Handle decode errors in processIncomingPacket method
_logger.exception(ex)
self.client.state = ModbusTransactionState.TRANSACTION_COMPLETE
self.client.close()
if self.reset_socket:
self.client.close()
return ex

def _retry_transaction(self, retries, reason,
Expand Down Expand Up @@ -294,7 +297,8 @@ def _transact(self, packet, response_length,

except (socket.error, ModbusIOException,
InvalidMessageReceivedException) as msg:
self.client.close()
if self.reset_socket:
self.client.close()
_logger.debug("Transaction failed. (%s) " % msg)
last_exception = msg
result = b''
Expand Down
2 changes: 1 addition & 1 deletion pymodbus/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __str__(self):
return '[%s, version %s]' % (self.package, self.short())


version = Version('pymodbus', 2, 5, 1)
version = Version('pymodbus', 2, 5, 2)

version.__name__ = 'pymodbus' # fix epydoc error

Expand Down