Skip to content

Commit 925573f

Browse files
authored
fix remaining pymodbus errors
1 parent b1d3a42 commit 925573f

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

simulator/modbus/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -471,11 +471,11 @@ async def set_mapping_key(device_name: RemoteDeviceType) -> Tuple[RemoteDeviceTy
471471
client = AsyncModbusClient(host=device_ip, port=device_port, timeout=300000)
472472
await client.connect()
473473
if not client.connected:
474-
print(perf_counter(), type(self).__name__, device_name, "@", device_ip, ":", device_port, "=>", type(client.protocol))
474+
print(perf_counter(), type(self).__name__, device_name, "@", device_ip, ":", device_port, "=>", type(client))
475475
mapping: RemoteDeviceMapping = {
476476
"ip": IPString(device_ip),
477477
"port": device_port,
478-
"client": client.protocol,
478+
"client": client,
479479
"tags": device_class.create_tag_database()
480480
}
481481
return (device_name, mapping)

utils/otdump.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
async def connect(ip: str, port: int, timeout: float = 1) -> Optional[ModbusBaseClient]:
2222
client = AsyncModbusClient(host=ip, port=port, timeout=timeout, loop=asyncio.get_running_loop())
2323
await client.connect()
24-
if client.protocol is None:
24+
if not client.connected:
2525
await client.close()
2626
return None
27-
return client.protocol
27+
return client
2828

2929
async def read_tags(
3030
client: ModbusBaseClient,

utils/otset.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ async def run_tasks(address, class_name, tag_values) -> bool:
7979
client = AsyncModbusClient(host=ip, port=port, timeout=1, loop=asyncio.get_running_loop())
8080
await client.connect()
8181

82-
if client.protocol is not None and class_name in class_list:
82+
if client.connected and class_name in class_list:
8383
device_class = class_list[class_name]
8484
tag_database = device_class.create_tag_database()
8585
parsed_tag_values: List[Tuple[Tag, RegisterValue]] = []
@@ -92,7 +92,7 @@ async def run_tasks(address, class_name, tag_values) -> bool:
9292
if new_value is not None:
9393
parsed_tag_values.append((tag_type, new_value))
9494
if len(parsed_tag_values):
95-
await tell_device(client.protocol, args.unit_id, *parsed_tag_values)
95+
await tell_device(client, args.unit_id, *parsed_tag_values)
9696
return True
9797
return False
9898

0 commit comments

Comments
 (0)