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 |
||
(One intermediate revision by the same user not shown) | |||
Line 11: | Line 11: | ||
<div class="phd-panel phd-flex-column-align-left phd-flex-column-justify-top"> | <div class="phd-panel phd-flex-column-align-left phd-flex-column-justify-top"> | ||
<p>Welcome to using Phidgets with C#! By using C#, you will have access to the complete Phidget22 API, including events.</p> | <p>Welcome to using Phidgets with C#! By using C#, you will have access to the complete Phidget22 API, including events.</p> | ||
<p>The dotnet command-line interface is the quickest way to start programming in C# | <p>The dotnet command-line interface is the quickest way to start programming in C#.</p> | ||
</div> | </div> | ||
</div> | </div> | ||
Line 17: | Line 17: | ||
<div class="phd-slide"> | <div class="phd-slide"> | ||
<h2> | <h2>Setting UDev Rules</h2> | ||
<p> | <p> | ||
By default, Linux will not allow regular users to access physical hardware, as a security feature. This means that you must grant yourself root privileges via | |||
sudo to run Phidgets code. | |||
</p> | |||
< | <div class="phd-command-line"><code>sudo dotnet run</code></div> | ||
< | <p> | ||
To avoid having to use sudo every time, you can set up a rules file to allow it automatically using the vendor code for Phidget USB devices. Create a text file | |||
called <b>99-libphidget22.rules</b> containing the following line: | |||
</p> | |||
< | <div class="phd-command-line"><code>SUBSYSTEMS=="usb", ACTION=="add", ATTRS{idVendor}=="06c2", ATTRS{idProduct}=="00[3-a][0-f]", MODE="666"</code></div> | ||
< | <p> | ||
Mode 666 means every user has permission to read and write to the specified devices. Next, move this file to <b>/etc/udev/rules.d</b>. Now you can run code that | |||
uses Phidgets as a regular user without sudo. | |||
</p> | |||
</div> | </div> | ||
Line 39: | Line 48: | ||
<p>Usually, this will involve adding Microsoft packages to your repository and then installing dotnet via apt-get.</p> | <p>Usually, this will involve adding Microsoft packages to your repository and then installing dotnet via apt-get.</p> | ||
<p>If you are a Visual Studio Code user, you can get the '.NET Install Tool' extension instead of installing manually.</p> | |||
</div> | </div> | ||
Line 48: | Line 59: | ||
<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 | <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 70: | ||
<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 | 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> |