change how to measure power

This commit is contained in:
KwanghoKim 2023-12-01 12:47:26 +09:00
parent a9040ed98d
commit 5140141eaa
1 changed files with 23 additions and 22 deletions

View File

@ -15,8 +15,8 @@ if os.system("lsmod | grep max7301") == 0:
# For PION-D3W-035(Power Controller) No.1, UT35A(Temperature Controller) No.1 # 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 = 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.rs485_mode = serial.rs485.RS485Settings()
_serial_port_A.close() # _serial_port_A.close()
del _serial_port_A # del _serial_port_A
client1 = ModbusClient(method='rtu', port='/dev/ttyMAX1', baudrate=38400, client1 = ModbusClient(method='rtu', port='/dev/ttyMAX1', baudrate=38400,
parity='N', stopbits=1, bytesize=8, timeout=1) 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 # 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 = 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.rs485_mode = serial.rs485.RS485Settings()
_serial_port_B.close() # _serial_port_B.close()
del _serial_port_B # del _serial_port_B
client2 = ModbusClient(method='rtu', port='/dev/ttyMAX0', baudrate=38400, client2 = ModbusClient(method='rtu', port='/dev/ttyMAX0', baudrate=38400,
parity='N', stopbits=1, bytesize=8, timeout=1) 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 # 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 = 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.rs485_mode = serial.rs485.RS485Settings()
_serial_port_C.close() # _serial_port_C.close()
del _serial_port_C # del _serial_port_C
client3 = ModbusClient(method='rtu', port='/dev/ttyMAX2', baudrate=38400, client3 = ModbusClient(method='rtu', port='/dev/ttyMAX2', baudrate=38400,
parity='N', stopbits=1, bytesize=8, timeout=1) parity='N', stopbits=1, bytesize=8, timeout=1)
@ -84,9 +84,10 @@ def Read_Temperature(client, ch_num):
id = 3 id = 3
name = 'tempFn3' 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(): if not result.isError():
# print(f'Temperature: {ch_num} {result.registers}') # print(f'Temperature: {ch_num} {result.registers}')
# value = (result.registers[0] * 256 + result.registers[1])/10
value = (result.registers[0])/10 value = (result.registers[0])/10
else: else:
print(f'Temperature Err: {ch_num} \n {result}') print(f'Temperature Err: {ch_num} \n {result}')
@ -123,20 +124,19 @@ def Read_Power(client, ch_num):
id = 13 id = 13
name = 'enerWn3' name = 'enerWn3'
r_high = client.read_input_registers(address=325, count=1, slave=id) r_power_rate = client.read_input_registers(address=305, count=1, slave=id)
r_low = client.read_input_registers(address=326, count=1, slave=id) s_power_rate = client.read_input_registers(address=306, count=1, slave=id)
s_high = client.read_input_registers(address=327, count=1, slave=id) t_power_rate = client.read_input_registers(address=307, 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) max_power = 23036
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]}') mean_power_rate = (
# print(f's_high: {s_high.registers[0]}, s_low: {s_low.registers[0]}') (r_power_rate.registers[0] +
# print(f't_high: {t_high.registers[0]}, t_low: {t_low.registers[0]}') s_power_rate.registers[0] +
value = ( t_power_rate.registers[0]) / 30000)
(r_high.registers[0] << 16) + r_low.registers[0] +
(s_high.registers[0] << 16) + s_low.registers[0] + value = (max_power * mean_power_rate) / 1000
(t_high.registers[0] << 16) + t_low.registers[0] # print(value)
)
data = { data = {
"assetCode": info['mqtt']['assetCode'], "assetCode": info['mqtt']['assetCode'],
@ -299,3 +299,4 @@ while True:
if diff < 3: if diff < 3:
time.sleep(3.0 - diff) time.sleep(3.0 - diff)