added serial_relay.py and listen2relay.service, for reading the tritium monitor by raspberry pi

This commit is contained in:
Ryan Tang 2024-05-23 16:29:20 -04:00
parent 40ead85e2f
commit fdb4aa54c4
5 changed files with 74 additions and 6 deletions

View File

@ -24,6 +24,7 @@ print(token)
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=1)
ser.reset_input_buffer()
tri_file = "/home/pi03/TRI_reading.txt"
outFile = "/home/pi03/data.txt"
# cmd='curl -s -XPOST "http://fsunuc.physics.fsu.edu:8086/write?db=interlock" --data-binary @/home/pi02/data.txt'
@ -35,10 +36,10 @@ input_normal= [
OPEN, #// 1 Reset switch
CLOSED, #// 2 Emergency source trip switch
CLOSED, #// 3 Cage door contact
CLOSED, #// 4 Fume hood flow switch
OPEN, #// 4 Fume hood flow switch
OPEN, #// 5 Vacuum condition - gnd
CLOSED, #// 6 Tritium monitor
OPEN, #// 7 Control Room Emergency Switch
CLOSED, #// 7 Control Room Emergency Switch
CLOSED, #// 8 Power failure
CLOSED, #// 9 Coolant flow - gnd
OPEN, #//10 Vacuum condition - mid
@ -117,12 +118,20 @@ while True:
for key, value in format_value.items():
# print(f"{key} value={value}")
if key != "Tritium" :
point.field(key, float(value))
else:
with open(tri_file, 'r') as file:
tri_reading = file.read()
point.field("Tritium", float(tri_reading))
with open(outFile, "w") as file:
for key, value in format_value.items():
if key == "Tritium":
file.write(f"Tritium value={tri_reading}\n")
elif key == "Vaccum" or key == "SubPump" :
file.write(f"{key} value={value}\n")
if key == "State" :
elif key == "State" :
if value == "0" or value == "1":
file.write(f"preaccl value=1\n")
file.write(f"valve1 value=1\n")

0
listen2P1AM.service Executable file → Normal file
View File

13
listen2relay.service Normal file
View File

@ -0,0 +1,13 @@
[Unit]
Description=Listening tritium monitor output
After=network.target # Adjust the target as needed
[Service]
ExecStart=/home/pi03/Multi-SNICS_Interlock/serial_relay.py
#WorkingDirectory=/home/pi02/Multi-SNICS_Interlock/ # Optional, set the working directory
#Restart=always
#StartLimitIntervalSec=10
#StartLimitBurst=5
[Install]
WantedBy=multi-user.target

46
serial_relay.py Executable file
View File

@ -0,0 +1,46 @@
#!/usr/bin/python
import serial
import RPi.GPIO as GPIO
import time
import random
#Open serial port
ser = serial.Serial('/dev/ttyUSB0',baudrate=9600,timeout =1)
GPIO.setmode(GPIO.BCM)
# init list with pin numbers
pinList = [17]
# loop through pins and set mode and state to 'high'
for i in pinList:
GPIO.setup(i, GPIO.OUT)
#text file for saving the reading
file_path = '/home/pi03/TRI_reading.txt'
try:
while True:
#Read ASCII data from serial port
data = ser.readline().decode('ascii').strip()
if data:
try:
reading = (int(data[3:8],16)-160)*0.3
print("Received:", data, ":", data[3:8], "=", int(data[3:8],16),":",round(reading))
#write to file
with open(file_path, 'w') as file:
file.write(str(round(reading)))
if reading >50:
GPIO.output(17, GPIO.LOW)
#print ("ON")
else:
GPIO.output(17, GPIO.HIGH)
#print ("OFF")
except :
os.putenv('TRI_reading', 'no_data')
except KeyboardInterrupt:
#Close serial port on Crt+C
ser.close()
#print ("Quit")
# Reset GPIO settings
GPIO.cleanup()

View File

@ -22,7 +22,7 @@ const std::string error_txt[16] = {
"Fume Hood Flow", //3
"Vacuum Gauge 2", //4
"Tritium Monitor", //5
"error: port map", //6
"Control Room Emergency Switch", //6
"Bldg Power Fail", //7
"Coolant Flow 2", //8
"Vacuum Gauge 1", //9