According to the documentation, the eol parameter is indeed no longer supported when using Python version 2.6 of higher.
Please disregard my previous advice to use FileLike
. That isn't using in python 2.6+ either!
How you have to handle the data depends on how the data looks. Since you haven't given us an example of the raw data, I'll be using the format from this page as an example.
The format of the data in the abovementioned example is:
t: 2012.11.18 19:39:03 50A93957 +024.50 0189
t: 2012.11.18 19:39:13 50A93961 +024.50 0189
t: 2012.11.18 19:39:23 50A9396B +024.50 0188
Each line has the following columns:
- date and time
- raw date and time in hex
- temperature value in degree celsuis
- raw temperature value in hex
You will notice that each measurement starts with a 't:', and has six items separated by spaces. So in this case I would run a loop that works like this:
import serial
import time
buffer = bytes()
ser = serial.Serial('/dev/ttyACM0',9600, timeout=10)
while buffer.count('t:') < 2:
buffer += ser.read(30)
ser.close();
# Now we have at least one complete datum. Isolate it.
start = buffer.index('t:')
end = buffer.index('t:', start+1)
items = buffer[start:end].strip().split()
print items[1], items[2], items[4]
An example. Realize that you might begin reading in the middle of a line of data. You cannot assume you start reading at the beginning of a line.
In [23]: buffer = '39:03 50A9\r\nt: 2012.11.18 19:39:13 50A93961 +024.50 0189\r\nt: 2012.11.18 19:39:23 50A9396B +024.50 0188'
Let's check how many 't:''s we can find. (You could also search for '\r\n' instead. All that matters is that you have something to delimiter lines with)
In [24]: buffer.count('t:')
Out[24]: 2
Since we have two delimiters, we have at least one data point. Let's isolate the complete data point.
In [25]: buffer.index('t:')
Out[25]: 12
In [26]: buffer.index('t:', 12+1)
Out[26]: 58
This is what we want to see. A complete data point:
In [27]: buffer[12:58+1].strip().split()
Out[27]: ['t:', '2012.11.18', '19:39:13', '50A93961', '+024.50', '0189', 't']
In [28]: items = buffer[12:59].strip().split()
In [29]: print items[1], items[2], items[4]
2012.11.18 19:39:13 +024.50