[clean] modbus/test_modbus

This commit is contained in:
Maxime Alves LIRMM@home 2020-08-02 09:37:36 +02:00
commit 8cd3184532
2 changed files with 13 additions and 4 deletions

View file

@ -33,12 +33,15 @@ def read_coils(start, end):
connect()
res = []
address = -1
qty = -1
try:
for address in range(start, end + 1, 125):
qty = 125 if (end - address) >= 125 else (end - address)
if not qty:
break
print(start, end, address, qty)
req_adu = rtu.read_coils(
slave_id=1,
starting_address=address,
@ -48,6 +51,8 @@ def read_coils(start, end):
res.extend(resp)
except umodbus.exceptions.IllegalDataAddressError as e:
print(e)
print(f'{address} {qty}')
return res
@ -57,12 +62,15 @@ def read_holding_registers(start, end):
connect()
res = []
address = -1
qty = -1
try:
for address in range(start, end + 1, 125):
qty = 125 if (end - address) >= 125 else (end - address)
if not qty:
break
print(start, end, address, qty)
req_adu = rtu.read_holding_registers(
slave_id=1,
starting_address=address,
@ -72,6 +80,8 @@ def read_holding_registers(start, end):
res.extend(resp)
except umodbus.exceptions.IllegalDataAddressError as e:
print(e)
print(f'{address} {qty}')
return res
if __name__ == '__main__':

View file

@ -33,7 +33,7 @@ def set_test_db():
yield
#os.unlink(tmpdb)
os.unlink(tmpdb)
@pytest.fixture(scope='module')
def serial_conn():
@ -123,4 +123,3 @@ def test_get_digital(set_test_db, serial_conn, var_types):
for r in res:
assert type(r) == int
assert r in [0, 1]