Phidgets supports a variety of languages, but before you start programming, you'll need to get the library for the language you like working in, which can be found on the language pages on Phidgets.com. While you're there, you'll also find the code examples and an in-depth API.
The C library comes with the drivers you installed in Phidgets Lesson 1. So, for this lesson, we'll run those examples. This should get you started and ensure the Phidgets are working. You can refer to the resources provided by Phidgets to run examples in the other languages.
- Download the example code and unpack the downloaded file, which has the Phidget generic C examples.
- On Linux and OSX, open a terminal window and go to the directory where the examples are unpacked, then compile the
HelloWorld.cexample: On Linux:
On Mac:gcc HelloWorld.c -o HelloWorld -lphidget21
On Windows, you can use Visual Studio to open the examples. To load all projects in Visual Studio, go to File → Project → Solution, and opengcc example.c -o example -F/Library/Frameworks -framework Phidget21 -I/Library/Frameworks/Phidget21.framework/HeadersVisual Studio Phidgets Examples.slnin the VCpp folder of the examples. (Since the examples were written in Visual Studio 2005, if you are opening the examples in Visual Studio 2008/2010, you will need to go through the Visual Studio Conversion Wizard to open and convert the 2005 project.) -
Run the
HelloWorldexample. On Linux (The sudo is needed for USB access for now, see "Setting udev Rules" for how to change this):sudo ./HelloWorld
On Mac:
On Windows, in Visual Studio, click on Debug → Start Debugging. The projects, by default, try to find the./HelloWorldphidget21.handphidget21.libin the$(SystemDrive)\Program Files\Phidgets. If you have these files installed in another location, please change the path to the file's location accordingly.
The HelloWorldprogram will simply print out basic information for any device you plug in, and print a message upon unplugging the device. The output will look something like this:Opening... Press Enter to end Hello to Device Phidget InterfaceKit 8/8/8, Serial Number: 37299 Goodbye Device Phidget InterfaceKit 8/8/8, Serial Number: 37299 Closing...
This is a companion discussion topic for the original entry at https://community.robotshop.com/index.php/blog/show/phidgets-lesson-2-running-the-examples