Language - C Sharp
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.
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
Create your Visual Studio project, and navigate to the Solution Explorer. From there, right-click on Dependencies and select Manage NuGet Packages... | |
Next, click Browse and enter Phidget22.NET in the search bar. | |
Click on the package and press the Install button. | |
Finally, add your C# code and run it using the button at the top of the screen. |
Visual Studio Code
Install the C# Dev Kit extension for Visual Studio Code. | |
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... | |
Open the Command Palette (Ctrl + Shift + P), type .NET: New Project, and press Enter. A list of supported project types will appear. | |
Select your preferred project type from the list. For this example, we will select Console App. | |
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.... | |
When prompted, enter Phidget22.NET and install the package. | |
Finally, add your C# code and run it using the button at the top of the screen. |
.NET Command-Line Interface (CLI)
Download and install the latest version of.NET from Microsoft's .NET download page. | |
Next, open a command prompt or terminal in a new folder and enter the following command:
dotnet new console
|
|
This previous command will create a new console application at the folder location. | |
Navigate back to the command prompt or terminal, and add the Phidget22.NET package with the following command:
dotnet add package Phidget22.NET
|
|
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
|
Example Code
Navigate to our Code Sample Generator to view and download code samples that are tailored to your specific device.
Phidget Programming Basics
To learn more about the structure of the example code, visit our Phidget Programming Basics guide.