PDA

View Full Version : Multiple Phidget 8/8/8 board problem



askinner
06-27-2007, 09:54 AM
I am trying to interface two Phidget 8/8/8 boards with a program written in C++.
I can initialize one board by using:

CPhidget_open( IFK, -1 );

Where IFK is my first Interface Kit Handle, and -1 finds the serial number automatically.

However, if I use:

CPhidget_open( IFK2, -1 );

Where IFK2 is my second Interface Kit Handle, it assigns the same serial number to both Phidget boards.

How do I set it up in such a way that I can plug in any two phidget 8/8/8 boards, and it will assign two different boards (with serials) with both Interface Kit Handles.

Thanks

Alex
06-27-2007, 10:52 AM
Hey sKinner!

Using -1 finds the serial number automatically only if you have one of the same kind of Phidget device connected to your computer. If you have more than one, you need to find the serial number of each device and pass that instead of -1 each time.


CPhidget_open (CPhidgetHandle, int SerialNumber);
Attempts to locate a Phidget matching your requirements on the local computer.
The CPhidgetHandle should be a valid handle previously allocated by CPhidget(device)_create. Before
calling CPhidget_open, we recommend registering the event handlers your application will use.
SerialNumber specifies the desired serial number, allowing the call to open a specific Phidget.
Specifying -1 for the serial number will cause it to open the first available device.
Open is pervasive. What this means is that you can call open on a device before it is plugged in, and
keep the device opened across device dis- and re-connections.
Open is Asynchronous. What this means is that open will return immediately – before the device being
opened is actually available. What this means is that you need to either poll CPhidget_getDeviceStatus
for an attached status, or handle the attach event, in order to wait for the device to become available
before trying to use it.

You can read more about this and the other various commands on the C API Manual in the Downloads Section (http://www.phidgets.com/downloads_sections.php) at Phidgets.com

askinner
06-27-2007, 11:16 AM
Thats no good to me.
I need to connect any two 8/8/8 boards, and it would be really nice if they "just worked". I don't want to be manually entering phidget board serials unless I absolutely have to, and it adds a severe complication to my code if I have to start reading from text files, or typing them in manually.

would it help if I had one w/led display and one without?

Alex
06-27-2007, 11:50 AM
They do "just work", that's just the way that Phidgets work;)

However, if you need multiple devices of the same type connect to a single machine, and cannot deal with serial numbers, then you'll have to build your application around the concept of having multiple ID's, essentually, creating "DynamicPhidgets", something that I was working on a bit ago, but I had other things that got in the way.

Here's the concept:

Think about the fact that all Phidget devices inherit constructors, properties, methods and events from the same base class, Phidget. That being said, all you have to do is use the Phidget.Manager object in your class. The Phidget.Manager object is a manager class that handles the attach/detach events (along with some other stuff) for all Phidget devices connected to the same computer.

Then, additionally in your class, you'll have a custom Type-Based collections, one for each particular type you need to instantiate. When you call the .Open command on the Phidget.Manager object, the Attach event of the Phidget Manager fires for each device. Inside that Attach event, you'll run the passed data to determine the device type and serial number, and then add it to the correct custom Type-Based collection. When you are inside the Attach event, be sure to check the e.Device object, as that is the object that is created internally, and passed as the correct Phidget device being created.

I hope all of that made sense:)

I know it may be a bit confusing, so don't hesitate to ask questions. I just won't be able to help very much when it comes down to coding. I'm a C# guy.

BTW, the 0/16/16, 8/8/8, 0/0/4, and the Text LCD with 8/8/8 all are Interface Kit types in code.

askinner
06-27-2007, 12:03 PM
wow. Sounds like it would be easier to read the serial numbers from a text file.

Alex
06-27-2007, 12:15 PM
Aww. Come on man, aren't up for a challenge:D

Seriously though, it will work, I know for a fact, because I almost completed it. There was just too many other day to day work things that got in the way. Hopefully I'll be able to revisit and finish that project though.

askinner
06-28-2007, 06:53 AM
The thing is, I'm not doing this for fun. I am using this in a work-related project, and time is money. My superiors have no problem modifiying text files, but they will have a problem with a major overhaul of the code when a much simpler solution exists.

Alex
06-28-2007, 08:32 AM
gotcha.

Work-related projects using Phidgets? Man, I bet that's fun:)

Do you have a GUI application?

If so, obviously I don't know much about your project so this may not be possible at all, but instead of having a text file to modify, couldn't you just populate a dropdown box of some sort that allows people to choose between the IFK's attached to the computer?

If that's completely out of the question and you can tell me a bit more about your app, then I might be able to come up with a more streamlined solution.

askinner
06-29-2007, 06:14 AM
Yes it is a GUI application using MFC.

I'm actually looking at using the classes of MFC to make its own configration file and simply read it on start-up with the ability to modifiy it through the program.

The program is currently set up to save/load configuration files for calibration of different pieces of hardware. Essentially what I am using this program for is integrating components of a ships bridge (wheel, thrusters, throttles) into a bridge simulator via a phidget board (or two depending on the amount of hardware required to steer the ship.)

So yes, its fun, and very interesting, and it's getting complex. But that is about all I can say about the work that I am doing. :)

Alex
06-29-2007, 10:29 AM
That does sound like a blast:D

The only thing other than the text file, is the dropdown that I mentioned that gets populated with the IFK serial numbers at startup:(

askinner
07-03-2007, 06:58 AM
yeh, it's alright.

I think I got it figured out.