I'm using the new VINT modules and Phidget22.
After a lot of learning (I'm also new to Java!) I have modified the code (1700 lines) and it compiles OK. But it dosent work.
So I wrote two short programs to separately exercise the stepper, and the 2/2/2 (which has a joystick). These work nicely as stand alone programs. They were based the excellent examples on the website.
When I try to combine them, the joystick change events are being detected OK, but the steppers cant be controlled. I get no errors flagged - just nothing happens.
I've attached the java code. Its full of print statements as I try to understand what's going on (or not!) It does the print inside the altChange event method, but not the rest of that try block. I guess its all about where I am declaring or opening Phidgets?
Any pointers greatly fully accepted, but remember I'm a bit of a Java newbie!
Many thanks, Keith
ps:is there a better way to post code examples?
Code: Select all
import com.phidget22.*;
public class Java_Example {
public static Stepper altStepper;
public static DigitalOutput LED1;
public static void main(String[] args) throws Exception {
try {
VoltageRatioInput altJoy = new VoltageRatioInput();
VoltageRatioInput azJoy = new VoltageRatioInput();
DigitalInput button = new DigitalInput();
DigitalInput toggle = new DigitalInput();
DigitalOutput LED1 = new DigitalOutput();
DigitalOutput LED2 = new DigitalOutput();
Stepper altStepper = new Stepper();
altJoy.setChannel(0);
azJoy.setChannel(1);
button.setChannel(0);
toggle.setChannel(1);
LED1.setChannel(0);
LED2.setChannel(1);
altJoy.addVoltageRatioChangeListener(new VoltageRatioInputVoltageRatioChangeListener() {
public void onVoltageRatioChange(VoltageRatioInputVoltageRatioChangeEvent altJ) {
altChange(altJ);
}
});
azJoy.addVoltageRatioChangeListener(new VoltageRatioInputVoltageRatioChangeListener() {
public void onVoltageRatioChange(VoltageRatioInputVoltageRatioChangeEvent azJ) {
azChange(azJ);
}
});
button.addStateChangeListener(new DigitalInputStateChangeListener() {
public void onStateChange(DigitalInputStateChangeEvent butJ) {
try {
if (button.getState())
{
butChange(butJ);
}
}
catch (PhidgetException ex) {
System.out.println("");
}
}
});
toggle.addStateChangeListener(new DigitalInputStateChangeListener() {
public void onStateChange(DigitalInputStateChangeEvent togJ) {
togChange(togJ);
}
});
altStepper.open(5000);
System.out.println(altStepper.getPosition());
altStepper.setTargetPosition(100);
altStepper.setEngaged(true);
Thread.sleep(1);
System.out.println(altStepper.getPosition());
altJoy.open(5000);
altJoy.setVoltageRatioChangeTrigger(0.2);
azJoy.open(5000);
azJoy.setVoltageRatioChangeTrigger(0.2);
button.open(5000);
toggle.open(5000);
LED1.open(5000);
LED2.open(5000);
LED1.setDutyCycle(0);
LED2.setDutyCycle(0);
//Thread.sleep(1000);
}
catch (PhidgetException ex) {
System.out.println("PhidgetException " + ex.getErrorCode() + " (" + ex.getDescription() + "): " + ex.getDetail());
}
//Wait until Enter has been pressed before exiting
}
public static void azChange(VoltageRatioInputVoltageRatioChangeEvent az){
System.out.println("azimuth change: " + az.getVoltageRatio());
}
public static void altChange(VoltageRatioInputVoltageRatioChangeEvent alt){
System.out.println("altitude change: " + alt.getVoltageRatio());
try {
System.out.println("trying motor");
System.out.println(altStepper.getPosition());
LED1.setDutyCycle(1);
altStepper.setTargetPosition(100000);
altStepper.setEngaged(true);
System.out.println(altStepper.getPosition());
} catch (PhidgetException ex) {
System.out.println("PhidgetException " + ex.getErrorCode() + " (" + ex.getDescription() + "): " + ex.getDetail());
}
}
public static void butChange(DigitalInputStateChangeEvent but){
System.out.println("button change: ");
}
public static void togChange(DigitalInputStateChangeEvent tog){
System.out.println("toggle change: ");
}
}
/code]