|
@@ -6,6 +6,7 @@ import umodbus
|
6
|
6
|
from pprint import pprint
|
7
|
7
|
|
8
|
8
|
from .config import config
|
|
9
|
+from .models import *
|
9
|
10
|
|
10
|
11
|
serial_conn = None
|
11
|
12
|
|
|
@@ -85,6 +86,33 @@ def read_holding_registers(start, end):
|
85
|
86
|
|
86
|
87
|
return res
|
87
|
88
|
|
|
89
|
+def write_coil(var_value: VariableValue):
|
|
90
|
+ global serial_conn
|
|
91
|
+ connect()
|
|
92
|
+
|
|
93
|
+ try:
|
|
94
|
+ req_adu = rtu.write_single_coil(
|
|
95
|
+ slave_id=1,
|
|
96
|
+ address=var_value.address,
|
|
97
|
+ value=var_value.value)
|
|
98
|
+ return resp.send_message(req_adu, serial_conn)
|
|
99
|
+ except Exception as e:
|
|
100
|
+ raise e
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+def write_holding_register(var_value: VariableValue):
|
|
104
|
+ global serial_conn
|
|
105
|
+ connect()
|
|
106
|
+
|
|
107
|
+ try:
|
|
108
|
+ req_adu = rtu.write_single_register(
|
|
109
|
+ slave_id=1,
|
|
110
|
+ address=var_value.address,
|
|
111
|
+ value=var_value.value)
|
|
112
|
+ return resp.send_message(req_adu, serial_conn)
|
|
113
|
+ except Exception as e:
|
|
114
|
+ raise e
|
|
115
|
+
|
88
|
116
|
if __name__ == '__main__':
|
89
|
117
|
resp = read_holding_registers(1, 5000)
|
90
|
118
|
#pprint(resp)
|