import threading import GlobalVariables import serial import time import datetime class ListenToArduino(threading.Thread): ser = serial.Serial('/dev/myArduino', 9600) year = datetime.date.today().year month = datetime.date.today().month day = datetime.date.today().day hour = time.localtime(time.time())[3] minute = time.localtime(time.time())[4] date=str(year) date+="%(month)02d" % {"month":month} date+="%(day)02d" % {"day":day} date+="_" date+="%(hour)02d" % {"hour":hour} date+="%(minute)02d" % {"minute":minute} filename="/ct3data/SlowData/Trigger_"+date+".slow" fileHandle = open ( filename, 'w' ) fileHandle.close() def run(self): time.sleep(0.01) while(GlobalVariables.UserInput[1:]!="exit" and GlobalVariables.UserInput[1:] != "EXIT"): ArduinoMessage = self.ser.readline() GlobalVariables.ServerMessage = ArduinoMessage #GlobalVariables.ServerMessage = "[Temp ,28,10]" time.sleep(0.05) self.fileHandle = open ( self.filename, 'a' ) t = datetime.datetime.now() EpochSeconds=time.mktime(t.timetuple()) now = datetime.datetime.fromtimestamp(EpochSeconds) if ArduinoMessage[0]=='[': self.fileHandle.write(now.ctime()) self.fileHandle.write(" ") self.fileHandle.write(str(EpochSeconds)) self.fileHandle.write(" ") self.fileHandle.write(ArduinoMessage) self.fileHandle.close()