Template:Language - Java Editing the Examples
To get our example code to run in a custom application, simply remove the calls to AskForDeviceParameters and PrintEventDescriptions, as well as the ChannelInfo object, then hard-code the addressing parameters for your application.
If you are unsure what values to use for the addressing parameters, check the Finding The Addressing Information page.
For instance:
//You may remove these lines and hard-code the addressing parameters to fit your application
ChannelInfo channelInfo = new ChannelInfo(); //Information from AskForDeviceParameters(). May be removed when hard-coding parameters.
PhidgetHelperFunctions.AskForDeviceParameters(channelInfo, ch);
ch.setDeviceSerialNumber(channelInfo.deviceSerialNumber);
ch.setHubPort(channelInfo.hubPort);
ch.setIsHubPortDevice(channelInfo.isHubPortDevice);
ch.setChannel(channelInfo.channel);
if(channelInfo.netInfo.isRemote) {
ch.setIsRemote(channelInfo.netInfo.isRemote);
if(channelInfo.netInfo.serverDiscovery) {
try {
Net.enableServerDiscovery(ServerType.DEVICE_REMOTE);
}
catch (PhidgetException e) {
PhidgetHelperFunctions.PrintEnableServerDiscoveryErrorMessage(e);
throw new Exception("Program Terminated: EnableServerDiscovery Failed", e);
}
}
else {
Net.addServer("Server", channelInfo.netInfo.hostname,
channelInfo.netInfo.port, channelInfo.netInfo.password, 0);
}
}
//This call may be harmlessly removed
PrintEventDescriptions();
Might become:
ch.setDeviceSerialNumber(370114);
ch.setHubPort(2);
ch.setIsHubPortDevice(true);
Notice that you can leave out any parameter not relevant to your application for simplicity.
You can then manipulate the rest of the code as your application requires. A more in-depth description of programming with Phidgets can be found in our guide on Phidget Programming Basics.
For future Phidgets-based projects, you can leave out the PhidgetHelperFunctions.java and ChannelInfo.java classes entirely.