1010
1111from examples .client_async import _logger , run_client , setup_client
1212
13- UNIT = 0x01
13+ SLAVE = 0x01
1414
1515
1616async def handle_coils (client ):
1717 """Read/Write coils."""
1818 _logger .info ("### Reading Coil" )
19- rr = await client .read_coils (1 , 1 , unit = UNIT )
19+ rr = await client .read_coils (1 , 1 , slave = SLAVE )
2020 assert not rr .isError () # test that call was OK
2121 txt = f"### coils response: { str (rr .bits )} "
2222 _logger .debug (txt )
2323
2424 _logger .info ("### Reading Coils to get bit 5" )
25- rr = await client .read_coils (1 , 5 , unit = UNIT )
25+ rr = await client .read_coils (1 , 5 , slave = SLAVE )
2626 assert not rr .isError () # test that call was OK
2727 txt = f"### coils response: { str (rr .bits )} "
2828 _logger .debug (txt )
2929
3030 _logger .info ("### Write true to coil bit 0 and read to verify" )
31- rq = await client .write_coil (0 , True , unit = UNIT )
32- rr = await client .read_coils (0 , 1 , unit = UNIT )
31+ rq = await client .write_coil (0 , True , slave = SLAVE )
32+ rr = await client .read_coils (0 , 1 , slave = SLAVE )
3333 assert not rq .isError () and not rr .isError () # test that calls was OK
3434 assert rr .bits [0 ] # test the expected value
3535 txt = f"### coils response: { str (rr .bits )} "
3636 _logger .debug (txt )
3737
3838 _logger .info ("### Write true to multiple coils 1-8" )
39- rq = await client .write_coils (1 , [True ] * 21 , unit = UNIT )
40- rr = await client .read_coils (1 , 21 , unit = UNIT )
39+ rq = await client .write_coils (1 , [True ] * 21 , slave = SLAVE )
40+ rr = await client .read_coils (1 , 21 , slave = SLAVE )
4141 assert not rq .isError () and not rr .isError () # test that calls was OK
4242 resp = [True ] * 21
4343 # If the returned output quantity is not a multiple of eight,
@@ -49,8 +49,8 @@ async def handle_coils(client):
4949 _logger .debug (txt )
5050
5151 _logger .info ("### Write False to address 1-8 coils" )
52- rq = await client .write_coils (1 , [False ] * 8 , unit = UNIT )
53- rr = await client .read_coils (1 , 8 , unit = UNIT )
52+ rq = await client .write_coils (1 , [False ] * 8 , slave = SLAVE )
53+ rr = await client .read_coils (1 , 8 , slave = SLAVE )
5454 assert not rq .isError () and not rr .isError () # test that calls was OK
5555 assert rr .bits == [False ] * 8 # test the expected value
5656 txt = f"### coils response: { str (rr .bits )} "
@@ -60,7 +60,7 @@ async def handle_coils(client):
6060async def handle_discrete_input (client ):
6161 """Read discrete inputs."""
6262 _logger .info ("### Reading discrete input, Read address:0-7" )
63- rr = await client .read_discrete_inputs (0 , 8 , unit = UNIT )
63+ rr = await client .read_discrete_inputs (0 , 8 , slave = SLAVE )
6464 assert not rr .isError () # nosec test that we are not an error
6565 txt = f"### address 0-7 is: { str (rr .bits )} "
6666 _logger .debug (txt )
@@ -69,16 +69,16 @@ async def handle_discrete_input(client):
6969async def handle_holding_registers (client ):
7070 """Read/write holding registers."""
7171 _logger .info ("### write holding register and read holding registers" )
72- rq = await client .write_register (1 , 10 , unit = UNIT )
73- rr = await client .read_holding_registers (1 , 1 , unit = UNIT )
72+ rq = await client .write_register (1 , 10 , slave = SLAVE )
73+ rr = await client .read_holding_registers (1 , 1 , slave = SLAVE )
7474 assert not rq .isError () and not rr .isError () # test that calls was OK
7575 assert rr .registers [0 ] == 10 # nosec test the expected value
7676 txt = f"### address 1 is: { str (rr .registers [0 ])} "
7777 _logger .debug (txt )
7878
7979 _logger .info ("### write holding registers and read holding registers" )
80- rq = await client .write_registers (1 , [10 ] * 8 , unit = UNIT )
81- rr = await client .read_holding_registers (1 , 8 , unit = UNIT )
80+ rq = await client .write_registers (1 , [10 ] * 8 , slave = SLAVE )
81+ rr = await client .read_holding_registers (1 , 8 , slave = SLAVE )
8282 assert not rq .isError () and not rr .isError () # test that calls was OK
8383 assert rr .registers == [10 ] * 8 # nosec test the expected value
8484 txt = f"### address 1-8 is: { str (rr .registers )} "
@@ -91,8 +91,8 @@ async def handle_holding_registers(client):
9191 "write_address" : 1 ,
9292 "write_registers" : [256 , 128 , 100 , 50 , 25 , 10 , 5 , 1 ],
9393 }
94- rq = await client .readwrite_registers (unit = UNIT , ** arguments )
95- rr = await client .read_holding_registers (1 , 8 , unit = UNIT )
94+ rq = await client .readwrite_registers (unit = SLAVE , ** arguments )
95+ rr = await client .read_holding_registers (1 , 8 , slave = SLAVE )
9696 assert not rq .isError () and not rr .isError () # test that calls was OK
9797 assert rq .registers == arguments ["write_registers" ]
9898 assert rr .registers == arguments ["write_registers" ]
@@ -103,7 +103,7 @@ async def handle_holding_registers(client):
103103async def handle_input_registers (client ):
104104 """Read input registers."""
105105 _logger .info ("### read input registers" )
106- rr = await client .read_input_registers (1 , 8 , unit = UNIT )
106+ rr = await client .read_input_registers (1 , 8 , slave = SLAVE )
107107 assert not rr .isError () # nosec test that we are not an error
108108 txt = f"### address 1 is: { str (rr .registers [0 ])} "
109109 _logger .debug (txt )
0 commit comments