Template:PT3 CSHARP LNX DOTNET

From Phidgets Support

Linux with dotnet CLI

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

The dotnet command-line interface is the quickest way to start programming in C# on Linux and MacOS.

Requirements

First, make sure you have the Phidgets Drivers for Linux installed (see this page for installation instructions).


You also need our C development libraries in order to use dotnet. You can install them with:

apt-get install libphidget22-dev

Installing dotnet CLI

For installation instructions, visit Microsoft's documentation and select your Linux distro.

Usually, this will involve adding Microsoft packages to your repository and then installing dotnet via apt-get.

Setting up a New Project

Create a new C# project using the following command:

dotnet new console -o helloworld

This will create a new C# console application in a folder named helloworld in your current directory. Next, enter the folder and type:

dotnet run

If everything installed properly, the application should build and you'll see 'Hello, World!' printed in the terminal.

Getting Phidgets Sample Code

Next we'll use this base project to run some Phidgets sample code. Go to the product page for your Phidget and go to the Code Samples tab. Select C# from the language drop-down and use the check boxes to modify the example if you'd like.

Click the copy button in the corner of the code sample and paste it into the Program.cs for your HelloWorld program, overwriting the existing code.

Compile and Run

Once you've pasted the sample code into the .cs file and saved, you need to add the Phidgets .NET package to your project:

dotnet add package Phidget22.NET

Then you can re-build the project using

dotnet run

Success! The project is now using Phidgets.

What's Next?

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

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

«
»