diff --git a/Software/Monitoring/Monitoring.py b/Software/Monitoring/Monitoring.py index e84b4a9..11430a7 100644 --- a/Software/Monitoring/Monitoring.py +++ b/Software/Monitoring/Monitoring.py @@ -4,6 +4,9 @@ Description: Monitoring of the environmental variables. +Temperature, relative humidity, and dew point are measured at regular time intervals and are saved into one or several text files. +When the maximum number of measurements per text file is reached, a new text file is opened. +The text files are saved in "/disk/groups/hep/flionett/TestStand/Data//Monitoring according to the name "Monitoring--.dat", with determined according to the number of rows and the maximum number of rows. Parameters: - , the type of sensor; @@ -17,7 +20,9 @@ """ import argparse +import math import os +import re import serial import sys import time @@ -49,6 +54,7 @@ wait = 5 # Variables to be monitored. +reading = [] T = -1. RH = -1. DP = -1. @@ -74,24 +80,11 @@ print "Serial port listening." print "================================================================================================" - # ser.write('GO\r') - # command = ser.read(2) - # print "Sending the command...", command - - ''' - trash = ser.read(3) - H = ser.read(5) - percent = ser.read(1) # Read the % symbol. - trash = ser.read(4) - T = ser.read(5) - degrees = ser.read(1) - print H - print percent - print T - print degrees - print "Relative humidity...", H, percent - print "Temperature...", T, degrees - ''' + ser.write('MOD=H\r') + while True : + trash = ser.read(1) + if (trash == '\r') : + break # Loop until the user presses Ctrl+C... try : @@ -101,24 +94,40 @@ # Read current time. currentTime = time.ctime() # Reset. + reading = [] T = -1. RH = -1. DP = -1. # Measure. ser.write('GET\r') - command = ser.read(4) - # print "Sending the command...", command - trash1 = ser.read(2) + while True : + trash = ser.read(1) + if (trash == '\r') : + break + + while True : + byte = ser.read(1) + if (byte != '\r') : + reading.append(byte) + else : + trash = ser.read(1) + break + # print reading + + # Manipulate the list and extract the desired information. + reading.remove('\n') + # print reading + s = ''.join(reading) + # print s + l = re.findall(r"[-+]?\d*\.\d+",s) # Relative humidity (RH). - RH = ser.read(5) - percent = ser.read(1) # Read the % symbol. - trash2 = ser.read(4) + RH = float(l[0]) # Temperature (T). - T = ser.read(5) - degrees = ser.read(1) - trash3 = ser.read(4) + T = float(l[1]) # Dew point (DP). - DP = -1 + H = (math.log10(RH)-2)/0.4343 + (17.62*T)/(243.12+T) + DP = 243.12*H/(17.62-H) + # Write row in the output text file. if (nRows%maxNRows==0) : # Close previous output text file, if exists. @@ -145,24 +154,11 @@ file.write(header) nFiles = nFiles+1 - ''' - print RH - print percent - print T - print degrees - print "Relative humidity...", RH, percent - print "Temperature...", T, degrees - print "Dew point...", DP, degrees - ''' - - row = currentTime + " " + str(T) + " " + str(RH) + " " + str(DP) + "\n" + row = currentTime + " " + "%.2f" % T + " " + "%.2f" % RH + " " + "%.2f" % DP + "\n" print row file.write(row) nRows = nRows+1 except KeyboardInterrupt : - # ser.write('S') - # command = ser.read(1) - # print "Sending the command...", command sys.exit(0) # Close output text file.