I was trying to run the posted code in order to test out the serial port on our cRIO. The code faulted with a null pointer error due to the serial resource not being initialized and returning the error "VI_ERROR_RSRC_NFOUND in function viOpen"
Code:
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.SerialPort;
import edu.wpi.first.wpilibj.visa.VisaException;
public class RobotTemplate extends IterativeRobot {
public SerialPort serial;
public void robotInit() {
}
public void autonomousInit() {
}
public void autonomousPeriodic() {
}
public void teleopInit() {
try {
serial = new SerialPort(115200);
} catch (VisaException ex) {
System.out.println("Error to initialize serial port at 115200 baud " + ex.getMessage());
}
}
public void teleopPeriodic() {
try {
serial.print("test");
System.out.println(serial.read(1));
} catch (VisaException ex) {
System.out.println("Error");
}
}
}