Browse Source

[clean] modbus/test_modbus

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

+ 1
- 2
tests/test_modbus.py View File

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

Loading…
Cancel
Save