Template:PT3 CSHARP LNX DOTNET

From Phidgets Support
Revision as of 19:22, 27 May 2024 by Mparadis (talk | contribs) (Created page with "<div class="phd-slide-deck" data-deck="PT3_CSHARP_LNX_DOTNET"> <div class="phd-slide-deck-header"><h3>Language - C#</h3></div> <div class="phd-slides"> <div class="phd-slide"> <h2>Linux with dotnet CLI</h2> <div class="phd-panels"> <div class="phd-panel phd-flex-column-align-center phd-flex-column-justify-middle"> <div class="phd-lazy-image" data-src="https://www.phidgets.com/decks/PT3_CSHARP_LNX_DOTNET/200x-/50/dotnet.jpg"></div> </div> <div class="phd-panel phd-flex-c...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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 following installed:

● Phidgets Drivers for Linux (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.

«
»