From fdb4aa54c4fe7f1ee77193ee1476d99051ab9068 Mon Sep 17 00:00:00 2001 From: "Ryan@interlock" Date: Thu, 23 May 2024 16:29:20 -0400 Subject: [PATCH] added serial_relay.py and listen2relay.service, for reading the tritium monitor by raspberry pi --- Listen2Arduino.py | 19 +++++++++++----- listen2P1AM.service | 0 listen2relay.service | 13 +++++++++++ serial_relay.py | 46 +++++++++++++++++++++++++++++++++++++++ statusDisplay/display.cpp | 2 +- 5 files changed, 74 insertions(+), 6 deletions(-) mode change 100755 => 100644 listen2P1AM.service create mode 100644 listen2relay.service create mode 100755 serial_relay.py diff --git a/Listen2Arduino.py b/Listen2Arduino.py index af282f0..60a9f89 100755 --- a/Listen2Arduino.py +++ b/Listen2Arduino.py @@ -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}") - point.field(key, float(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(): - file.write(f"{key} value={value}\n") - if key == "State" : + if key == "Tritium": + file.write(f"Tritium value={tri_reading}\n") + elif key == "Vaccum" or key == "SubPump" : + file.write(f"{key} value={value}\n") + elif key == "State" : if value == "0" or value == "1": file.write(f"preaccl value=1\n") file.write(f"valve1 value=1\n") diff --git a/listen2P1AM.service b/listen2P1AM.service old mode 100755 new mode 100644 diff --git a/listen2relay.service b/listen2relay.service new file mode 100644 index 0000000..ee7b15d --- /dev/null +++ b/listen2relay.service @@ -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 diff --git a/serial_relay.py b/serial_relay.py new file mode 100755 index 0000000..0048c84 --- /dev/null +++ b/serial_relay.py @@ -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() diff --git a/statusDisplay/display.cpp b/statusDisplay/display.cpp index cc775ba..6a61989 100644 --- a/statusDisplay/display.cpp +++ b/statusDisplay/display.cpp @@ -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