Browse Source

[clean] modbus/test_modbus

Maxime Alves LIRMM@home 3 years ago
parent
commit
8cd3184532
2 changed files with 13 additions and 4 deletions
  1. 12
    2
      pyheatpump/modbus.py
  2. 1
    2
      tests/test_modbus.py

+ 12
- 2
pyheatpump/modbus.py View File

@@ -33,12 +33,15 @@ def read_coils(start, end):
33 33
     connect()
34 34
     res = []
35 35
 
36
+    address = -1
37
+    qty = -1
38
+
36 39
     try:
37 40
         for address in range(start, end + 1, 125):
38 41
             qty = 125 if (end - address) >= 125 else (end - address)
39 42
             if not qty:
40 43
                 break
41
-            print(start, end, address, qty)
44
+
42 45
             req_adu = rtu.read_coils(
43 46
                 slave_id=1,
44 47
                 starting_address=address,
@@ -48,6 +51,8 @@ def read_coils(start, end):
48 51
             res.extend(resp)
49 52
     except umodbus.exceptions.IllegalDataAddressError as e:
50 53
         print(e)
54
+        print(f'{address} {qty}')
55
+
51 56
     return res
52 57
 
53 58
 
@@ -57,12 +62,15 @@ def read_holding_registers(start, end):
57 62
     connect()
58 63
     res = []
59 64
 
65
+    address = -1
66
+    qty = -1
67
+
60 68
     try:
61 69
         for address in range(start, end + 1, 125):
62 70
             qty = 125 if (end - address) >= 125 else (end - address)
63 71
             if not qty:
64 72
                 break
65
-            print(start, end, address, qty)
73
+
66 74
             req_adu = rtu.read_holding_registers(
67 75
                 slave_id=1,
68 76
                 starting_address=address,
@@ -72,6 +80,8 @@ def read_holding_registers(start, end):
72 80
             res.extend(resp)
73 81
     except umodbus.exceptions.IllegalDataAddressError as e:
74 82
         print(e)
83
+        print(f'{address} {qty}')
84
+
75 85
     return res
76 86
 
77 87
 if __name__ == '__main__':

+ 1
- 2
tests/test_modbus.py View File

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

Loading…
Cancel
Save