Template:PT3 CSHARP MAC DOTNET
Contents
Language - C#
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# on MacOS and Linux.
Installing dotnet CLI
First, make sure you have the Phidgets Drivers for MacOS installed (see this page for installation instructions).
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.
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.