serialEvent() error in Linux + Arduino
in
Integration and Hardware
•
3 years ago
I'm getting the following error when attempting to run the frontend for the Arduino PID library, the full code for the frontend can be found at:
Arduino PID
The serialEvent() function contains several setText() and setValue() calls to controlP5 objects. These objects are declared globally as follows:
If I comment out those calls, like this:
This error occurs only on my Linux machine. If I run identical code on a Windows XP machine there is no error.
The only other mention of an error like this I found is here:
http://processing.org/discourse/yabb2/YaBB.pl?num=1183525352
Any thoughts or advice?
Arduino PID
error, disabling serialEvent() for /dev/ttyUSB0
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at processing.serial.Serial.serialEvent(Unknown Source)
at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
at gnu.io.RXTXPort.eventLoop(Native Method)
at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)
Caused by: java.lang.NullPointerException
at PID_FrontEnd_v02.serialEvent(PID_FrontEnd_v02.java:436)
... 8 more
The serialEvent() function contains several setText() and setValue() calls to controlP5 objects. These objects are declared globally as follows:
- ControlP5 controlP5;
controlP5.Button AMButton;
controlP5.Textlabel AMLabel, AMCurrent, InLabel,
OutLabel, SPLabel, PLabel,
ILabel, DLabel;
controlP5.Textfield SPField, InField, OutField,
PField, IField, DField;
If I comment out those calls, like this:
//take the string the arduino sends us and parse it
void serialEvent(Serial myPort)
{
String read = myPort.readStringUntil(10);
if(outputFileName!="") output.print(str(millis())+ " "+read);
String[] s = split(read, " ");
if (s.length ==8)
{
Setpoint = float(s[1]); // * pull the information
Input = float(s[2]); // we need out of the
Output = float(s[3]); // string and put it
//SPLabel.setValue(s[1]); // where it's needed
//InLabel.setValue(s[2]); //
//OutLabel.setValue(trim(s[3])); //
//PLabel.setValue(trim(s[4])); //
//ILabel.setValue(trim(s[5])); //
//DLabel.setValue(trim(s[6])); //
//AMCurrent.setValue(trim(s[7])); //
if(justSent) // * if this is the first read
{ // since we sent values to
//SPField.setText(trim(s[1])); // the arduino, take the
//InField.setText(trim(s[2])); // current values and put
//OutField.setText(trim(s[3])); // them into the input fields
//PField.setText(trim(s[4])); //
//IField.setText(trim(s[5])); //
//DField.setText(trim(s[6])); //
mode = trim(s[7]); //
//AMLabel.setValue(mode); //
justSent=false; //
} //
if(!madeContact) madeContact=true;
}
}
This error occurs only on my Linux machine. If I run identical code on a Windows XP machine there is no error.
The only other mention of an error like this I found is here:
http://processing.org/discourse/yabb2/YaBB.pl?num=1183525352
Any thoughts or advice?
1