Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
|
5eff7bb7d3 | |
|
9722b2b8d0 | |
|
bbc2f5e6cc |
|
@ -8,5 +8,5 @@ spec:
|
|||
package: requirements.txt # 설치할 Python 패키지 정보 파일입니다.(기본 값은 requirement.txt 입니다.)
|
||||
runtime: python3.9
|
||||
stackbase:
|
||||
tagName: v2.0.0 # Stackbase(gitea)에 릴리즈 태그명 입니다.
|
||||
tagName: v2.0.3 # Stackbase(gitea)에 릴리즈 태그명 입니다.
|
||||
repoName: aquarack-sensor-collector # Satackbase(gitea)에 저장될 저장소 이릅니다.
|
||||
|
|
37
main.py
37
main.py
|
@ -7,7 +7,7 @@ import threading
|
|||
sdtcloud = sdtcloudpubsub.sdtcloudpubsub()
|
||||
sdtcloud.setClient(f"device-app-{uuid.uuid1()}") # parameter is client ID(string)
|
||||
|
||||
def get_modbus(evt, serial_obj, file_path):
|
||||
def get_modbus(evt, serial_obj):
|
||||
global isThread, g_zero_point, pub_dict, a_col, d_col, t_col, p_col, S_col
|
||||
|
||||
ctl_mode = 'None'
|
||||
|
@ -20,7 +20,8 @@ def get_modbus(evt, serial_obj, file_path):
|
|||
evt.wait()
|
||||
evt.clear()
|
||||
|
||||
with open(os.path.join(file_path, 'control.json'), 'r') as f:
|
||||
# with open(os.path.join(file_path, 'control.json'), 'r') as f:
|
||||
with open('./control.json', 'r') as f:
|
||||
control_data = json.load(f)
|
||||
pre_dict = control_data.copy()
|
||||
|
||||
|
@ -42,7 +43,8 @@ def get_modbus(evt, serial_obj, file_path):
|
|||
# print(f'cdu_digital:{cdu_digital.bits}')
|
||||
|
||||
if control_data['set_zero_temperature'] == 'y':
|
||||
with open(os.path.join(file_path, 'config.json'), 'r') as f:
|
||||
# with open(os.path.join(file_path, 'config.json'), 'r') as f:
|
||||
with open('./config.json', 'r') as f:
|
||||
config_data = json.load(f)
|
||||
|
||||
for i, j in enumerate(a_col):
|
||||
|
@ -51,7 +53,8 @@ def get_modbus(evt, serial_obj, file_path):
|
|||
|
||||
control_data['set_zero_temperature'] = 'n'
|
||||
|
||||
with open(os.path.join(path, 'config.json'), 'w') as f:
|
||||
# with open(os.path.join(path, 'config.json'), 'w') as f:
|
||||
with open('./config.json', 'w') as f:
|
||||
json.dump(config_data, f, indent=4)
|
||||
|
||||
g_zero_point[0] = config_data['ref_zero_point']['oilInFlowRate']
|
||||
|
@ -95,7 +98,7 @@ def get_modbus(evt, serial_obj, file_path):
|
|||
|
||||
try:
|
||||
if control_data['mode'] == 'auto':
|
||||
if control_data['cmd'] == 'init':
|
||||
if control_data['cmd'] == 'init': # 방어코드 필요
|
||||
if cmd_sub_status == 'None':
|
||||
valve_status[0], valve_status[1] = True, True
|
||||
res = serial_obj.write_coils(address=0, values=valve_status, slave=5)
|
||||
|
@ -256,7 +259,7 @@ def get_modbus(evt, serial_obj, file_path):
|
|||
cmd_sub_status = 'None'
|
||||
control_data['cmd'] = 'None'
|
||||
|
||||
elif control_data['cmd'] == 'emer':
|
||||
elif control_data['cmd'] == 'emer': # 어느 조건에서든 입력되면 바로 수행
|
||||
if cmd_sub_status == 'None':
|
||||
valve_status[0], valve_status[1] = False, False
|
||||
res = serial_obj.write_coils(address=0, values=valve_status, slave=5)
|
||||
|
@ -325,7 +328,8 @@ def get_modbus(evt, serial_obj, file_path):
|
|||
print(f'Device Setting Error: {e}')
|
||||
|
||||
if pre_dict != control_data:
|
||||
with open(os.path.join(path, 'control.json'), 'w') as f:
|
||||
# with open(os.path.join(path, 'control.json'), 'w') as f:
|
||||
with open('./control.json', 'w') as f:
|
||||
json.dump(control_data, f, indent=4)
|
||||
|
||||
def get_sensor(evt, serial_obj):
|
||||
|
@ -356,7 +360,7 @@ def timer_s1(evt):
|
|||
time.sleep(5)
|
||||
|
||||
def runAction():
|
||||
global ctl_data, pub_data
|
||||
global ctl_data, pub_dict
|
||||
sum_data = {key: 0.0 for key in pub_dict.keys()}
|
||||
|
||||
cnt, cnt_limit = 0, 0
|
||||
|
@ -374,7 +378,7 @@ def runAction():
|
|||
while True:
|
||||
start = int(time.time() * 1000)
|
||||
|
||||
for key, value in pub_data.items():
|
||||
for key, value in pub_dict.items():
|
||||
try:
|
||||
sum_data[key] += value
|
||||
except:
|
||||
|
@ -386,6 +390,7 @@ def runAction():
|
|||
cnt += 1
|
||||
if cnt == cnt_limit:
|
||||
snd_data = {key: value / cnt_limit for key, value in sum_data.items()}
|
||||
# print(snd_data)
|
||||
sdtcloud.pubMessage(snd_data)
|
||||
cnt = 0
|
||||
sum_data = {key: 0.0 for key in pub_dict.keys()}
|
||||
|
@ -393,8 +398,8 @@ def runAction():
|
|||
time.sleep(sleep_time)
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.system(f'sudo chmod 777 /dev/ttyS0')
|
||||
os.system(f'sudo chmod 777 /dev/ttyS1')
|
||||
os.system(f'chmod 777 /dev/ttyS0')
|
||||
os.system(f'chmod 777 /dev/ttyS1')
|
||||
port_name_1 = '/dev/ttyS0'
|
||||
client1 = ModbusClient(port=port_name_1, baudrate=19200, parity='N', stopbits=1, bytesize=8, timeout=0.25)
|
||||
port_name_2 = '/dev/ttyS1'
|
||||
|
@ -408,11 +413,13 @@ if __name__ == "__main__":
|
|||
|
||||
g_zero_point = [0] * 2
|
||||
|
||||
path = '/home/ecn-2u/Aquarack/21u'
|
||||
with open(os.path.join(path, 'config.json'), 'r') as config:
|
||||
# path = '/home/ecn-2u/Aquarack/21u'
|
||||
# with open(os.path.join(path, 'config.json'), 'r') as config:
|
||||
with open('./config.json', 'r') as config:
|
||||
cfg_data = json.load(config)
|
||||
|
||||
with open(os.path.join(path, 'control.json'), 'r') as control:
|
||||
# with open(os.path.join(path, 'control.json'), 'r') as control:
|
||||
with open('./control.json', 'r') as control:
|
||||
ctl_data = json.load(control)
|
||||
|
||||
len_a_col = len(cfg_data['cdu_analog_list'])
|
||||
|
@ -468,7 +475,7 @@ if __name__ == "__main__":
|
|||
timer_evt_s0.set()
|
||||
timer_evt_s1.set()
|
||||
|
||||
thr_modbus_rtu = threading.Thread(target=get_modbus, args=(timer_evt_s0, client1, path,))
|
||||
thr_modbus_rtu = threading.Thread(target=get_modbus, args=(timer_evt_s0, client1, ))
|
||||
thr_modbus_rtu.start()
|
||||
|
||||
thr_get_sensor = threading.Thread(target=get_sensor, args=(timer_evt_s1, client2,))
|
||||
|
|
Loading…
Reference in New Issue