Hello,
I have recently started using python and i have come to a halt while writing a 
code and i was hoping someone out there can help me.
I am attempting to store a stream of data directly from a serial port onto 
multiple files in sequence after x amount of time is elapsed.
for example :
Read data from serial and write to file 1 for 15 sec, after the 15 seconds 
continue writing the data on to file 2 for 15 seconds and vice versa. in 
essence each file should write for 15 seconds and stop for 15 seconds while the 
data is written to the other file
at the moment i have managed to write a code to read and write the data to one 
file (see below). can someone please assist me.
Code:
#!/usr/bin/env python
from datetime import datetimeimport serial
outfile='/home/bogie/Documents/Data/file1.txt'#outfile='/home/bogie/Documents/Data/file2.txt'ser
 = serial.Serial(    port='/dev/ttyS4',    baudrate=9600,    
parity=serial.PARITY_NONE,    stopbits=serial.STOPBITS_ONE,    
bytesize=serial.EIGHTBITS,
)
while ser.isOpen():    d = open(outfile,'a')     dataString = ser.read(44)    
d.write(datetime.utcnow().isoformat()+ '\t' + dataString + '\n')    d.flush() 
#included to force the system to write to disk

ser.close()

Thanks,Mohanad 
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to