JAVA Phidget22 API InterfaceKit 8/8/8 EXAMPLE?

Supporting Java SE version 7 and up
VytautasDV
Phidgetsian
Posts: 6
Joined: Fri Jul 07, 2017 4:37 am
Contact:

JAVA Phidget22 API InterfaceKit 8/8/8 EXAMPLE?

Post by VytautasDV »

I'm sorry I have to do this, but API and examples are complete waste. Is it just me or what?

If anyone could post example of 8/8/8 interface kit i would appreciate.

It would be nice if the example had:

code for selecting specific kit if the whole system had more then one kit (i assume it is done with serial number);
code for selecting specific ports for reading sensor data (or voltage, i can use formulas later on to get exact value);

Example language preference is JAVA.
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: JAVA Phidget22 API InterfaceKit 8/8/8 EXAMPLE?

Post by mparadis »

The comments in the Java examples explain how to specify the InterfaceKit and port using setDeviceSerialNumber and setChannel, respectively:

Code: Select all

 /*
            * Specifies the serial number of the device to attach to.
            * For VINT devices, this is the hub serial number.
            *
            * The default is any device.
            */
            //ch.setDeviceSerialNumber(<YOUR DEVICE SERIAL NUMBER>);
            /*
            * For VINT devices, this specifies the port the VINT device must be plugged into.
            *
            * The default is any port.
            */
            //ch.setHubPort(0);

            /*
            * Specifies that the channel should only match a VINT hub port.
            * The only valid channel id is 0.
            *
            * The default is 0 (false), meaning VINT hub ports will never match
            */
             //ch.setIsHubPortDevice(true);

            /*
            * Specifies which channel to attach to.  It is important that the channel of
            * the device is the same class as the channel that is being opened.
            *
            * The default is any channel.
            */
            //ch.setChannel(0);
For more information on channel matching (i.e. how the drivers determine which channel to open based on the information you provide) see this page.

Edit: You can use the VoltageRatioInput or VoltageInput example to read sensor data, depending on whether the sensor is ratiometric or non-ratiometric.
VytautasDV
Phidgetsian
Posts: 6
Joined: Fri Jul 07, 2017 4:37 am
Contact:

Re: JAVA Phidget22 API InterfaceKit 8/8/8 EXAMPLE?

Post by VytautasDV »

Example please.
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: JAVA Phidget22 API InterfaceKit 8/8/8 EXAMPLE?

Post by mparadis »

If all you want to do is open and read a sensor on an InterfaceKit, then the VoltageInput or VoltageRatioInput example (from this page) is all you should need.

Is there some functionality that is missing in these examples, or are you getting errors when you try to run them?
VytautasDV
Phidgetsian
Posts: 6
Joined: Fri Jul 07, 2017 4:37 am
Contact:

Re: JAVA Phidget22 API InterfaceKit 8/8/8 EXAMPLE?

Post by VytautasDV »

I want to get into phidgets programming and I cant wrap my head around the examples.

Lets theoretically take interface kit 8/8/8 and precision light sensor, i want to connect light sensor to analog port 3 and just read data without all the event listeners.

So theoretically i need to specify interface kit's S/N and port from which i will read the data. It should be more or less 10-20 code lines.

as i imagine it should look like this:

Code: Select all

import com.phidget22.*;

public class VoltageInputExample {

    public static void main(String[] args) throws Exception {
    	
    	double x;
    	
        VoltageInput ch = new VoltageInput();
		
        x = ch.getVoltage();
    }
}
what do i need to add to this code to specify what interface kit is being used at this moment and what port the sensor is on?
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: JAVA Phidget22 API InterfaceKit 8/8/8 EXAMPLE?

Post by mparadis »

Before you can get the voltage, you need to open the channel. First you declare the channel:

Code: Select all

VoltageRatioInput ch = new VoltageRatioInput();
Then you provide information to narrow down which VoltageRatioInput channel you want:

Code: Select all

ch.setDeviceSerialNumber(283033);
ch.setChannel(3);
Edit: then you have to open the channel (the parameter is the number of milliseconds to try to open for before it times out):

Code: Select all

ch.open(5000);
Then you can get the voltage:

Code: Select all

double x;
x = ch.getVoltage();
You can also set an event handler which will launch code every time the voltage changes:

Code: Select all

ch.addVoltageChangeListener(new VoltageInputVoltageInputChangeListener) {
public void onVoltageChange(VoltageInputVoltageChangeEvent e) {
				System.out.printf("Voltage Changed: %.3g\n", e.getVoltage());
			}
        });
VytautasDV
Phidgetsian
Posts: 6
Joined: Fri Jul 07, 2017 4:37 am
Contact:

Re: JAVA Phidget22 API InterfaceKit 8/8/8 EXAMPLE?

Post by VytautasDV »

Finally, thank you.

So in summary it would look like this?

Code: Select all

import com.phidget22.*;

public class VoltageInputExample {

    public static void main(String[] args) throws Exception {

        VoltageRatioInput ch = new VoltageRatioInput();

		ch.setDeviceSerialNumber(283033);
		ch.setChannel(3);
		ch.open(5000);

		double x;
        x = ch.getVoltage();
    }
}
But it raises another question.

What if I have two sensors? precision light sensor on port 3 and precision temperature sensor on port 5.

How does this code line

Code: Select all

x = ch.getVoltage();
know from which sensor I am trying to read voltage?

Or a better question. How do i tell to that code line which sensor to read?
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: JAVA Phidget22 API InterfaceKit 8/8/8 EXAMPLE?

Post by mparadis »

Before you opened the channel, you specified that you wanted your InterfaceKit's third VoltageInput port:

Code: Select all

ch.setChannel(3);
Once you've opened ch, this variable permanently refers to that third port on the InterfaceKit until you close and reopen it. If you wanted to read from both sensors, you'd create 2 VoltageInput objects and give them different information:

Code: Select all

VoltageRatioInput light_ch = new VoltageRatioInput();
VoltageRatioInput temp_ch = new VoltageRatioInput();

light_ch.setChannel(3);
temp_ch.setChannel(5);
VytautasDV
Phidgetsian
Posts: 6
Joined: Fri Jul 07, 2017 4:37 am
Contact:

Re: JAVA Phidget22 API InterfaceKit 8/8/8 EXAMPLE?

Post by VytautasDV »

Thank you!
dmccue128
Phidgetsian
Posts: 5
Joined: Sun Sep 03, 2017 5:47 am
Contact:

Re: JAVA Phidget22 API InterfaceKit 8/8/8 EXAMPLE?

Post by dmccue128 »

Just to be sure I understand, for InterfaceKit 8/8/8 when I say,

ch = new VoltageInput();
ch.setChannel(3);
ch.open(5000);

this is referring to analog input #3

My digital input might have the same channel number, right?

chInput = new DigitalInput();
chInput.setChannel(3);
chInput.open(5000);

The channel numbering for the InterfaceKit 8/8/8 is 0-7 for each of DigitalInput, DigitalOutput and VoltageInput?
Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests