Skip to content

Commit 2acdbae

Browse files
committed
Add simple asyncio RTU serial client exmaple
1 parent 3844b02 commit 2acdbae

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python
2+
# scripts/example/simple_async_rtu_client.py
3+
import asyncio
4+
5+
from serial_asyncio import open_serial_connection
6+
7+
from umodbus.client.serial import rtu
8+
9+
10+
async def main():
11+
reader, writer = await open_serial_connection(url='/dev/ttyS1', timeout=1)
12+
13+
# Returns a message or Application Data Unit (ADU) specific for doing
14+
# Modbus TCP/IP.
15+
message = tcp.write_multiple_coils(slave_id=1, starting_address=1, values=[1, 0, 1, 1])
16+
17+
# Response depends on Modbus function code. This particular returns the
18+
# amount of coils written, in this case it is.
19+
response = await tcp.async_send_message(message, reader, writer)
20+
21+
writer.close()
22+
await writer.wait_closed()
23+
24+
25+
asyncio.run(main())

0 commit comments

Comments
 (0)