|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
SerialPort viOpen error
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");
}
}
}
|
|
#2
|
||||
|
||||
|
Re: SerialPort viOpen error
Quote:
It may also be useful to check the following
|
|
#3
|
|||||
|
|||||
|
Re: SerialPort viOpen error
Quote:
We saw that bug, but the fix was attached in May and should have been rolled into the 2014 release, I would think. Plus this isn't the same error as that one. |
|
#4
|
|||
|
|||
|
Re: SerialPort viOpen error
Quote:
It's sporadic. SerialPort settings we use are 57600, 8, N, 1 The nav6 sends a stream of 30-40 bytes packets at about 20-50Hz rate, so a stream of bytes is arriving when the serial port is opened. [cRIO] edu.wpi.first.wpilibj.visa.VisaException: VI_ERROR_RSRC_NFOUND in function viOpen [cRIO] at edu.wpi.first.wpilibj.visa.Visa.assertCleanStatus( Visa.java:151) [cRIO] at edu.wpi.first.wpilibj.visa.Visa.viOpen(Visa.java:6 3) Here's a note on the error: "...there doesn't seem to be any consistency with when the error occurs. Occasionally it would happen after a few times of sending new code to the robot and sometimes it would happen after I had just powered on the robot. I wasn't able to find anything that seemed to be a specific trigger. I was typically able to fix it by leaving the robot powered off for a period of time and then powering it back on." [Side Note: If possible, if the Java SerialPort class is being modified, can the setReadBufferSize() method please be made public?] |
|
#5
|
|||
|
|||
|
Re: SerialPort viOpen error
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|