change how to measure power
This commit is contained in:
parent
a9040ed98d
commit
5140141eaa
|
@ -15,8 +15,8 @@ if os.system("lsmod | grep max7301") == 0:
|
|||
# For PION-D3W-035(Power Controller) No.1, UT35A(Temperature Controller) No.1
|
||||
_serial_port_A = serial.Serial('/dev/ttyMAX1', 38400, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout = 1, rtscts=True)
|
||||
_serial_port_A.rs485_mode = serial.rs485.RS485Settings()
|
||||
_serial_port_A.close()
|
||||
del _serial_port_A
|
||||
# _serial_port_A.close()
|
||||
# del _serial_port_A
|
||||
|
||||
client1 = ModbusClient(method='rtu', port='/dev/ttyMAX1', baudrate=38400,
|
||||
parity='N', stopbits=1, bytesize=8, timeout=1)
|
||||
|
@ -25,8 +25,8 @@ client1 = ModbusClient(method='rtu', port='/dev/ttyMAX1', baudrate=38400,
|
|||
# For PION-D3W-035(Power Controller) No.2, UT35A(Temperature Controller) No.1
|
||||
_serial_port_B = serial.Serial('/dev/ttyMAX0', 38400, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout = 1, rtscts=True)
|
||||
_serial_port_B.rs485_mode = serial.rs485.RS485Settings()
|
||||
_serial_port_B.close()
|
||||
del _serial_port_B
|
||||
# _serial_port_B.close()
|
||||
# del _serial_port_B
|
||||
|
||||
client2 = ModbusClient(method='rtu', port='/dev/ttyMAX0', baudrate=38400,
|
||||
parity='N', stopbits=1, bytesize=8, timeout=1)
|
||||
|
@ -34,8 +34,8 @@ client2 = ModbusClient(method='rtu', port='/dev/ttyMAX0', baudrate=38400,
|
|||
# For PION-D3W-035(Power Controller) No.3, UT35A(Temperature Controller) No.1
|
||||
_serial_port_C = serial.Serial('/dev/ttyMAX2', 38400, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout = 1, rtscts=True)
|
||||
_serial_port_C.rs485_mode = serial.rs485.RS485Settings()
|
||||
_serial_port_C.close()
|
||||
del _serial_port_C
|
||||
# _serial_port_C.close()
|
||||
# del _serial_port_C
|
||||
|
||||
client3 = ModbusClient(method='rtu', port='/dev/ttyMAX2', baudrate=38400,
|
||||
parity='N', stopbits=1, bytesize=8, timeout=1)
|
||||
|
@ -84,9 +84,10 @@ def Read_Temperature(client, ch_num):
|
|||
id = 3
|
||||
name = 'tempFn3'
|
||||
|
||||
result = client.read_holding_registers(address=2003, count=1, slave=id)
|
||||
result = client.read_holding_registers(address=2003, count=2, slave=id)
|
||||
if not result.isError():
|
||||
# print(f'Temperature: {ch_num} {result.registers}')
|
||||
# value = (result.registers[0] * 256 + result.registers[1])/10
|
||||
value = (result.registers[0])/10
|
||||
else:
|
||||
print(f'Temperature Err: {ch_num} \n {result}')
|
||||
|
@ -123,20 +124,19 @@ def Read_Power(client, ch_num):
|
|||
id = 13
|
||||
name = 'enerWn3'
|
||||
|
||||
r_high = client.read_input_registers(address=325, count=1, slave=id)
|
||||
r_low = client.read_input_registers(address=326, count=1, slave=id)
|
||||
s_high = client.read_input_registers(address=327, count=1, slave=id)
|
||||
s_low = client.read_input_registers(address=328, count=1, slave=id)
|
||||
t_high = client.read_input_registers(address=329, count=1, slave=id)
|
||||
t_low = client.read_input_registers(address=330, count=1, slave=id)
|
||||
# print(f'r_high: {r_high.registers[0]} {r_high.registers[1]}, r_low: {r_low.registers[0]} {r_low.registers[1]}')
|
||||
# print(f's_high: {s_high.registers[0]}, s_low: {s_low.registers[0]}')
|
||||
# print(f't_high: {t_high.registers[0]}, t_low: {t_low.registers[0]}')
|
||||
value = (
|
||||
(r_high.registers[0] << 16) + r_low.registers[0] +
|
||||
(s_high.registers[0] << 16) + s_low.registers[0] +
|
||||
(t_high.registers[0] << 16) + t_low.registers[0]
|
||||
)
|
||||
r_power_rate = client.read_input_registers(address=305, count=1, slave=id)
|
||||
s_power_rate = client.read_input_registers(address=306, count=1, slave=id)
|
||||
t_power_rate = client.read_input_registers(address=307, count=1, slave=id)
|
||||
|
||||
max_power = 23036
|
||||
|
||||
mean_power_rate = (
|
||||
(r_power_rate.registers[0] +
|
||||
s_power_rate.registers[0] +
|
||||
t_power_rate.registers[0]) / 30000)
|
||||
|
||||
value = (max_power * mean_power_rate) / 1000
|
||||
# print(value)
|
||||
|
||||
data = {
|
||||
"assetCode": info['mqtt']['assetCode'],
|
||||
|
@ -298,4 +298,5 @@ while True:
|
|||
# print(f'diff: {diff}')
|
||||
|
||||
if diff < 3:
|
||||
time.sleep(3.0 - diff)
|
||||
time.sleep(3.0 - diff)
|
||||
|
||||
|
|
Loading…
Reference in New Issue