-
Notifications
You must be signed in to change notification settings - Fork 0
/
dds8558.py
73 lines (58 loc) · 2.99 KB
/
dds8558.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
import minimalmodbus
import serial
class DDS8558_Modbus():
"""Functions impmented from document SINGLE-PHASE TWO-WIRE DIN-RAIL ENERGY METER"""
def __init__(self, serial_device='/dev/ttyUSB0',modbus_address=125, baudrate=9600, debug=False):
self.instrument = minimalmodbus.Instrument(serial_device, modbus_address, minimalmodbus.MODE_RTU)
self.instrument.serial.baudrate = baudrate
self.instrument.serial.parity = serial.PARITY_EVEN
self.instrument.close_port_after_each_call = True
self.instrument.serial.bytesize = 8
self.instrument.serial.stopbits = 1
self.instrument.serial.timeout = 0.1
self.instrument.debug = debug
self.instrument.clear_buffers_before_each_transaction = True
#actutal adresses of the individual registers
self.Voltage = "0x0000"
self.Current = "0x0008"
def read_voltage(self):
"Data register Address in hex is below in hex"
value = self.instrument.read_float(int(self.Voltage, 0), functioncode=4, number_of_registers=2, byteorder=0)
return value
def read_current(self):
"Data register Address"
value = self.instrument.read_float(int(self.Current, 0), functioncode=4, number_of_registers=2, byteorder=0)
return value
def read_reactive_power(self):
"Data register Address"
Current = "0x0008"
value = self.instrument.read_float(int(Current, 0), functioncode=4, number_of_registers=2, byteorder=0)
return value
def read_active_power(self):
ActivePower = "0x0012"
value = self.instrument.read_float(int(ActivePower, 0), functioncode=4, number_of_registers=2, byteorder=0)
return value
def read_power_factor(self):
PowerFactor = "0x002A"
value = self.instrument.read_float(int(PowerFactor, 0), functioncode=4, number_of_registers=2, byteorder=0)
return value
def read_total_active_energy(self):
TotalActiveEnergy = "0x0100"
value = self.instrument.read_float(int(TotalActiveEnergy, 0), functioncode=4, number_of_registers=2,
byteorder=0)
return value
def read_total_reactive_energy(self):
TotalReactiveEnergy = "0x0400"
value = self.instrument.read_float(int(TotalReactiveEnergy, 0), functioncode=4, number_of_registers=2,
byteorder=0)
return value
def read_frequency(self):
Frequency = "0x0036"
value = self.instrument.read_float(int(Frequency, 0), functioncode=4, number_of_registers=2, byteorder=0)
return value
def reset_energy_values(self):
#didnt test it yet..usefull for resseting values now and then...
TotalActiveEnergy = "0x0100"
TotalReactiveEnergy = "0x0400"
self.instrument.write_float(int(TotalActiveEnergy, 0), 0, number_of_registers=2, byteorder=0)
self.instrument.write_float(int(TotalReactiveEnergy, 0), 0, number_of_registers=2, byteorder=0)