Language - C Sharp

From Phidgets Support


Get Started

With the Phidget22.NET library, it's easy to create C# applications that work with Phidget devices.

C# Libraries

Nuget Package

The Phidget22.NET library is available as a nuget package. This is the recommend way to install and manage the Phidget22.NET library.

macOS Considerations

Phidget devices running a HID USB stack require the installation of the macOS libraries or the standalone Phidget Control Panel (download here).

To determine what USB stack your Phidget device is on, navigate to the product page and then to the specification tab, and look for the USB Stack specification. If you are using a VINT device, navigate to the product page for the VINT Hub you are using.

Javascript networkserver webusb spec.png

Linux Considerations

Linux restricts access to USB devices to the root user. To run your .NET application as a regular user, you'll need to set up udev rules on your system.

Library Files

If you would like to manually manage the Phidget22.NET library files, you can download them here.

Development Environment Configuration

Visual Studio

Instructions
Create your Visual Studio project, and navigate to the Solution Explorer. From there, right-click on Dependencies and select Manage NuGet Packages...
Language csharp vs managenuget.png
Next, click Browse and enter Phidget22.NET in the search bar.
Language csharp vs browsenuget.png
Click on the package and press the Install button.
Language csharp vs installnuget.png
Finally, add your C# code and run it using the button at the top of the screen.
Language csharp vs run.png

Visual Studio Code

Instructions
Install the C# Dev Kit extension for Visual Studio Code.
Language csharp vscode installext.png
Next, create a directory and open it in Visual Studio Code. You can do this by opening Visual Studio Code and selecting File > Open Folder...
Language csharp vscode newfolder.png
Open the Command Palette (Ctrl + Shift + P), type .NET: New Project, and press Enter. A list of supported project types will appear.
Language csharp vscode netnewproject.png
Select your preferred project type from the list. For this example, we will select Console App.
Language csharp vscode netconsoleapp.png
Next, we need to add the Phidget22.NET library using NuGet. Open the Command Palette again (Ctrl + Shift + P), and enter NuGet: Add NuGet package....
Language csharp vscode addnugetpackage.png
When prompted, enter Phidget22.NET and install the package.
Language csharp vscode phidget22net.png
Finally, add your C# code and run it using the button at the top of the screen.
Language csharp vscode runcodepng.png

.NET Command-Line Interface (CLI)

Instructions
Download and install the latest version of.NET from Microsoft's .NET download page.
Language csharp cli download.png
Next, open a command prompt or terminal in a new folder and enter the following command:
dotnet new console
Language csharp cli newconsole.png
This previous command will create a new console application at the folder location.
Language csharp cli newproject.png
Navigate back to the command prompt or terminal, and add the Phidget22.NET package with the following command:
dotnet add package Phidget22.NET
Language csharp cli addpackage.png
You can now open the Program.cs file and add your code. Run the program by entering the following command into your command prompt or terminal:
dotnet run
Language csharp cli runcode.png

Example Code

Navigate to our Code Sample Generator to view and download code samples that are tailored to your specific device.

Language csharp codesample.png

Phidget Programming Basics

To learn more about the structure of the example code, visit our Phidget Programming Basics guide.

API

Phidget22 API