Bug 96 : readBytesUntil() and bufferUntil() broken in serial
Last modified: 2008-06-09 12:08




Status:
RESOLVED
Resolution:
FIXED -
Priority:
P3
Severity:
normal

 

Reporter:
fry
Assigned To:
fry

Attachment Type Created Size Actions
makes bufferUntil work as documented patch 2008-04-20 15:38 642 bytes

Description:   Opened: 2005-07-27 19:39
port buffering not working properly.. may just be a problem with thread
starvation.

bufferUntil() fires an event but continues to fill up the buffer.
Additional Comment #1 From fry 2005-07-27 19:40
from stendahl:

The readBytesUntil function currently drops any data in the buffer after
the "interesting" character. So if, for example, two lines are read into
the buffer before readStringUntil('\n') gets called, the first line is
returned and the second vanishes.

Here's a patch (is this the right place for this sort of thing, btw?):

Index: serial/Serial.java
===================================================================
RCS file: /cvsroot/processing/processing/serial/Serial.java,v
retrieving revision 1.2
diff -r1.2 Serial.java
408,409c408,412
< bufferIndex = 0; // rewind
< bufferLast = 0;
---
> bufferIndex += length;
> if (bufferIndex == bufferLast) {
> bufferIndex = 0; // rewind
> bufferLast = 0;
> }
Additional Comment #2 From robert.terwilliger 2008-02-16 10:18
under Mac OSX 10.5 with Processing 0135, the bufferUntil() still doesn't work. I set it to wait
for a line feed (ASCII 10), but it calls serialEvent() when a single character is put in the
buffer.


void setup(){
size(640,480);
port = new Serial(this,Serial.list()[0],9600);
port.bufferUntil(10); // ASCII 10 is a linefeed
}

void serialEvent(Serial p){
print( p.available() );
println(" " + p.readString()); // the p.available() always says there is only one char in the
// even though for me it should be 20-30
}
Additional Comment #3 From jmuhlich 2008-04-20 15:38
edit]
makes bufferUntil work as documented

Fixes the user event trigger logic in serialEvent(), which corrects the bug
identified in comment 2. The second part of the if-condition fails to check
that the variable bufferUntil is false, thus if the user has previously called
the method bufferUntil(), this if-statement will evaluate to true on every byte
read instead of correctly waiting for the desired byte. This patch adds the
missing check.
Additional Comment #4 From fry 2008-06-09 12:08
sorry all, i can't believe this one has gone unpatched this long. thanks
both for the patches, i've now applied them for 0140.