Multi-SNICS_Interlock/Listen2Arduino.py
2024-02-08 17:34:00 -05:00

118 lines
3.6 KiB
Python
Executable File

#!/usr/bin/python
import serial
import os
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=1)
ser.reset_input_buffer()
outFile = "/home/pi02/data.txt"
cmd='curl -s -XPOST "http://fsunuc.physics.fsu.edu:8086/write?db=interlock" --data-binary @/home/pi02/data.txt'
OPEN = 0
CLOSED = 1
input_normal= [
OPEN, #// Reset switch
CLOSED, #// Emergency source trip switch
CLOSED, #// Cage door contact
CLOSED, #// Fume hood flow switch
OPEN, #// Vacuum condition - gnd
CLOSED, #// Tritium monitor
OPEN, #// UNUSED
CLOSED, #// Power failure
CLOSED, #// Coolant flow - gnd
OPEN, #// Vacuum condition - mid
OPEN, #// UNUSED
CLOSED, #// Coolant flow - high
OPEN, #// Smoke detector - high
OPEN, #// UNUSED
OPEN, #// UNUSED
OPEN #// UNUSED
]
in_txt = [ "Reset Button",
"Emergency Switch",
"Cage Door Open",
"Fume Hood Flow",
"Vacuum Gauge 2",
"Tritium Monitor",
"error: port map",
"Bldg Power Fail",
"Coolant Flow 2",
"Vacuum Gauge 1",
"error: port map",
"Coolant Flow 1",
"Smoke at Source",
"error: port map",
"error: port map",
"error: port map",
""]
while True:
if ser.in_waiting > 0:
line = ser.readline().decode('utf-8').rstrip()
list = []
components = line.split(';')
format_value = {}
for component in components:
parts = component.strip().split(': ')
if len(parts) == 2:
key, valueUnit = parts
part2 = valueUnit.split(' ')
if len(part2) == 2:
value, unit = part2
if value == "ovf" :
value = 99999
format_value[key] = value
else:
format_value[key] = valueUnit
else:
list.append(component)
# print(line)
# for key, value in format_value.items():
# print(f"{key} value={value}")
with open(outFile, "w") as file:
for key, value in format_value.items():
file.write(f"{key} value={value}\n")
if key == "State" :
if value == "0" or value == "1":
file.write(f"preaccl value=1\n")
file.write(f"valve1 value=1\n")
file.write(f"valve2 value=1\n")
file.write(f"hv value=1\n")
file.write(f"boiler value=1\n")
file.write(f"ion value=1\n")
if value == "2":
file.write(f"preaccl value=0\n")
file.write(f"valve1 value=1\n")
file.write(f"valve2 value=1\n")
file.write(f"hv value=0\n")
file.write(f"boiler value=1\n")
file.write(f"ion value=1\n")
if value == "3":
file.write(f"preaccl value=0\n")
file.write(f"valve1 value=0\n")
file.write(f"valve2 value=0\n")
file.write(f"hv value=0\n")
file.write(f"boiler value=1\n")
file.write(f"ion value=0\n")
if value == "4":
file.write(f"preaccl value=0\n")
file.write(f"valve1 value=0\n")
file.write(f"valve2 value=0\n")
file.write(f"hv value=0\n")
file.write(f"boiler value=0\n")
file.write(f"ion value=0\n")
for i in range(16):
if int(list[i]) != input_normal[i]:
file.write(f"#{i}--{in_txt[i]}\n")
os.system(cmd)