Parsing data from pyserial (final resolution)

2006-12-05 Thread Lone Wolf
After going back and reading everybody's suggestions, I finally got a simple, efficient solution. As was pointed out to me in several posts, I needed to use readline rather than read. That's obvious to me now ... but isn't everything obvious once you understand it :) Anyway, I am posting my code

Re: Parsing data from pyserial, an (inefficient) solution

2006-12-04 Thread Giovanni Bajo
Dennis Lee Bieber wrote: The really sad thing is that I get a perfectly constructed packet from the reading variable, and that gets butchered when I try to slice it up to pick out individual elements. Since pyserial doesn’t do anything to rearrange the data, then the CMUcam must do the

Re: Parsing data from pyserial

2006-12-04 Thread Grant Edwards
On 2006-12-04, John Machin [EMAIL PROTECTED] wrote: Try reading previous posts. The OP reported that to be returned from the cam, based on print forty_bytes, not print repr(forty_bytes). I think everybody (including possibly even the OP) is willing to believe that the cam is *generating*

Re: Parsing data from pyserial, an (inefficient) solution

2006-12-04 Thread Grant Edwards
On 2006-12-04, Giovanni Bajo [EMAIL PROTECTED] wrote: [...] This should result in complete packets (from the M to a \r) Oh well. readline(eol=\r) will do that much better. Yup. Using readline() has been suggested several times. It sure seems like the obvious solution to me as well.

Re: Parsing data from pyserial

2006-12-03 Thread Giovanni Bajo
Lone Wolf wrote: reading = ser.read(40) Simply try ser.readline() here, or maybe ser.readline(eol=\r). -- Giovanni Bajo -- http://mail.python.org/mailman/listinfo/python-list

Re: Parsing data from pyserial

2006-12-03 Thread Grant Edwards
On 2006-12-03, Lone Wolf [EMAIL PROTECTED] wrote: import serial ser=serial.Serial('com1',baudrate=115200, bytesize=8, parity='N', stopbits=1,xonxoff=0, timeout=1) ser.write(PM 1) #This sets the CMUcam to poll mode for i in range(0,100,1): ser.write(TC 016 240 100 240 016 240\r\n)

Re: Parsing data from pyserial

2006-12-03 Thread Si Ballenger
On Sat, 2 Dec 2006 23:02:06 -0500, Lone Wolf [EMAIL PROTECTED] wrote: I'm trying to get data through my serial port from a CMUcam. This gizmo tracks a color and returns a packet of data. The packet has nine data points (well, really eight since the first point is just a packet header) separated

Re: Parsing data from pyserial

2006-12-03 Thread Grant Edwards
On 2006-12-03, Si Ballenger [EMAIL PROTECTED] wrote: In my dealing with serial gizmos I have to put a delay between the request sent to the gizmo and the reading of the serial input buffer for returned data. Serial ports and gizmos need some time to do their thing. I doubt that's the issue.

Re: Parsing data from pyserial

2006-12-03 Thread Si Ballenger
On Sun, 03 Dec 2006 16:52:33 -, Grant Edwards [EMAIL PROTECTED] wrote: On 2006-12-03, Si Ballenger [EMAIL PROTECTED] wrote: In my dealing with serial gizmos I have to put a delay between the request sent to the gizmo and the reading of the serial input buffer for returned data. Serial

Re: Parsing data from pyserial

2006-12-03 Thread John Machin
Grant Edwards wrote: When something odd seems to be happening with strings, always print `whatever` rather than whatever :-) Unholy perlism, Batman! For the benefit of gentle readers who are newish and might not have seen the ` character in Python code outside a string literal, or for those

Re: Parsing data from pyserial

2006-12-03 Thread Grant Edwards
On 2006-12-03, Si Ballenger [EMAIL PROTECTED] wrote: In my dealing with serial gizmos I have to put a delay between the request sent to the gizmo and the reading of the serial input buffer for returned data. Serial ports and gizmos need some time to do their thing. I doubt that's the issue.

Re: Parsing data from pyserial

2006-12-03 Thread Fredrik Lundh
Si Ballenger wrote: I would think a time delay would be needed between the below two lines in the code if he expects to get a useable data string back from the gizmo for the command sent to it. ser.write(TC 016 240 100 240 016 240\r\n) reading = ser.read(40) why's that? if the

Re: Parsing data from pyserial

2006-12-03 Thread Grant Edwards
On 2006-12-03, John Machin [EMAIL PROTECTED] wrote: Grant Edwards wrote: When something odd seems to be happening with strings, always print `whatever` rather than whatever :-) Unholy perlism, Batman! OK, make that print repr(whatever). :) -- Grant Edwards grante

Re: Parsing data from pyserial

2006-12-03 Thread Si Ballenger
On Sun, 03 Dec 2006 18:44:07 -, Grant Edwards [EMAIL PROTECTED] wrote: On 2006-12-03, Si Ballenger [EMAIL PROTECTED] wrote: In my dealing with serial gizmos I have to put a delay between the request sent to the gizmo and the reading of the serial input buffer for returned data. Serial

Re: Parsing data from pyserial

2006-12-03 Thread John Machin
Si Ballenger wrote: Per what was posted (below), it appears that the the appropriate data is being received. [snip] Here is an example output: M 37 79 3 4 59 124 86 25 ['59', '123', '87', '25', 'M', '37', '79', '3', '4', '59', '124', '86', '25', 'M '] M 38 77 3 2 59 124 86 25 ['39',

Parsing data from pyserial, an (inefficient) solution

2006-12-03 Thread Lone Wolf
I want to thank everybody who tried to help me, and also to post my solution, even though I don’t think it is a very good one. Many of you correctly guessed that there was an “\r” included with the packet from the CUMcam, and you were correct. The actual format of the packet is: M xxx xxx xxx

Re: Parsing data from pyserial

2006-12-03 Thread Si Ballenger
On 3 Dec 2006 17:33:59 -0800, John Machin [EMAIL PROTECTED] wrote: In any case, I wouldn't call that the appropriate data is being received -- looks like chunks missing to me. Well, below is the posted expected return data format from the cam and below that is what has been reported to be

Re: Parsing data from pyserial, an (inefficient) solution

2006-12-03 Thread John Machin
Lone Wolf wrote: Your code has a problem when the first character of reading is 'M': you will miss the full packet and pick up a fragment. The length test that you are doing to reject the fragment is a kludge. If the average length of a packet is say 25, then you are throwing away 4% of all

Re: Parsing data from pyserial

2006-12-03 Thread John Machin
Si Ballenger wrote: On 3 Dec 2006 17:33:59 -0800, John Machin [EMAIL PROTECTED] wrote: In any case, I wouldn't call that the appropriate data is being received -- looks like chunks missing to me. Well, below is the posted expected return data format from the cam and below that is what has

Parsing data from pyserial

2006-12-02 Thread Lone Wolf
I'm trying to get data through my serial port from a CMUcam. This gizmo tracks a color and returns a packet of data. The packet has nine data points (well, really eight since the first point is just a packet header) separated by spaces as follows: M xxx xxx xxx xxx xxx xxx xxx xxx Here is the

Re: Parsing data from pyserial

2006-12-02 Thread John Machin
Lone Wolf wrote: I'm trying to get data through my serial port from a CMUcam. This gizmo tracks a color and returns a packet of data. The packet has nine data points (well, really eight since the first point is just a packet header) separated by spaces as follows: M xxx xxx xxx xxx xxx xxx

Re: Parsing data from pyserial

2006-12-02 Thread Hendrik van Rooyen
Lone Wolf [EMAIL PROTECTED] wrote: I'm trying to get data through my serial port from a CMUcam. This gizmo tracks a color and returns a packet of data. The packet has nine data points (well, really eight since the first point is just a packet header) separated by spaces as follows: M xxx xxx