Template:PT3 C WIN CB

From Phidgets Support

Windows with Code::Blocks

Welcome to using Phidgets with C! By using C, you will have access to the complete Phidget22 API, including events.

Code::Blocks is a free, open source cross-platform IDE that can be used for C and C++.

Requirements

First, make sure you have the following installed:

● Phidgets Drivers for Windows (see Part 1 of this user guide)

Code::Blocks

Setting up a New Project

When you are building a project from scratch, or adding Phidget functionality to an existing project, you'll need to configure your development environment to properly link the Phidget C library.

To start, open Code::Blocks, and go to Settings -> Compiler as shown in the image below:

Setting up a New Project

From the Global compiler settings screen, go to Search directories -> Compiler and add:

C:\Program Files\Phidgets\Phidget22

Setting up a New Project

Next, select Search directories -> Linker and add the following directory:

C:\Program Files\Phidgets\Phidget22\x86

Setting up a New Project

Next, go to Linker settings and add the following line:

phidget22

Setting up a New Project

Next, create a new Console Application project, as follows:

Setting up a New Project

Name your project, and finish creating the project.

Setting up a New Project

Now your project is created, and you can open the generated main.c to begin coding.

To include the Phidget C library, add the following line to your code:

#include <phidget22.h>

Your project now has access to the Phidget libraries.

Finding Code Samples

To find the code sample to use for your Phidget, navigate to the Code Samples page and select your device from the drop-down menu.

Once you select your device, the code sample generator will give you a working code sample, and a selection of options to customize it to your needs.

Using the Code Samples

If it's unclear what any of the options do, click on the nearby '?' for more info.

Once you've made your selections, click the copy button and paste the code into your new project.

What's Next?

Now that you've set up Phidgets in your C programming environment, you should read our guide on Phidget Programming Basics to learn the fundamentals of programming with Phidgets.

In particular, you should ensure that you familiarize yourself with how error handling is done in C, because it's not automatically implemented like in other programming languages. Once you've added error handling to your code, you can use the Error Code List to anticipate and handle various errors.

Continue down below for advanced information and troubleshooting for your device.

«
»