source: trigger/ListenToArduino.py@ 113

Last change on this file since 113 was 77, checked in by rissim, 15 years ago
trigger: gui added, interface modified
File size: 1.3 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 date=str(year)
12 date+="0"
13 date+=str(month)
14 date+=str(day)
15 filename="Arduino_testing_"+date+".txt"
16 fileHandle = open ( filename, 'w' )
17 fileHandle.close()
18
19 def run(self):
20 time.sleep(0.01)
21 while(GlobalVariables.UserInput[1:]!="exit" and GlobalVariables.UserInput[1:] != "EXIT"):
22 ArduinoMessage = self.ser.readline()
23 GlobalVariables.ServerMessage = ArduinoMessage
24 #GlobalVariables.ServerMessage = "[Temp ,28,10]"
25 time.sleep(0.05)
26
27 self.fileHandle = open ( self.filename, 'a' )
28 t = datetime.datetime.now()
29 EpochSeconds=time.mktime(t.timetuple())
30 now = datetime.datetime.fromtimestamp(EpochSeconds)
31
32 if ArduinoMessage[0]=='[':
33 self.fileHandle.write(now.ctime())
34 self.fileHandle.write(" ")
35 self.fileHandle.write(str(EpochSeconds))
36 self.fileHandle.write(" ")
37 self.fileHandle.write(ArduinoMessage)
38 self.fileHandle.close()
39
Note: See TracBrowser for help on using the repository browser.