Using the Phidget22 API

From Phidgets Support
Jump to: navigation, search
 Phidget Programming Basics: Using the Phidget22 APITOC Icon.png Table of Contents

Back Arrow.png WhiteTab1.png WhiteTab2.png WhiteTab3.png WhiteTab4.png WhiteTab5.png WhiteTab6.png WhiteTab7.png WhiteTab8.png WhiteTab9.png WhiteTab10.png WhiteTab11.png WhiteTab12.png GreenTab13.png WhiteTab14.png WhiteTab15.png WhiteTab16.png Next Arrow.png


13 . Using the Phidget22 API

The Phidget22 API is the collection of properties, functions, events, and other tools that are at your disposal when programming with Phidgets. Our API documentation will define each of these items and guide you through their usage. Reading the API is a good way to learn what your device is capable of, and it also useful to have open when you're reading through the sample programs we provide.

To begin, we recommend that you go to the product page for your device and click on the API tab:

APItab.jpg

Firmware version found in the Phidget Control Panel.

From there, you can select your preferred programming language and specify the firmware version of your device (You can find the firmware version in the "version" column of the Phidget Control Panel). The final box selects which channel class you want to look at. Many Phidgets will have multiple different channel classes for differing parts of the physical device. For example, this DC motor controller has separate channel classes for its DCMotor, Encoder, and MotorPositionController functionalities. There is also a generic Phidget API for each one that contains common functions like open and close.

APIselect.jpg

Once you've selected a channel class, all of the members will be sorted into categories below

  • Properties - These are variables that can be "set" and/or "get" which control certain aspects of the device. Some properties like the DCMotor's CurrentLimit can be changed, and others like MaxCurrentLimit are constants. For languages that don't support properties, these are managed using functions or methods instead.
  • Functions / Methods - These are commands that do something with your device. (e.g. the Spatial's ZeroGyroscope command)
  • Events - These are triggers that you can assign to a piece of code that you want to execute every time something happens with your device, like when data comes in or when the channel attaches.
  • Constants and Enumerations - Constants are variable names that represent a static value. Using them instead of the numbers they represent makes your code more legible and cross-compatible with other devices of the same class. Enumerations are groups of numbers that represent options for a certain setting.
  • Structs - These are variables that a grouped together to make them easier to use.

Click on a member to expand the box and display in-depth information about it: Parameters, return values, minimum and maximum allowable values, code sample showing proper usage, and more.