I'm using serial event to pass rfid tags read from arduino to processing. In the serial event I am parsing and converting the variable to an integer. This working for the most part, only one rfid card keeps throwing an error.
void serialEvent(Serial thisPort)
{
String inString = thisPort.readString();
if(inString != null)
{
Serial connect1 = (Serial) connections.get(0);
if(thisPort == connect1 )
{
Chair chair = (Chair) chairs.get(0);
if(inString.contains("UID Value:"))
{
int p2 = inString.indexOf(":");
String pString = inString.substring(p2+1);
String pString2 = pString.substring (0,10);
//println(pString2);
pString2.trim();
println("String length: " + pString2.length());
chair.setRFID(pString2);
println(pString2);
}
}
}
}
void setRFID(String r)
{
try{
this.rfid = Integer.parseInt(r);
}
catch (Exception e) {
e.printStackTrace();
}
//set position of person to chair
for (Person person : people)
{
//println(this.rfid != chair.rfid);
//println(this.rfid + "," + "person: " + person.ID + "," + person.RFID);
if(this.rfid == person.RFID)
{
person.setPos(this.pos);
this.personID = person.ID;
}
}
}
The try-catch is not working, and this line is causing the problem this.rfid = Integer.parseInt(r);. I thought it might be a malformed string but the strings seems ok. Here the results of checking string consistency: String length: 10 1811524219 String length: 10 1942302231 String length: 10 1010368230 String length: 10 9813023219