9
1051_2_Product_Manual - May 5, 2010 4:34 PM
Programming a Phidget
Phidgets’ philosophy is that you do not have to be an electrical engineer in order to do projects that use devices
like sensors, motors, motor controllers, and interface boards. All you need to know is how to program. We have
developed a complete set of Application Programming Interfaces (API) that are supported for Windows, Mac OS X,
and Linux. When it comes to languages, we support VB6, VB.NET, C#.NET, C, C++, Flash 9, Flex, Java, LabVIEW,
Python, Max/MSP, and Cocoa.
Architecture
We have designed our libraries to give you the maximum amount of freedom. We do not impose our own
programming model on you.
To achieve this goal we have implemented the libraries as a series of layers with the C API at the core surrounded
by other language wrappers.
Libraries
The lowest level library is the C API. The C API can be programmed against on Windows, CE, OS X and Linux. With
the C API, C/C++, you can write cross-platform code. For systems with minimal resources (small computers), the C
API may be the only choice.
The Java API is built into the C API Library. Java, by default is cross-platform - but your particular platform may not
support it (CE).
The .NET API also relies on the C API. Our default .NET API is for .NET 2.0 Framework, but we also have .NET
libraries for .NET 1.1 and .NET Compact Framework (CE).
The COM API relies on the C API. The COM API is programmed against when coding in VB6, VBScript, Excel (VBA),
Delphi and Labview.
The ActionScript 3.0 Library relies on a communication link with a PhidgetWebService (see below). ActionScript 3.0
is used in Flex and Flash 9.
Programming Hints
Every Phidget has a unique serial number - this allows you to sort out which device is which at runtime. Unlike
•
USB devices which model themselves as a COM port, you don’t have to worry about where in the USB bus you
plug your Phidget in. If you have more than one Phidget, even of the same type, their serial numbers enable
you to sort them out at runtime.
Each Phidget you have plugged in is controlled from your application using an object/handle specific to that
•
phidget. This link between the Phidget and the software object is created when you call the .OPEN group of
commands. This association will stay, even if the Phidget is disconnected/reattached, until .CLOSE is called.
The Phidget APIs are designed to be used in an event-driven architecture. While it is possible to poll them, we
•
don’t recommend it. Please familiarize yourself with event programming.
Networking Phidgets
The PhidgetWebService is an application written by Phidgets Inc. which acts as a network proxy on a computer. The
PhidgetWebService will allow other computers on the network to communicate with the Phidgets connected to that
computer. ALL of our APIs have the capability to communicate with Phidgets on another computer that has the
PhidgetWebService running.
The PhidgetWebService also makes it possible to communicate with other applications that you wrote and that are
connected to the PhidgetWebService, through the PhidgetDictionary object.