-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwattmeter.py.save
44 lines (30 loc) · 857 Bytes
/
wattmeter.py.save
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import time
import struct
from pyModbusTCP.client import ModbusClient
while True:
# TCP auto connect on first modbus request
c = ModbusClient(host="10.208.8.125", port=502, auto_open=True)
regs = c.read_input_registers(19026, 2)
a = regs[0]
b= regs[1]
fl = struct.unpack('!f', bytes.fromhex('{0:02x}'.format(a) + '{0:02x}'.format(b)))
print (a,b)
print (fl)
time.sleep(0.1)
'''
import struct
from pyModbusTCP.client import ModbusClient
# TCP auto connect on first modbus request
c = ModbusClient(host="10.208.8.125", port=502, auto_open=True)
regs = c.read_input_registers(4884, 2)
a = regs[0]
b= regs[1]
fl = struct.unpack('!f', bytes.fromhex('{0:02x}'.format(a) + '{0:02x}'.format(b)))
print (fl)
if regs:
print(regs)
#result = regs.registers
#print (result)
else:
print("read error")
'''