-
Notifications
You must be signed in to change notification settings - Fork 0
/
schneider_test.py
executable file
·61 lines (46 loc) · 1.62 KB
/
schneider_test.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
#!/usr/bin/env python3
# Copyright 2021 Arup
# MIT License
import minimalmodbus
import serial
#import os
import sys
PORT = '/dev/ttyUSB0'
BAUDRATE = 9600
def get_readings():
instrument = minimalmodbus.Instrument(PORT, 1)
instrument.serial.baudrate = BAUDRATE
instrument.serial.parity = serial.PARITY_NONE
instrument.serial.timeout = 0.5
instrument.serial.stopbits = 1
instrument.serial.bytesize = 8
instrument.serial.timeout = 0.5
print(instrument.read_string(29,20))
print(instrument.read_string(49,20))
print(instrument.read_string(69,20))
print("Current: ", instrument.read_float(2999))
print("Voltage: ", instrument.read_float(3027))
print("Active Power: ", instrument.read_float(3053), "kW")
print("Reactive Power: ", instrument.read_float(3067), "kVAR")
print("Apparent Power: ", instrument.read_float(3075), "kVA")
# need to process quadrant information in the datasheet
pf = instrument.read_float(3083)
if pf < 0:
if pf < -1:
print("Power factor: ", -2-pf, " leading")
else:
print("Power factor: ", pf, " lagging")
else:
if pf > 1:
print("Power factor: ", 2-pf, " leading")
else:
print("Power factor: ", pf, " lagging")
print("Cumulative active energy: ", instrument.read_float(45099), "Wh")
print("Cumulative reactive energy: ", instrument.read_float(45101), "VARh")
# starts here
try:
get_readings()
except:
# if we reach here we likely have had an I/O error on the serial port.
sys.stderr.write("System error: probably serial port IO.\n")
sys.exit(1)