Bug 291 : Serial Read missing a character while reading a string
Last modified: 2007-02-03 12:19




Status:
RESOLVED
Resolution:
WORKSFORME -
Priority:
P2
Severity:
normal

 

Reporter:
Vinay Venkatraman
Assigned To:
fry

Attachment Type Created Size Actions

Description:   Opened: 2006-02-14 06:09
While trying to read a string using the serial library there is a infrequent drop of a character
towards the end of the string. I am sending a numeric string through the serial port at baud
19200. the string appears quite normal when seen in a Serial port monitor (like Zterm or
Arduino IDE) . When read with the following code in processing 99, it randomly drops some
characters and throws an exception.


-----------------------------------------------------------------------------

// adapted from the original code by Tom Igoe
// Vinay Venkatraman, IDII Feb 2006.

import processing.serial.*;
String myString = null;
Serial myPort;
int position=0;

void setup()
{
myPort = new Serial(this, Serial.list()[2], 19200);
myPort.clear();
myString = myPort.readString();
myString = null;
}

void draw()
{

while (myPort.available() > 0)
{
myString = myPort.readString();
if (myString != null)
{
String pos = trim(myString);
try
{
position = Integer.parseInt(pos);
} catch (NumberFormatException e)
{
println(e);
}

println(position);

}
}
}


-----------------------------------------------------------------------------
Additional Comment #1 From fry 2006-02-18 18:07
what exception is it throwing? i can't debug without knowing the problem.
Additional Comment #2 From Vinay Venkatraman 2006-02-21 04:33
Sorry...the exception was due to the Integer parsing
"java.lang.NumberFormatException: For input string: " " ".

but randomly (without any apperent pattern) it drops a character without any kind of exception.
I have been reading the same values in Zterm and it seems fine.

Maybe there is some noise in my signal. i will get a oscilloscope and check it out. Also i am
using a USB to serial chip on the line..so will check out with a different setup.
Additional Comment #3 From fry 2007-02-03 12:19
can't seem to reproduce this.