On 2/2/2011 6:51 AM Tom Brauch said...
All,
I am a python neophyte and not terrible well versed in programming (as will
become obvious shortly)
I have a script which is reading a serial device on a schedule. The device
outputs a header at the beginning of every read. I have a data file which I
am appending and would like to eliminate the header so that I end up with
one master data file. A copy of the serial readout is:
*
6CSV Type Reports2 - Display All Data3 - Display New Data4 - Display Last
Data5 - Display All Flow Stats6 - Display New Flow Stats7 - Display All
5-Min Flow8 - Display New 5-Min Flow9 - Display Error Log>
4 - Display CSV DataStation,
1Time,Conc(mg/m3),Qtot(m3),no(V),WS(MPS),no(V),RH(%),no(V),AT(C),E,U,M,I,L,R,N,F,P,D,C,T,02/02/11
08:00, 0.042, 0.701, 0.004, 0.1, 0.002, 7, 0.012,
-18.0,0,0,0,0,0,0,0,0,0,0,0,0,
I am only interested in the information following the T, in the header. I
have tried to use an exception to have the script throw out all data prior
to the T, in the header but I don't know how to define this excecption. My
current script looks as follows:
def cycle(ser,prefix):
inRecovery=False
resp=False
# tm.sleep(30.0)
ser.open()
tm.sleep(2)
ser.write('\n\r\n\r\n\r')
resp=buffer_read(ser)
ser.write('6')
resp=buffer_read(ser)
ser.write('3')
resp=buffer_read(ser)
lines = resp.split('\r\n')
waste=lines.pop()
pop changes lines by discarding the end of the list. So your subsequent
remove fails because waste is no longer in the list.
Perhaps waste is the data you're looking for?
sprinkle some prints through here so you can see what values you're
dealing with. That's a common technique to help figure out what's wrong.
HTH,
Emile
while True:
try:
lines.remove(waste)
except Exception:
??????
for x,row in enumerate(lines):
lines[x]=row.split(',')
if DEBUG: print lines
f=open(prefix,'a')
csvf = csv.writer(f)
csvf.writerows(lines)
f.close()
ser.close()
How do I define the exception so that I get only the data following the
header?
Thanks!
Tomb
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor