On Mon, Jan 23, 2012 at 4:48 PM, M.Pekala <mcdpek...@gmail.com> 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 = event.data > self.sensorabuffer = self.sensorabuffer + text > self.sensorbbuffer = self.sensorbbuffer + text > self.sensorcbuffer = self.sensorcbuffer + text > > if sensoraenable: > sensorresult = re.search(r'\$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 = re.search(r'\$A.*\$.*', self.sensorbenable) > here, you're not searching in the buffer, but in the enable flag. > if sensorcenable: > sensorresult = re.search(r'\$A.*\$.*', self.sensorcenable) > And here too. Does that fix the problem? -- Jerry
-- http://mail.python.org/mailman/listinfo/python-list