View Single Post
  #2   Spotlight this post!  
Unread 20-01-2014, 11:31
eddie12390's Avatar
eddie12390 eddie12390 is offline
Registered User
AKA: Eddie
FRC #3260 (SHARP)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Pittsburgh
Posts: 285
eddie12390 is a glorious beacon of lighteddie12390 is a glorious beacon of lighteddie12390 is a glorious beacon of lighteddie12390 is a glorious beacon of lighteddie12390 is a glorious beacon of light
Re: SerialPort viOpen error

Quote:
Originally Posted by tech2077 View Post
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");
        }
    }
}
The Java SerialPort implementation seems to be buggy, I don't think that the issue found here http://firstforge.wpi.edu/sf/go/artf...3699545405 50 has been fixed yet.

It may also be useful to check the following
  1. State of the Console Out switch (You don't need it on if you're trying to do something like interface with a sensor over the serial port)
  2. No CAN plugin installed if you're not trying to use CAN (They take control of the serial port)
  3. Correct cable (Some implementations require a special DB9 cable known as a null modem cable)
Reply With Quote