Language - C Sharp Windows Visual Studio

From Phidgets Support
Revision as of 21:34, 26 June 2018 by Mparadis (talk | contribs) (Created page with "{{NoTitle}} {{Language_-_CSharp_Dev_Environment_Table}} {| |style="vertical-align:middle; width: 60%;"| <font size=6>'''Language - C#''' '''Windows with Visual Studio'''</fon...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
C# Development Environments
OS - Windows Windows

CS VS WIN.png CS VS WIN on.png

CS MONO WIN.png CS MONO WIN on.png

CS MONODEV WIN.png CS MONODEV WIN on.png

OS - macOS macOS

CS MONO MAC.png CS MONO MAC on.png

OS - Linux Linux

CS MONO LNX.png CS MONO LNX on.png

Language - C#

Windows with Visual Studio

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

Visual Studio is an IDE provided by Microsoft that can be used to develop code in a wide variety of programming languages, including C#.

Install Phidget Drivers for Windows

Before getting started with the guides below, ensure you have the following components installed on your machine:

  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 and start the example by pressing the Start button:


Csharp visualstudio 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 a Digital Output channel on a RFID Phidget:


Csharp visualstudio rfid.PNG


You should now have the example up and running for your device. Play around with the device and experiment with some of the functionality. When you are ready, the next step is configuring your project and writing your own code!

VINT Hub

If you are trying to connect to one of the VINT hub ports directly rather than to a VINT device connected through a VINT hub then there is one additional step. There is a isHubPort property of the Phidget class that must be set before calling open. It defaults to false but in this case it will need to be set to true. In our examples this is done via command line though in practice you can just set it before calling open. To add command line parameters to your project in Visual Studio, you can go to the Project->Properties screen. Under the Debug section there is a field to enter command line parameters for startup. Use "-h" to make sure isHubPort is set before open is called and then you should be good to go.

Csharp visualstudio commandLineParameters.png

Configure Your 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 .NET library. To begin:


Create a new Windows Forms Application project:


CSharp VS2015 New Project.png


Next, right-click to add a reference to the Phidget .NET library:


CSharp VS2015 Add Reference.png


On the following screen, click Browse... and navigate to the location of Phidget22.NET.dll:

  • C:\Program Files\Phidgets\Phidget22\Phidget22.NET.dll


CSharp VS2015 Add Reference 2.png


Finally, to include the Phidget .NET library, add the following lines to main window class file:

using Phidget22;
using Phidget22.Events;

Success! The project now has access to Phidgets. Next, view the write your own code section located below.