source: trigger/ListenToArduino.py@ 7703

Last change on this file since 7703 was 115, checked in by daqct3, 15 years ago
New Functions
File size: 1.6 KB
Line 
1import threading
2import GlobalVariables
3import serial
4import time
5import datetime
6class ListenToArduino(threading.Thread):
7 ser = serial.Serial('/dev/myArduino', 9600)
8 year = datetime.date.today().year
9 month = datetime.date.today().month
10 day = datetime.date.today().day
11 hour = time.localtime(time.time())[3]
12 minute = time.localtime(time.time())[4]
13 date=str(year)
14
15
16 date+="%(month)02d" % {"month":month}
17 date+="%(day)02d" % {"day":day}
18 date+="_"
19 date+="%(hour)02d" % {"hour":hour}
20 date+="%(minute)02d" % {"minute":minute}
21 filename="/ct3data/SlowData/Trigger_"+date+".slow"
22 fileHandle = open ( filename, 'w' )
23 fileHandle.close()
24
25 def run(self):
26 time.sleep(0.01)
27 while(GlobalVariables.UserInput[1:]!="exit" and GlobalVariables.UserInput[1:] != "EXIT"):
28 ArduinoMessage = self.ser.readline()
29 GlobalVariables.ServerMessage = ArduinoMessage
30 #GlobalVariables.ServerMessage = "[Temp ,28,10]"
31 time.sleep(0.05)
32
33 self.fileHandle = open ( self.filename, 'a' )
34 t = datetime.datetime.now()
35 EpochSeconds=time.mktime(t.timetuple())
36 now = datetime.datetime.fromtimestamp(EpochSeconds)
37
38 if ArduinoMessage[0]=='[':
39 self.fileHandle.write(now.ctime())
40 self.fileHandle.write(" ")
41 self.fileHandle.write(str(EpochSeconds))
42 self.fileHandle.write(" ")
43 self.fileHandle.write(ArduinoMessage)
44 self.fileHandle.close()
45
Note: See TracBrowser for help on using the repository browser.