Skip to content

Commit 6e72e44

Browse files
committed
1. Fix tornado async serial client TypeError while processing incoming packet.
2. Fix asyncio examples. 3. Minor update in factory.py, now server logs prints received request instead of only function cod
1 parent 826240b commit 6e72e44

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

examples/common/async_asyncio_serial_client.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ async def start_async_test(client):
4949
# which defaults to `0x00`
5050
# ----------------------------------------------------------------------- #
5151
try:
52-
log.debug("Reading Coils")
53-
rr = client.read_coils(1, 1, unit=UNIT)
54-
5552
# ----------------------------------------------------------------------- #
5653
# example requests
5754
# ----------------------------------------------------------------------- #
@@ -137,7 +134,7 @@ async def start_async_test(client):
137134
# socat -d -d PTY,link=/tmp/ptyp0,raw,echo=0,ispeed=9600 PTY,
138135
# link=/tmp/ttyp0,raw,echo=0,ospeed=9600
139136
loop, client = ModbusClient(schedulers.ASYNC_IO, port='/tmp/ptyp0',
140-
baudrate=9600, timeout=2, method="rtu")
137+
baudrate=9600, method="rtu")
141138
loop.run_until_complete(start_async_test(client.protocol))
142139
loop.close()
143140

examples/common/async_tornado_client_serial.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
# configure the client logging
2525
# ---------------------------------------------------------------------------#
2626
import logging
27-
logging.basicConfig()
27+
28+
FORMAT = ('%(asctime)-15s %(threadName)-15s'
29+
' %(levelname)-8s %(module)-15s:%(lineno)-8s %(message)s')
30+
logging.basicConfig(format=FORMAT)
2831
log = logging.getLogger()
2932
log.setLevel(logging.DEBUG)
3033

pymodbus/client/asynchronous/tornado/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,11 @@ def callback(*args):
175175
data = self.stream.connection.read(waiting)
176176
LOGGER.debug(
177177
"recv: " + " ".join([hex(byte2int(x)) for x in data]))
178+
unit = self.framer.decode_data(data).get("uid", 0)
178179
self.framer.processIncomingPacket(
179180
data,
180181
self._handle_response,
182+
unit,
181183
tid=request.transaction_id
182184
)
183185
break

pymodbus/factory.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,17 @@ def _helper(self, data):
124124
:returns: The decoded request or illegal function request object
125125
"""
126126
function_code = byte2int(data[0])
127-
_logger.debug("Factory Request[%d]" % function_code)
128127
request = self.__lookup.get(function_code, lambda: None)()
129128
if not request:
129+
_logger.debug("Factory Request[%d]" % function_code)
130130
request = IllegalFunctionRequest(function_code)
131+
else:
132+
fc_string = "%s: %s" % (
133+
str(self.__lookup[function_code]).split('.')[-1].rstrip(
134+
"'>"),
135+
function_code
136+
)
137+
_logger.debug("Factory Request[%s]" % fc_string)
131138
request.decode(data[1:])
132139

133140
if hasattr(request, 'sub_function_code'):

0 commit comments

Comments
 (0)