Compare commits

..

4 Commits

Author SHA1 Message Date
KwanghoKim eed0eacab4 1. Read_Temperature: register 주소 값 변경
2. Set_Temperature: 장비 구동 방법 변경
3. timestamp 값 milisecond 값으로 표현되도록 변경
2023-12-21 13:53:09 +09:00
KwanghoKim 8dbb6c0ba5 edit mulfunction 2023-12-15 15:49:53 +09:00
KwanghoKim a179f05921 edit typo2 2023-12-01 15:05:29 +09:00
KwanghoKim 75b77ba638 edit typo 2023-12-01 15:01:58 +09:00
1 changed files with 101 additions and 46 deletions

View File

@ -84,25 +84,25 @@ def Read_Temperature(client, ch_num):
id = 3 id = 3
name = 'tempFn3' name = 'tempFn3'
result = client.read_holding_registers(address=2003, count=2, slave=id) result = client.read_holding_registers(address=2002, 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 = {
"accetCode": info['mqtt']['assetCode'], "assetCode": info['mqtt']['assetCode'],
"timestamp": int(time.time()), "timestamp": int(time.time() * 1000),
"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, value): def Set_Temperature(client, ch_num, order, val=None):
if ch_num == 1: if ch_num == 1:
id = 1 id = 1
elif ch_num == 2: elif ch_num == 2:
@ -110,7 +110,66 @@ def Set_Temperature(client, ch_num, value):
else: # ch_num == 3 else: # ch_num == 3
id = 3 id = 3
return 0 if not val == None:
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:
@ -127,6 +186,7 @@ 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 = (
@ -139,7 +199,7 @@ def Read_Power(client, ch_num):
data = { data = {
"assetCode": info['mqtt']['assetCode'], "assetCode": info['mqtt']['assetCode'],
"timestamp": int(time.time()), "timestamp": int(time.time() * 1000),
"dataType": "DATA", "dataType": "DATA",
"data": { "data": {
name: value name: value
@ -205,7 +265,7 @@ def Read_GasDetector(client, ch_num):
data = { data = {
"assetCode": info['mqtt']['assetCode'], "assetCode": info['mqtt']['assetCode'],
"timestamp": int(time.time()), "timestamp": int(time.time() * 1000),
"dataType": "DATA", "dataType": "DATA",
"data": { "data": {
name_1: oxygen_value, name_1: oxygen_value,
@ -218,18 +278,10 @@ 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
# print(f'register_value: {register_value}') client.write_registers(address=3, values=register_value, slave=id)
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)
@ -262,14 +314,17 @@ 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, value=float(cmd['cmd']['tempFn1'])) Set_Temperature(client=client1, ch_num=1, order=cmd['type'], val=float(cmd['cmd']['tempFn1']))
if cmd['cmd']['tempFn2'] != 'null': if cmd['cmd']['tempFn2'] != 'null':
Set_Temperature(client=client2, ch_num=2, value=float(cmd['cmd']['tempFn1'])) Set_Temperature(client=client2, ch_num=2, order=cmd['type'], val=float(cmd['cmd']['tempFn2']))
if cmd['cmd']['tempFn3'] != 'null': if cmd['cmd']['tempFn3'] != 'null':
Set_Temperature(client=client2, ch_num=3, value=float(cmd['cmd']['tempFn1'])) Set_Temperature(client=client3, ch_num=3, order=cmd['type'], val=float(cmd['cmd']['tempFn3']))
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 = {
@ -289,12 +344,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)