Parsing a serial stream too slowly

Jerry Hill malaclypse2 at
Mon Jan 23 16:54:17 EST 2012

On Mon, Jan 23, 2012 at 4:48 PM, M.Pekala <mcdpekala at> wrote:

> Hello, I am having some trouble with a serial stream on a project I am
> When one sensor is running my python script grabs the data just fine,
> removes the formatting, and throws it into a text control box. However
> when 3 or more sensors are running, I get output like the following:
> Sensor 1: 373
> Sensor 2: 112$$M-160$G373
> Sensor 3: 763$$A892$
> I am fairly certain this means that my code is running too slow to
> catch all the '$' markers. Below is the snippet of code I believe is
> the cause of this problem...

That doesn't sound right.  Being too slow seems unlikely to produce the
wrong data...

def OnSerialRead(self, event):
>        text =
>        self.sensorabuffer = self.sensorabuffer + text
>        self.sensorbbuffer = self.sensorbbuffer + text
>        self.sensorcbuffer = self.sensorcbuffer + text
>        if sensoraenable:
>                sensorresult ='\$A.*\$.*', self.sensorabuffer )

Here, you search in sensorabuffer (which, by the way, would be much more
readable to me as sensor_a_buffer, as recommended by the PEP 8 style guide).

>        if sensorbenable:
>                sensorresult ='\$A.*\$.*', self.sensorbenable)

here, you're not searching in the buffer, but in the enable flag.

>        if sensorcenable:
>                sensorresult ='\$A.*\$.*', self.sensorcenable)

And here too.

Does that fix the problem?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list