Template:PT3 CSHARP LNX DOTNET: Difference between revisions

From Phidgets Support
(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...")
 
No edit summary
 
Line 19: Line 19:
<h2>Requirements</h2>
<h2>Requirements</h2>


<p>First, make sure you have the following installed:</p>
<p>
 
First, make sure you have the Phidgets Drivers for Linux installed (see <span>[https://www.phidgets.com/docs/OS_-_Linux this page]</span> for installation
<p>● Phidgets Drivers for Linux (see <span>[https://www.phidgets.com/docs/OS_-_Linux this page]</span> for installation instructions)</p>
instructions).
</p>


<br />
<br />
Line 48: Line 49:
<div class="phd-command-line"><code>dotnet new console -o helloworld</code></div>
<div class="phd-command-line"><code>dotnet new console -o helloworld</code></div>


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


<div class="phd-command-line"><code>dotnet run</code></div>
<div class="phd-command-line"><code>dotnet run</code></div>


<p>If everything installed properly, the application should build and you'll see 'Hello, World!' printed in the terminal.</p>
<p>If everything installed properly, the application should build and you'll see <b>'Hello, World!'</b> printed in the terminal.</p>
</div>
</div>


Line 59: Line 60:


<p>
<p>
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
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 <b>Code Samples</b> tab. Select C# from
language drop-down and use the check boxes to modify the example if you'd like.
the language drop-down and use the check boxes to modify the example if you'd like.
</p>
</p>


<div class="phd-lazy-image" data-src="https://www.phidgets.com/decks/PT3_CSHARP_LNX_DOTNET/example.jpg"></div>
<div class="phd-lazy-image" data-src="https://www.phidgets.com/decks/PT3_CSHARP_LNX_DOTNET/-x240/50/example.jpg"></div>


<p>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.</p>
<p>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.</p>

Latest revision as of 19:32, 27 May 2024

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.

«
»