Some questions about Phidgets in Java

Supporting Java SE version 7 and up
Bremen
Fresh meat
Posts: 3
Joined: Thu Jan 09, 2014 3:14 am
Contact:

Some questions about Phidgets in Java

Postby Bremen » Thu Jan 09, 2014 3:18 am

Hello everyone,


I am currently doing a multi plateform program. I have program it on Arduino, I would like to program it now on Phidgets.
Is there a function like the Arduino "Serial.print()" on Phidgets in Java or should I use the RXTX librairie ?
Also, because they are not really good documentation on Phidgets, how many storage memory did they dispose ? Did they reset (like Arduino do) when we establish the serial connection ?

Thanks a lot.

erik
King of the Lab
Posts: 476
Joined: Fri Mar 06, 2009 12:42 pm
Location: Calgary, Canada
Contact:

Re: Some questions about Phidgets in Java

Postby erik » Thu Jan 09, 2014 9:33 am

Phidgets do not communicate using serial ports. They communicate with the host computer using USB. You can check out our Java support documentation and our Java API page to see how to set up communication. Our Java examples also show how to use them.

Instead of using Serial.print(), you would simply access the Phidget device object's properties and methods available in the Java API.

Also since the program that you write runs on the computer instead of directly on the Phidget, the storage memory depends only on how much you have on your computer - when using Phidgets, you are only writing software and not firmware.

Bremen
Fresh meat
Posts: 3
Joined: Thu Jan 09, 2014 3:14 am
Contact:

Re: Some questions about Phidgets in Java

Postby Bremen » Fri Jan 10, 2014 3:08 am

Thanks, it helps me a lot.
Anyway, I have another question. When you said
Also since the program that you write runs on the computer instead of directly on the Phidget, the storage memory depends only on how much you have on your computer - when using Phidgets, you are only writing software and not firmware.


I don't really understand ... I would like to have a program running on Phidgets, and not on my computer. I would like a software on my Phidgets, which will be able to run without the standalone.
Bascially, the program I have to write should connect to a computer to send data and to receive command, to manage sensors. He has to connect this sensor data by itself, not with the computer help.

Because of this, I have problem to develop on Phidgets, because I don't know how to upload my program on it ...

Thanks a lot !

User avatar
mparadis
Site Admin
Posts: 632
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: Some questions about Phidgets in Java

Postby mparadis » Mon Jan 13, 2014 8:45 am

The only type of Phidget capable of running a program without being connected to a computer via USB are Phidget SBCs. An SBC can act as a host computer for other Phidgets, and also has an InterfaceKit built in. You cannot run programs on any other type of Phidget because they do not have storage memory or a processor.

Bremen
Fresh meat
Posts: 3
Joined: Thu Jan 09, 2014 3:14 am
Contact:

Re: Some questions about Phidgets in Java

Postby Bremen » Mon Jan 13, 2014 10:14 am

Thanks you very much, I was thinking like on Arduino, so its sounds weird to me ... But now, i'm ok !
I just have some issue with the InterfaceKit Phidgets (I am using it right now) and i'm not able to open it ...

May be you'll have some solutions ?

Here is my code (wrapped in one of your package)

Code: Select all

 // Do an action when the event is triggered.
      public void attached(AttachEvent event)
      {

         int serialNumber = 0;
         String name = new String();
         InterfaceKitPhidget ikp;

         try
         {
            // Get the Phidget name and Serial Number.
            serialNumber = ((Phidget) event.getSource()).getSerialNumber();
            name = ((Phidget) event.getSource()).getDeviceName();
            ikp = new InterfaceKitPhidget();
            ikp.open(serialNumber);
            System.out.println(ikp.getSensorValue(3));
         }
         catch (PhidgetException exception)
         {
            printError(exception.getErrorNumber(), exception.getDescription());
         }

         System.out.println("Hello Device " + name + ", Serial Number: " + Integer.toString(serialNumber));
      }
   };


And i get the error "Error Event: 5 - Phidget not physically attached."
and then
"Hello Device Phidget InterfaceKit 8/8/8, Serial Number: 6706"

that proof the values are correct ... But it is not able to open the connection ... Thanks!

erik
King of the Lab
Posts: 476
Joined: Fri Mar 06, 2009 12:42 pm
Location: Calgary, Canada
Contact:

Re: Some questions about Phidgets in Java

Postby erik » Mon Jan 13, 2014 2:00 pm

There are two issues that I can see here.

1. You are trying to open the object again. In the main(), it is already opening and trying to connect to it. When your program jumps into the attached() function, this is an event that is triggered when the device is in the process of setting up communication and attaching. So you don't need to have

Code: Select all

ikp = new InterfaceKitPhidget();
ikp.open(serialNumber);

in this section again (unless you are actually trying to open second device, in which this case this is also bad because calling open() and connecting to a second device will cause the attached() function to be called again, and then it will try to attach to the same device again and you will get an error).

2.

Code: Select all

ikp = new InterfaceKitPhidget();
ikp.open(serialNumber);
System.out.println(ikp.getSensorValue(3));

When you call open() and then immediately getSensorValue(), the InterfaceKit won't have enough time to establish communication, and so you are getting the "Not physically connected" error. You can use the waitForAttachment() method immediately after open(), which will block your program from continuing until the device gets attached.

So this is why you are getting an error, and then you see the "Hello Device..." message.

If you run the example without the extra code you added, then it will show that it is correctly attaching.

I'm not sure if you have done too much Event Driven programming, but it would be helpful to check out if you want to use events.


Return to “Java”

Who is online

Users browsing this forum: No registered users and 0 guests