Language - C Windows Visual Studio

From Phidgets Support
Revision as of 20:39, 22 May 2019 by Jdecoux (Talk | contribs)

Jump to: navigation, search

Language - C

Windows with Visual Studio



Install Phidget Drivers for Windows


  1. You will need the Phidgets Windows Drivers

Use Our Examples

One of the best ways to start programming with Phidgets is to use our example code as a guide. In order to run the examples, you will need to download and install Microsoft Visual Studio.

Now that you have Microsoft Visual Studio installed, select an example that will work with your Phidget:

Open the example project by unzipping the example folder, and opening the ExampleName.sln file in the ExampleName folder.

Once the project is open, start the example by pressing the Local Windows Debugger button:

C vs run.png

The application will open the Phidget, list basic information about the Phidget, and demonstrate the Phidget's functionality. Here is an example of an Accelerometer channel on a Spatial Phidget:

C vs output.PNG

Unresolved External Symbol

If you try to compile the program and the linker throws a number of errors called unresolved external symbol, then it is likely the project is trying to run using the wrong platform. Select your platform from the drop-down list, as shown in the image below.

VS Select Platform.jpg


Editing the Examples



For instance:

AskForDeviceParameters(&channelInfo, (PhidgetHandle)ch);

prc = Phidget_setDeviceSerialNumber((PhidgetHandle)ch, channelInfo.deviceSerialNumber);
CheckError(prc, "Setting DeviceSerialNumber", &(PhidgetHandle)ch);

prc = Phidget_setHubPort((PhidgetHandle)ch, channelInfo.hubPort);
CheckError(prc, "Setting HubPort", &(PhidgetHandle)ch);

prc = Phidget_setIsHubPortDevice((PhidgetHandle)ch, channelInfo.isHubPortDevice);
CheckError(prc, "Setting IsHubPortDevice", &(PhidgetHandle)ch);
CheckError(prc, "Setting Channel", &(PhidgetHandle)ch);

if (channelInfo.netInfo.isRemote) {
    prc = Phidget_setIsRemote((PhidgetHandle)ch, channelInfo.netInfo.isRemote);
    CheckError(prc, "Setting IsRemote", &(PhidgetHandle)ch);
    if (channelInfo.netInfo.serverDiscovery) {
        prc = PhidgetNet_enableServerDiscovery(PHIDGETSERVER_DEVICEREMOTE);
        CheckEnableServerDiscoveryError(prc, &(PhidgetHandle)ch);
    } else {
        prc = PhidgetNet_addServer("Server", channelInfo.netInfo.hostname,
                    channelInfo.netInfo.port, channelInfo.netInfo.password, 0);
        CheckError(prc, "Adding Server", &(PhidgetHandle)ch);

Might become:

prc = Phidget_setDeviceSerialNumber((PhidgetHandle)ch, 370114);

prc = Phidget_setHubPort((PhidgetHandle)ch, 2);

prc = Phidget_setIsHubPortDevice((PhidgetHandle)ch, 1);



Setting up a New Project


Create a new Win32 Console application:

C vs newproject.PNG

Select an empty project and finish:

C vs emptyproject.PNG


C vs configuration.png

Next, add a new item to your source folder:

C vs additem.png

Give the source file a descriptive name and continue:

C vs addsource.PNG

Access the project's properties:

C vs propertie.png


  • C:\Program Files\Phidgets\Phidget22

C vs additionalinclude.png



C vs additionadepend.png


#include <phidget22.h>
C vs finished.PNG

Success! The project now has access to Phidgets.

Common Issues

  • Linker error when using examples with a non-English version of Windows

The example projects, by default finds the phidget22.h and phidget22.lib in ${SystemDrive}\Program Files\Phidgets\Phidget22. If you are using a non US-English version of Windows, the Phidget drivers may be installed into a different location. To resolve, you will have to modify the paths to these two files.

What's Next?
