Difference between revisions of "Language - C Sharp macOS Mono"

From Phidgets Support
Jump to: navigation, search
Line 14: Line 14:
 
{{Language_-_C_Sharp_Intro|macOS|Mono}}
 
{{Language_-_C_Sharp_Intro|macOS|Mono}}
  
*You will also need to download and install [http://www.mono-project.com/download/ Mono] for macOS, if you haven't already. You can do this by entering the following command in the terminal:
+
#You will also need to download and install [http://www.mono-project.com/download/ Mono] for macOS, if you haven't already. You can do this by entering the following command in the terminal:
  
*Lastly, you will need a copy of [{{SERVER}}/downloads/phidget22/libraries/windows/Phidget22-windevel.zip Phidget22.NET.dll].
+
#Lastly, you will need a copy of [{{SERVER}}/downloads/phidget22/libraries/windows/Phidget22-windevel.zip Phidget22.NET.dll].
  
 
{{Finding Code Samples|C#|CSharp}}
 
{{Finding Code Samples|C#|CSharp}}

Revision as of 21:36, 16 October 2019

Language - C#

MacOS with Mono

Welcome to using Phidgets with C#! By using C#, you will have access to the complete Phidget22 API, including events.

Mono is an open-source programming environment that aims to make Microsoft .NET applications available across all operating systems.

Install Phidget Drivers for macOS

Before getting started with the guides below, ensure you have the following components installed on your machine:

  1. You will need the Phidgets macOS Drivers
  1. You will also need to download and install Mono for macOS, if you haven't already. You can do this by entering the following command in the terminal:
  1. Lastly, you will need a copy of Phidget22.NET.dll.

Finding Code Samples

To find the code sample to use for your Phidget, navigate to the Code Samples page and select your device from the drop-down menu.

CSharp sample code.jpg


Once you select your device, the code sample generator will give you a working code sample, and a selection of options to customize it to your needs.

Using the Code Samples

To use the code sample from the Code Samples page, you can click the Download Example button to download a CS file with the sample code.

CSharp Sample Code Download.png


Once you have the example, you can compile and run your code:

Setting up a New Project

Whether you are running our examples or adding Phidget functionality to an existing project, you'll need to configure your development environment to properly link the Phidget .NET library.

The easiest way to allow Mono to access the Phidgets .NET library is to place a copy of Phidget22.NET.dll in the same folder as your program.

Finally, you need to create a configuration file. Create a new file in the same directory and name it Phidget22.NET.dll.config. Copy the content below to the file.

  <configuration>
  <dllmap dll="phidget22.dll" target="/Library/Frameworks/Phidget22.framework/Versions/Current/Phidget22" />
  </configuration>

Your project directory should now look like this:


Csharp macos mono folder.png

Compile and Run

Once you are ready to run your program, open the Terminal and navigate to your project folder. Next, enter the following command:

mcs Program.cs -r:Phidget22.NET.dll

This will create an executable file called Program.exe. Type in the following command to run your program:

mono Program.exe

Success! The project is now using Phidgets.

What's Next?

Now that you have set up Phidgets to work with your programming environment, we recommend you read our guide on Phidget Programming Basics to learn the fundamentals of programming with Phidgets.Next Arrow.png