From dbdd56a47f4a10290b508736f31435a3b7d261ed Mon Sep 17 00:00:00 2001 From: Cougar Date: Sun, 4 Oct 2020 15:50:54 +0300 Subject: [PATCH] Refactor: use `hexlify_packets()` where possible --- pymodbus/client/asynchronous/async_io/__init__.py | 6 +++--- pymodbus/client/asynchronous/tornado/__init__.py | 10 +++++----- pymodbus/client/asynchronous/twisted/__init__.py | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pymodbus/client/asynchronous/async_io/__init__.py b/pymodbus/client/asynchronous/async_io/__init__.py index b4cefd486..552202a3f 100644 --- a/pymodbus/client/asynchronous/async_io/__init__.py +++ b/pymodbus/client/asynchronous/async_io/__init__.py @@ -7,7 +7,7 @@ import ssl from pymodbus.exceptions import ConnectionException from pymodbus.client.asynchronous.mixins import AsyncModbusClientMixin -from pymodbus.compat import byte2int +from pymodbus.utilities import hexlify_packets from pymodbus.transaction import FifoTransactionManager import logging @@ -137,7 +137,7 @@ def _execute(self, request, **kwargs): """ request.transaction_id = self.transaction.getNextTID() packet = self.framer.buildPacket(request) - _logger.debug("send: " + " ".join([hex(byte2int(x)) for x in packet])) + _logger.debug("send: " + hexlify_packets(packet)) self.write_transport(packet) return self._buildResponse(request.transaction_id) @@ -146,7 +146,7 @@ def _dataReceived(self, data): :param data: The data returned from the server ''' - _logger.debug("recv: " + " ".join([hex(byte2int(x)) for x in data])) + _logger.debug("recv: " + hexlify_packets(data)) unit = self.framer.decode_data(data).get("unit", 0) self.framer.processIncomingPacket(data, self._handleResponse, unit=unit) diff --git a/pymodbus/client/asynchronous/tornado/__init__.py b/pymodbus/client/asynchronous/tornado/__init__.py index 2b0cc55d6..4dfb01961 100644 --- a/pymodbus/client/asynchronous/tornado/__init__.py +++ b/pymodbus/client/asynchronous/tornado/__init__.py @@ -18,7 +18,7 @@ from pymodbus.client.asynchronous.mixins import (AsyncModbusClientMixin, AsyncModbusSerialClientMixin) from pymodbus.exceptions import ConnectionException -from pymodbus.compat import byte2int +from pymodbus.utilities import hexlify_packets LOGGER = logging.getLogger(__name__) @@ -74,7 +74,7 @@ def on_receive(self, *args): if not data: return - LOGGER.debug("recv: " + " ".join([hex(byte2int(x)) for x in data])) + LOGGER.debug("recv: " + hexlify_packets(data)) unit = self.framer.decode_data(data).get("unit", 0) self.framer.processIncomingPacket(data, self._handle_response, unit=unit) @@ -86,7 +86,7 @@ def execute(self, request=None): """ request.transaction_id = self.transaction.getNextTID() packet = self.framer.buildPacket(request) - LOGGER.debug("send: " + " ".join([hex(byte2int(x)) for x in packet])) + LOGGER.debug("send: " + hexlify_packets(packet)) self.stream.write(packet) return self._build_response(request.transaction_id) @@ -174,7 +174,7 @@ def callback(*args): if waiting: data = self.stream.connection.read(waiting) LOGGER.debug( - "recv: " + " ".join([hex(byte2int(x)) for x in data])) + "recv: " + hexlify_packets(data)) unit = self.framer.decode_data(data).get("uid", 0) self.framer.processIncomingPacket( data, @@ -185,7 +185,7 @@ def callback(*args): break packet = self.framer.buildPacket(request) - LOGGER.debug("send: " + " ".join([hex(byte2int(x)) for x in packet])) + LOGGER.debug("send: " + hexlify_packets(packet)) self.stream.write(packet, callback=callback) f = self._build_response(request.transaction_id) return f diff --git a/pymodbus/client/asynchronous/twisted/__init__.py b/pymodbus/client/asynchronous/twisted/__init__.py index e78da476f..f86cae3cb 100644 --- a/pymodbus/client/asynchronous/twisted/__init__.py +++ b/pymodbus/client/asynchronous/twisted/__init__.py @@ -40,7 +40,7 @@ def process(): from pymodbus.client.asynchronous.mixins import AsyncModbusClientMixin from pymodbus.transaction import FifoTransactionManager, DictTransactionManager from pymodbus.transaction import ModbusSocketFramer, ModbusRtuFramer -from pymodbus.compat import byte2int +from pymodbus.utilities import hexlify_packets from twisted.python.failure import Failure @@ -109,7 +109,7 @@ def execute(self, request): """ request.transaction_id = self.transaction.getNextTID() packet = self.framer.buildPacket(request) - _logger.debug("send: " + " ".join([hex(byte2int(x)) for x in packet])) + _logger.debug("send: " + hexlify_packets(packet)) self.transport.write(packet) return self._buildResponse(request.transaction_id)