Template:PT3 CSHARP MAC DOTNET: Difference between revisions

From Phidgets Support
(Created page with "<div class="phd-slide-deck" data-deck="PT3_CSHARP_MAC_DOTNET"> <div class="phd-slide-deck-header"><h3>Language - C#</h3></div> <div class="phd-slides"> <div class="phd-slide"> <h2>MacOS 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_MAC_DOTNET/200x-/50/dotnet.jpg"></div> </div> <div class="phd-panel phd-flex-c...")
 
No edit summary
 
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# on MacOS and Linux.</p>
<p>The dotnet command-line interface is the quickest way to start programming in C#.</p>
</div>
</div>
</div>
</div>
Line 20: Line 20:


<p>
<p>
First, make sure you have the Phidgets Drivers for MacOS installed (see <span>[https://www.phidgets.com/docs/OS_-_macOS this page]</span> for installation
If you plan on using any USB Phidgets that use the HID stack, you'll need to install the
instructions).
<span>[https://www.phidgets.com/docs/OS_-_macOS Phidget drivers for MacOS]</span>. You can check which stack your USB Phidgets use by checking the 'USB Stack'
in the product specifications. If all of your Phidgets use the PHIDUSB stack, you can skip installing the drivers.
</p>
</p>


Line 30: Line 31:


<p>Click on the .pkg file once it's finished downloading, and follow the steps to install the .NET SDK.</p>
<p>Click on the .pkg file once it's finished downloading, and follow the steps to install the .NET SDK.</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>



Latest revision as of 21:06, 17 December 2024

MacOS 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#.

Installing dotnet CLI

If you plan on using any USB Phidgets that use the HID stack, you'll need to install the Phidget drivers for MacOS. You can check which stack your USB Phidgets use by checking the 'USB Stack' in the product specifications. If all of your Phidgets use the PHIDUSB stack, you can skip installing the drivers.

Next, visit Microsoft's .NET page and download .NET after confirming compatibility with your version of MacOS.

Click on the .pkg file once it's finished downloading, and follow the steps to install the .NET SDK.

If you are a Visual Studio Code user, you can get the '.NET Install Tool' extension instead of installing manually.

Setting up a New Project

Open Finder and go to Utilities -> Terminal. 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, type cd helloworld to enter the folder, and type:

dotnet run

If everything installed properly, the application will build and you'll see 'Hello, World!' printed in the terminal. You can open Program.cs using the text editor to see the code.

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 using this terminal command:

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.

«
»