Template:PT3 C WIN CB

From Phidgets Support
Revision as of 21:32, 8 March 2021 by Mparadis (talk | contribs) (Created page with "<div class="phd-slide-deck" data-deck="PT3_C_WIN_CB"> <div class="phd-slide-deck-header"><h3>Language - C</h3></div> <div class="phd-slides"> <div class="phd-slide"> <h2>Windo...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.

«
»