open() throws 'TimeOut' PhidgetException
Posted: Sun Oct 29, 2017 5:25 am
Hi everybody.
I'm new to phidget programming and was just trying to write a little program that displays the voltage of a VoltageInput type sensor (slider) in Java.
I looked at the VoltageInput exemple and the online guide.
Whenever I execute the code, the open() method throws a timeout exception which I believe is due to no phidgets being attached during the duration of the open.
However I do have a slider plugged in my 8/8/8 1018 interface kit and it shows in the software control panel.
Here is my code:
I'm new to phidget programming and was just trying to write a little program that displays the voltage of a VoltageInput type sensor (slider) in Java.
I looked at the VoltageInput exemple and the online guide.
Whenever I execute the code, the open() method throws a timeout exception which I believe is due to no phidgets being attached during the duration of the open.
However I do have a slider plugged in my 8/8/8 1018 interface kit and it shows in the software control panel.
Here is my code:
Code: Select all
import com.phidget22.*;
public class LedSlider {
private static VoltageInput sl;
public static void main(String[] args) throws PhidgetException {
sl = new VoltageInput();
//Attach Listener
sl.addAttachListener(new AttachListener() {
public void onAttach(AttachEvent ae) {
VoltageInput slider = (VoltageInput) ae.getSource();
try {
System.out.println("Channel" + slider.getChannel() + "on device" + slider.getDeviceSerialNumber() + "connected\n" + slider.getVoltage());
}catch (PhidgetException ex){
System.out.println("AL ex " + ex.getDescription());
}
}
});
//Detach Listener
sl.addDetachListener(new DetachListener() {
public void onDetach(DetachEvent de) {
VoltageInput slider = (VoltageInput) de.getSource();
try {
System.out.println("Channel " + slider.getChannel() + "on device " + slider.getDeviceSerialNumber() + "detached");
}catch(PhidgetException ex) {
System.out.println("DL ex " + ex.getDescription());
}
}
});
//Upgrade Listener
sl.addVoltageChangeListener(new VoltageInputVoltageChangeListener() {
public void onVoltageChange(VoltageInputVoltageChangeEvent e) {
System.out.printf("Voltage changed: %.2f\n", e.getVoltage());
}
});
try {
System.out.println("5000ms to attach device");
sl.open(5000);
Thread.sleep(10000);
sl.close();
System.out.println("Channel closed");
} catch (PhidgetException ex) {
System.out.println(ex.getDescription());
} catch (InterruptedException ex) {
System.out.println("Interrupted!");
}
}
}