|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
EnhancedIO Exception Error
We are trying to read a potentiometer connected to our Cypress IO board using the enhancedIO class.
Here is our code so far: Code:
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.AnalogChannel;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.DriverStationEnhancedIO;
import edu.wpi.first.wpilibj.DriverStation;
/**
* The VM is configured to automatically run this class, and to call the
* functions corresponding to each mode, as described in the IterativeRobot
* documentation. If you change the name of this class or the package after
* creating this project, you must also update the manifest file in the resource
* directory.
*/
public class Team503Robot extends IterativeRobot {
private RobotDrive drivetrain;
private Joystick gamepad;
private Encoder leftDriveEncoder;
private Encoder rightDriveEncoder;
private AnalogChannel potentiometer;
private DigitalInput limitSwitch;
DriverStationEnhancedIO dseio;
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
public void robotInit() {
dseio = DriverStation.getInstance().getEnhancedIO();
}
/**
* This function is called periodically during autonomous
*/
public void autonomousPeriodic() {
}
/**
* This function is called periodically during operator control
*/
public void teleopPeriodic() {
double slider = dseio.getAnalogIn(1);
}
}
|
|
#2
|
|||
|
|||
|
Re: EnhancedIO Exception Error
Well, it's been a little while since I did Java, but I would guess that the getAnalogIn function can throw an exception, and it's not being handled. You either need a try block around it or you need to declare that it can throw the exception.
Solution 1 (in method): try { double slider = dseio.getAnalogIn(1); //additional code to execute if that works } catch (IOException ioexec) { //do stuff here if it goes wrong } (this last part may or may not be necessary; just know that it will always execute, even if an exception is thrown) finally { //more stuff that will always execute } Solution 2: public void teleopPeriodic() throws EnhancedIOException { double slider = dseio.getAnalogIn(1); } Solution 1 has much better control over what happens if an exception is thrown, so I suggest you use that one in your program. I hope it works for you. |
|
#3
|
|||
|
|||
|
Re: EnhancedIO Exception Error
We tried solution 1 and it worked. Thanks for the help.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Wait Exception? | NinJA999 | Java | 3 | 15-01-2010 14:13 |
| Exception in Timer.cpp | Phazonmutant | C/C++ | 2 | 17-02-2009 09:27 |
| Target Exception - Exception in Kernal Task | Thxe | C/C++ | 3 | 10-02-2009 07:24 |
| error - language-plug-in exception... | RedOctober45 | Programming | 1 | 16-01-2008 15:54 |
| Joystick Exception? | Blair Frank | Control System | 3 | 09-02-2007 22:41 |