Skip to content

Commit 4f6806d

Browse files
committed
fix formatting, add debug logs, add client_connect todo
1 parent 1a6e95c commit 4f6806d

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

umodbus/asynchronous/serial.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ async def _send(self,
144144
slave_addr: int) -> None:
145145
"""@see CommonRTUFunctions._send"""
146146

147+
print("async RTU: _send() called")
147148
post_send_actions = super()._send(device=self,
148149
modbus_pdu=modbus_pdu,
149150
slave_addr=slave_addr)
@@ -158,6 +159,7 @@ async def _post_send(self, sleep_time_us: float) -> None:
158159
@see CommonRTUFunctions._post_send
159160
"""
160161

162+
print("async RTU: _post_send() called")
161163
await hybrid_sleep(sleep_time_us)
162164
if self._ctrlPin:
163165
self._ctrlPin.off()
@@ -242,13 +244,15 @@ async def send_response(self,
242244
:type request: AsyncRequest, optional
243245
"""
244246

247+
print("async RTU: calling send_response()")
245248
task = super().send_response(slave_addr=slave_addr,
246249
function_code=function_code,
247250
request_register_addr=request_register_addr, # noqa: E501
248251
request_register_qty=request_register_qty,
249252
request_data=request_data,
250253
values=values,
251254
signed=signed)
255+
print("async RTU: send_response() called, task is:", task)
252256
if task is not None:
253257
await task
254258

@@ -267,9 +271,11 @@ async def send_exception_response(self,
267271
:type request: AsyncRequest, optional
268272
"""
269273

274+
print("async RTU: calling send_exception_response()")
270275
task = super().send_exception_response(slave_addr=slave_addr,
271276
function_code=function_code,
272277
exception_code=exception_code)
278+
print("async RTU: called send_exception_response(), task is:", task)
273279
if task is not None:
274280
await task
275281

umodbus/asynchronous/tcp.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,11 @@ async def _send(self,
179179
size = len(modbus_pdu)
180180
fmt = 'B' * size
181181
adu = struct.pack('>HHHB' + fmt,
182-
req_tid,
183-
0,
184-
size + 1,
185-
slave_addr,
186-
*modbus_pdu)
182+
req_tid,
183+
0,
184+
size + 1,
185+
slave_addr,
186+
*modbus_pdu)
187187
writer.write(adu)
188188
await writer.drain()
189189

@@ -248,6 +248,9 @@ async def _accept_request(self,
248248

249249
try:
250250
header_len = Const.MBAP_HDR_LENGTH - 1
251+
# TODO add "on_client_connected" and
252+
# "on_client_disconnected" callbacks for TCP
253+
# dest_addr = writer.get_extra_info('peername')
251254

252255
while True:
253256
task = reader.read(128)
@@ -259,7 +262,7 @@ async def _accept_request(self,
259262

260263
req_header_no_uid = req[:header_len]
261264
req_tid, req_pid, req_len = struct.unpack('>HHH',
262-
req_header_no_uid)
265+
req_header_no_uid)
263266
req_uid_and_pdu = req[header_len:header_len + req_len]
264267
if (req_pid != 0):
265268
raise ValueError(

umodbus/modbus.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def process(self, request: Optional[Request] = None) -> Optional[Awaitable]:
7474
if request is None:
7575
request = self._itf.get_request(unit_addr_list=self._addr_list,
7676
timeout=0)
77-
# if get_request is async or none, hands it off to the async subclass
77+
# if get_request is an async generator or None, hands it off to the async subclass
7878
if not isinstance(request, Request):
7979
return request
8080

0 commit comments

Comments
 (0)