Compare commits
No commits in common. "main" and "Version_1.3" have entirely different histories.
main
...
Version_1.
|
@ -84,14 +84,16 @@ 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=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])/10
|
value = (result.registers[0])/10
|
||||||
|
else:
|
||||||
|
print(f'Temperature Err: {ch_num} \n {result}')
|
||||||
|
|
||||||
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
|
||||||
|
@ -99,10 +101,8 @@ def Read_Temperature(client, ch_num):
|
||||||
}
|
}
|
||||||
|
|
||||||
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:
|
||||||
|
@ -186,7 +127,6 @@ def Read_Power(client, ch_num):
|
||||||
s_power_rate = client.read_input_registers(address=306, 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)
|
t_power_rate = client.read_input_registers(address=307, count=1, slave=id)
|
||||||
|
|
||||||
if not r_power_rate.isError() and not s_power_rate.isError() and not t_power_rate.isError():
|
|
||||||
max_power = 23036
|
max_power = 23036
|
||||||
|
|
||||||
mean_power_rate = (
|
mean_power_rate = (
|
||||||
|
@ -199,7 +139,7 @@ def Read_Power(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: value
|
name: value
|
||||||
|
@ -265,7 +205,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 +218,18 @@ def Read_GasDetector(client, ch_num):
|
||||||
def Set_FlowPump(client, value):
|
def Set_FlowPump(client, value):
|
||||||
id = 31
|
id = 31
|
||||||
|
|
||||||
|
# print(f'Set_FlowPump In!: {value}')
|
||||||
val = int(float(value) * 1000)
|
val = int(float(value) * 1000)
|
||||||
|
|
||||||
register_value = val * 8 + 10000
|
register_value = val * 8 + 10000
|
||||||
client.write_registers(address=3, values=register_value, slave=id)
|
# print(f'register_value: {register_value}')
|
||||||
|
client.write_registers(address=40004, values=register_value, slave=id)
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = client.read_holding_registers(address=40004, count=1, slave=id)
|
||||||
|
# print(f'result: {result.registers}')
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
def Publish_mqtt(data):
|
def Publish_mqtt(data):
|
||||||
send_mqtt_data = json.dumps(data, indent=4)
|
send_mqtt_data = json.dumps(data, indent=4)
|
||||||
|
@ -314,17 +262,14 @@ def Command_Read():
|
||||||
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 +289,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