-
Notifications
You must be signed in to change notification settings - Fork 0
/
7kt.py
106 lines (85 loc) · 3.73 KB
/
7kt.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python3
import minimalmodbus
import serial
import sys
addr = int(sys.argv[1])
what = ""
if len(sys.argv) > 2:
what = sys.argv[2]
instrument = minimalmodbus.Instrument('/dev/ttyUSB0', addr) # port name, slave address (in decimal)
instrument.serial.baudrate = 19200 # Baud
instrument.serial.bytesize = 8
instrument.serial.parity = serial.PARITY_NONE
instrument.serial.stopbits = 1
instrument.serial.timeout = 0.05 # seconds
instrument.mode = minimalmodbus.MODE_RTU # rtu or ascii mode
instrument.clear_buffers_before_each_transaction = True
if what == 'voltage.fase_average':
print(instrument.read_long(0x0034,3,False)/100)
elif what == 'voltage.fase_l1':
print(instrument.read_long(0x0002,3,False)/100)
elif what == "voltage.fase_l2":
print(instrument.read_long(0x0004,3,False)/100)
elif what == "voltage.fase_l3":
print(instrument.read_long(0x0006,3,False)/100)
elif what == "voltage.average":
print(instrument.read_long(0x0036,3,False)/100)
elif what == "voltage.l1":
print(instrument.read_long(0x000E,3,False)/100)
elif what == "voltage.l2":
print(instrument.read_long(0x0010,3,False)/100)
elif what == "voltage.l3":
print(instrument.read_long(0x0012,3,False)/100)
elif what == "frequency":
print(instrument.read_long(0x0032,3,False)/1000)
elif what == "current.l1":
print(instrument.read_long(0x0008,3,False)/10000)
elif what == "current.l2":
print(instrument.read_long(0x000A,3,False)/10000)
elif what == "current.l3":
print(instrument.read_long(0x000C,3,False)/10000)
elif what == "power.average":
print(instrument.read_long(0x003A,3,True)/100)
elif what == "power.l1":
print(instrument.read_long(0x0014,3,True)/100)
elif what == "power.l2":
print(instrument.read_long(0x0016,3,True)/100)
elif what == "power.l3":
print(instrument.read_long(0x0018,3,True)/100)
elif what == "power_factor.average":
print(instrument.read_long(0x0040,3,True)/10000)
elif what == "power_factor.l1":
print(instrument.read_long(0x0026,3,True)/10000)
elif what == "power_factor.l2":
print(instrument.read_long(0x0028,3,True)/10000)
elif what == "power_factor.l3":
print(instrument.read_long(0x002A,3,True)/10000)
elif what == "":
#Voltage of fase L1-L2-L3
print("voltage.fase_average:",instrument.read_long(0x0034,3,False)/100)
print("voltage.fase_l1:",instrument.read_long(0x0002,3,False)/100)
print("voltage.fase_l2:",instrument.read_long(0x0004,3,False)/100)
print("voltage.fase_l3:",instrument.read_long(0x0006,3,False)/100)
#Voltage L1-L2-L3
print("voltage.average:",instrument.read_long(0x0036,3,False)/100)
print("voltage.l1:",instrument.read_long(0x000E,3,False)/100)
print("voltage.l2:",instrument.read_long(0x0010,3,False)/100)
print("voltage.l3:",instrument.read_long(0x0012,3,False)/100)
#Frequency
print("frequency:",instrument.read_long(0x0032,3,False)/1000)
#Current L1-L2-L3
print("current.l1:",instrument.read_long(0x0008,3,False)/10000)
print("current.l2:",instrument.read_long(0x000A,3,False)/10000)
print("current.l3:",instrument.read_long(0x000C,3,False)/10000)
#Active Power L1-L2-L3
print("power:",instrument.read_long(0x003A,3,True)/100)
print("power.l1:",instrument.read_long(0x0014,3,True)/100)
print("power.l2:",instrument.read_long(0x0016,3,True)/100)
print("power.l3:",instrument.read_long(0x0018,3,True)/100)
#Power Factor
print("power_factor.average:",instrument.read_long(0x0040,3,True)/10000)
print("power_factor.l1:",instrument.read_long(0x0026,3,True)/10000)
print("power_factor.l2:",instrument.read_long(0x0028,3,True)/10000)
print("power_factor.l3:",instrument.read_long(0x002A,3,True)/10000)
else:
print("NaN")