Files
hpos-data/scripts/auto_check_led.py

84 lines
3.3 KiB
Python
Raw Normal View History

2023-12-26 22:35:30 +05:30
import serial
import pandas as pd
import os.path
from datetime import datetime
import math
import time
from tqdm import tqdm
class Device:
def __init__(self, accuracy, precision):
self.accuracy = accuracy
self.precision = precision
def perform_hpos_test(repeat_no):
try:
data_file = 'data.xlsx'
if os.path.exists(data_file):
df = pd.read_excel('data.xlsx')
else:
df = pd.DataFrame(columns=["sol", "427_buffer_intensity", "555_buffer_intensity", "427_sample_intensity", "555_sample_intensity", "427_absorbance", "555_absorbance", "absorbance_ratio", "time"])
time.sleep(5)
port = '/dev/cu.usbserial-23APB136'
baud_rate = 9600
with serial.Serial(port, baud_rate, timeout=1, parity=serial.PARITY_NONE) as ser:
x = ser.read()
s = ser.read(10)
line = ser.readline()
print(x)
print(s)
print(line)
# perform_blanking = input("Do you want to perform blanking?(Y/N)")
ser.write(b'I')
while True:
x = ser.read()
b = ser.read(100)
line = ser.readline()
print(b)
if 'SNE' in b.decode("utf-8"):
ser.write(b'B')
while True:
x = ser.read()
s = ser.read(100)
line = ser.readline()
print(s)
if 'BC' in s.decode("utf-8"):
ser.write(b'P')
while True:
x = ser.read()
r = ser.read(100)
line = ser.readline()
print(r)
if 'RESULT' in r.decode("utf-8") or 'REND' in r.decode('utf-8'):
result = r.decode("utf-8").split(' ')
df = pd.concat([df, pd.DataFrame([{"sol": solution + '-' + str(repeat_no), "427_buffer_intensity": result[3], "555_buffer_intensity": result[3], "427_sample_intensity": result[5], "555_sample_intensity": result[6], "427_absorbance": math.log10(float(result[3]) / float(result[5])), "555_absorbance": math.log10(float(result[4]) / float(result[6])), "absorbance_ratio": math.log10(float(result[3]) / float(result[5])) / math.log10(float(result[4]) / float(result[6])), "time": datetime.today().strftime('%d-%m-%y %H:%M:%S')}])], ignore_index = True)
print(df)
writer = pd.ExcelWriter(data_file, engine = 'openpyxl')
df.to_excel(writer, sheet_name = 'data', index=False)
writer.close()
break
break
except serial.serialutil.SerialException:
print("device is not connected or resuorce busy!")
exit()
except Exception as err:
print("error!", err)
exit()
if __name__ == "__main__":
d = Device(0.01, 0.001)
solution = "tar" #input("solution name: ")
repeats = 1 #int(input("number of repeats: "))
for repeat in tqdm(range(0, repeats)):
perform_hpos_test(repeat)