Go to Post Good tooling doesn't cost money, it makes money (and prevents doctor visits). - travis [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 20-01-2014, 00:07
tech2077 tech2077 is offline
Registered User
AKA: Matthew Skolaut
FRC #3847 (Spectrum 3847)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Houston
Posts: 21
tech2077 is an unknown quantity at this point
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");
        }
    }
}
Reply With Quote
  #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
  #3   Spotlight this post!  
Unread 20-01-2014, 11:36
AllenGregoryIV's Avatar
AllenGregoryIV AllenGregoryIV is online now
Engineering Coach
AKA: Allen "JAG" Gregory
FRC #3847 (Spectrum)
Team Role: Coach
 
Join Date: Jul 2008
Rookie Year: 2003
Location: Texas
Posts: 2,549
AllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond repute
Send a message via AIM to AllenGregoryIV
Re: SerialPort viOpen error

Quote:
Originally Posted by eddie12390 View Post
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)
1 and 2 are not the problem, I reimagined the cRIO for this setup with him last night and made sure to remove the CAN drivers and turn off Console Out.

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.
__________________

Team 647 | Cyber Wolf Corps | Alumni | 2003-2006 | Shoemaker HS
Team 2587 | DiscoBots | Mentor | 2008-2011 | Rice University / Houston Food Bank
Team 3847 | Spectrum | Coach | 2012-20... | St Agnes Academy
LRI | Alamo Regional | 2014-20...
"Competition has been shown to be useful up to a certain point and no further, but cooperation, which is the thing we must strive for today, begins where competition leaves off." - Franklin D. Roosevelt
Reply With Quote
  #4   Spotlight this post!  
Unread 22-01-2014, 14:02
slibert slibert is offline
Software Mentor
AKA: Scott Libert
FRC #2465 (Kauaibots)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2005
Location: Kauai, Hawaii
Posts: 343
slibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud of
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");
        }
    }
}
I'm working with a few teams who are using the nav6 IMU, and they are running into this problem too.

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?]
Reply With Quote
  #5   Spotlight this post!  
Unread 22-01-2014, 16:47
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 588
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
Re: SerialPort viOpen error

Check this thread:

http://forums.usfirst.org/showthread...t-viOpen-error

Brad
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 09:32.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi