Compare commits
No commits in common. "main" and "Version_1.0" have entirely different histories.
main
...
Version_1.
|
@ -47,7 +47,7 @@ _serial_port_D.rs485_mode = serial.rs485.RS485Settings()
|
||||||
# del _serial_port_A
|
# del _serial_port_A
|
||||||
|
|
||||||
client4 = ModbusClient(method='rtu', port='/dev/ttyMAX3', baudrate=9600,
|
client4 = ModbusClient(method='rtu', port='/dev/ttyMAX3', baudrate=9600,
|
||||||
parity='N', stopbits=1, bytesize=8, timeout=0.5)
|
parity='E', stopbits=1, bytesize=8, timeout=0.5)
|
||||||
|
|
||||||
client1.connect()
|
client1.connect()
|
||||||
client2.connect()
|
client2.connect()
|
||||||
|
@ -84,25 +84,25 @@ def Read_Temperature(client, ch_num):
|
||||||
id = 3
|
id = 3
|
||||||
name = 'tempFn3'
|
name = 'tempFn3'
|
||||||
|
|
||||||
result = client.read_holding_registers(address=2002, count=1, slave=id)
|
result = client.read_holding_registers(address=2003, count=1, 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])/10
|
value = (result.registers[0])/10
|
||||||
|
else:
|
||||||
|
print(f'Temperature Err: {ch_num} \n {result}')
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"assetCode": info['mqtt']['assetCode'],
|
"accetCode": info['mqtt']['assetCode'],
|
||||||
"timestamp": int(time.time() * 1000),
|
"timestamp": int(time.time()),
|
||||||
"dataType": "DATA",
|
"datatype": "DATA",
|
||||||
"data": {
|
"data": {
|
||||||
name: value
|
name: value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Publish_mqtt(data)
|
Publish_mqtt(data)
|
||||||
else:
|
|
||||||
print(f'Temperature Err: {ch_num} \n {result}')
|
|
||||||
|
|
||||||
def Set_Temperature(client, ch_num, order, val=None):
|
def Set_Temperature(client, ch_num, value):
|
||||||
if ch_num == 1:
|
if ch_num == 1:
|
||||||
id = 1
|
id = 1
|
||||||
elif ch_num == 2:
|
elif ch_num == 2:
|
||||||
|
@ -110,66 +110,7 @@ def Set_Temperature(client, ch_num, order, val=None):
|
||||||
else: # ch_num == 3
|
else: # ch_num == 3
|
||||||
id = 3
|
id = 3
|
||||||
|
|
||||||
if not val == None:
|
return 0
|
||||||
val *= 10
|
|
||||||
val = int(val)
|
|
||||||
|
|
||||||
try:
|
|
||||||
if order == 'start':
|
|
||||||
# Patten 1
|
|
||||||
client.write_register(address=8000, value=1, slave=id) # PTNO._C
|
|
||||||
client.write_register(address=8004, value=1, slave=id) # STC
|
|
||||||
|
|
||||||
# SEG 0
|
|
||||||
client.write_register(address=8001, value=0, slave=id) # SEGNO._C
|
|
||||||
client.write_register(address=8002, value=0, slave=id) # SSP_L1
|
|
||||||
|
|
||||||
# SEG 1
|
|
||||||
client.write_register(address=8001, value=1, slave=id) # SEGNO._C
|
|
||||||
|
|
||||||
client.write_register(address=8102, value=val, slave=id) # TSP_L1
|
|
||||||
client.write_register(address=8104, value=180, slave=id) # TIME
|
|
||||||
|
|
||||||
# SEG 2
|
|
||||||
client.write_register(address=8001, value=2, slave=id) # SEGNO._C
|
|
||||||
|
|
||||||
client.write_register(address=8102, value=val, slave=id) # TSP_L1
|
|
||||||
client.write_register(address=8104, value=1440, slave=id) # TIME
|
|
||||||
|
|
||||||
# Power On
|
|
||||||
client.write_register(address=2321, value=1, slave=id) # PTNO.
|
|
||||||
client.write_register(address=2315, value=1, slave=id) # MODE
|
|
||||||
elif order == 'change':
|
|
||||||
# Power Off
|
|
||||||
client.write_register(address=2315, value=0, slave=id) # MODE
|
|
||||||
|
|
||||||
# Patten 1
|
|
||||||
client.write_register(address=8000, value=1, slave=id) # PTNO._C
|
|
||||||
client.write_register(address=8004, value=1, slave=id) # STC
|
|
||||||
|
|
||||||
# SEG 0
|
|
||||||
client.write_register(address=8001, value=0, slave=id) # SEGNO._C
|
|
||||||
client.write_register(address=8002, value=0, slave=id) # SSP_L1
|
|
||||||
|
|
||||||
# SEG 1
|
|
||||||
client.write_register(address=8001, value=1, slave=id) # SEGNO._C
|
|
||||||
|
|
||||||
client.write_register(address=8102, value=val, slave=id) # TSP_L1
|
|
||||||
client.write_register(address=8104, value=180, slave=id) # TIME
|
|
||||||
|
|
||||||
# SEG 2
|
|
||||||
client.write_register(address=8001, value=2, slave=id) # SEGNO._C
|
|
||||||
|
|
||||||
client.write_register(address=8102, value=val, slave=id) # TSP_L1
|
|
||||||
client.write_register(address=8104, value=1440, slave=id) # TIME
|
|
||||||
|
|
||||||
client.write_register(address=2321, value=1, slave=id) # PTNO.
|
|
||||||
client.write_register(address=2315, value=1, slave=id) # MODE
|
|
||||||
else: # order == 'stop'
|
|
||||||
# Power Off
|
|
||||||
client.write_register(address=2315, value=0, slave=id) # MODE
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
|
|
||||||
def Read_Power(client, ch_num):
|
def Read_Power(client, ch_num):
|
||||||
if ch_num == 1:
|
if ch_num == 1:
|
||||||
|
@ -182,24 +123,24 @@ def Read_Power(client, ch_num):
|
||||||
id = 13
|
id = 13
|
||||||
name = 'enerWn3'
|
name = 'enerWn3'
|
||||||
|
|
||||||
r_power_rate = client.read_input_registers(address=305, count=1, slave=id)
|
r_high = client.read_input_registers(address=325, count=1, slave=id)
|
||||||
s_power_rate = client.read_input_registers(address=306, count=1, slave=id)
|
r_low = client.read_input_registers(address=326, count=1, slave=id)
|
||||||
t_power_rate = client.read_input_registers(address=307, 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)
|
||||||
if not r_power_rate.isError() and not s_power_rate.isError() and not t_power_rate.isError():
|
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'],
|
||||||
"timestamp": int(time.time() * 1000),
|
"timestamp": int(time.time()),
|
||||||
"dataType": "DATA",
|
"dataType": "DATA",
|
||||||
"data": {
|
"data": {
|
||||||
name: value
|
name: value
|
||||||
|
@ -265,7 +206,7 @@ def Read_GasDetector(client, ch_num):
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"assetCode": info['mqtt']['assetCode'],
|
"assetCode": info['mqtt']['assetCode'],
|
||||||
"timestamp": int(time.time() * 1000),
|
"timestamp": int(time.time()),
|
||||||
"dataType": "DATA",
|
"dataType": "DATA",
|
||||||
"data": {
|
"data": {
|
||||||
name_1: oxygen_value,
|
name_1: oxygen_value,
|
||||||
|
@ -278,10 +219,9 @@ def Read_GasDetector(client, ch_num):
|
||||||
def Set_FlowPump(client, value):
|
def Set_FlowPump(client, value):
|
||||||
id = 31
|
id = 31
|
||||||
|
|
||||||
val = int(float(value) * 1000)
|
register_value = int(((value * 0.32) + 4) * 2500)
|
||||||
|
|
||||||
register_value = val * 8 + 10000
|
client.write_registers(address=40004, values=register_value, slave=id)
|
||||||
client.write_registers(address=3, values=register_value, slave=id)
|
|
||||||
|
|
||||||
def Publish_mqtt(data):
|
def Publish_mqtt(data):
|
||||||
send_mqtt_data = json.dumps(data, indent=4)
|
send_mqtt_data = json.dumps(data, indent=4)
|
||||||
|
@ -306,25 +246,20 @@ def Command_Read():
|
||||||
with open(f'{ROOT_PATH}/control.json') as f:
|
with open(f'{ROOT_PATH}/control.json') as f:
|
||||||
cmd = json.load(f)
|
cmd = json.load(f)
|
||||||
|
|
||||||
# print(cmd)
|
|
||||||
|
|
||||||
if cmd['type'] != 'null':
|
if cmd['type'] != 'null':
|
||||||
if 'start' in cmd['type'] or 'change' in cmd['type']:
|
if 'start' in cmd['type'] or 'change' in cmd['type']:
|
||||||
if cmd['cmd']['precAc'] != 'null':
|
if cmd['cmd']['precAc'] != 'null':
|
||||||
Set_FlowPump(client=client4, value=float(cmd['cmd']['precAc']))
|
Set_FlowPump(client=client4, value=float(cmd['cmd']['precAc']))
|
||||||
|
|
||||||
if cmd['cmd']['tempFn1'] != 'null':
|
if cmd['cmd']['tempFn1'] != 'null':
|
||||||
Set_Temperature(client=client1, ch_num=1, order=cmd['type'], val=float(cmd['cmd']['tempFn1']))
|
Set_Temperature(client=client1, ch_num=1, value=float(cmd['cmd']['tempFn1']))
|
||||||
|
|
||||||
if cmd['cmd']['tempFn2'] != 'null':
|
if cmd['cmd']['tempFn2'] != 'null':
|
||||||
Set_Temperature(client=client2, ch_num=2, order=cmd['type'], val=float(cmd['cmd']['tempFn2']))
|
Set_Temperature(client=client2, ch_num=2, value=float(cmd['cmd']['tempFn1']))
|
||||||
|
|
||||||
if cmd['cmd']['tempFn3'] != 'null':
|
if cmd['cmd']['tempFn3'] != 'null':
|
||||||
Set_Temperature(client=client3, ch_num=3, order=cmd['type'], val=float(cmd['cmd']['tempFn3']))
|
Set_Temperature(client=client2, ch_num=3, value=float(cmd['cmd']['tempFn1']))
|
||||||
else: # 'stop' in cmd['type]
|
else: # 'stop' in cmd['type]
|
||||||
Set_Temperature(client=client1, ch_num=1, order=cmd['type'])
|
|
||||||
Set_Temperature(client=client2, ch_num=2, order=cmd['type'])
|
|
||||||
Set_Temperature(client=client3, ch_num=3, order=cmd['type'])
|
|
||||||
Set_FlowPump(client=client4, value=0.0)
|
Set_FlowPump(client=client4, value=0.0)
|
||||||
|
|
||||||
cmd = {
|
cmd = {
|
||||||
|
@ -344,12 +279,12 @@ while True:
|
||||||
# Need to add a function call for reading control.json
|
# Need to add a function call for reading control.json
|
||||||
Command_Read()
|
Command_Read()
|
||||||
|
|
||||||
# Read Temperature
|
# # Read Temperature
|
||||||
Read_Temperature(client1, 1)
|
Read_Temperature(client1, 1)
|
||||||
Read_Temperature(client2, 2)
|
Read_Temperature(client2, 2)
|
||||||
Read_Temperature(client3, 3)
|
Read_Temperature(client3, 3)
|
||||||
|
|
||||||
# Read Power
|
# # Read Power
|
||||||
Read_Power(client1, 1)
|
Read_Power(client1, 1)
|
||||||
Read_Power(client2, 2)
|
Read_Power(client2, 2)
|
||||||
Read_Power(client3, 3)
|
Read_Power(client3, 3)
|
||||||
|
|
Loading…
Reference in New Issue