<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.phidgets.com/docs/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=192.168.3.183</id>
	<title>Phidgets Support - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://www.phidgets.com/docs/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=192.168.3.183"/>
	<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/Special:Contributions/192.168.3.183"/>
	<updated>2026-09-24T04:46:08Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.8</generator>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Visual_Basic&amp;diff=19957</id>
		<title>Language - Visual Basic</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Visual_Basic&amp;diff=19957"/>
		<updated>2012-05-23T20:34:18Z</updated>

		<summary type="html">&lt;p&gt;192.168.3.183: /* Use Our Examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-Visual Basic Net.png|64x64px|link=|alt=]]|Visual Basic .NET, developed by [http://www.microsoft.com Microsoft] is a modern object oriented programming language and the successor to [[Language - Visual Basic 6.0 | Visual Basic 6.0]].}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|Visual Basic .NET|the complete Phidget API, including events|all Phidget devices.|the .NET or Mono framework. Both of the frameworks are supported on Windows. For Linux and OS X, only the Mono framework can be used. We provide instructions on how to set up your environment/compilers for [[#Visual Studio 2005/2008/2010 | Visual Studio 2005/2008/2010]], [[#Visual Studio 2003 | Visual Studio 2003]], [[#MonoDevelop | MonoDevelop]] and the [[#Mono | Mono command line compilers]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
{{QuickDownloads|Visual Basic .NET|&lt;br /&gt;
{{APIQuickDownloads|http://www.phidgets.com/documentation/Phidget21.NET.zip .NET}}|&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/VBNET.zip|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|http://www.phidgets.com/downloads/libraries/phidget21-x86.zip|.NET Framework Files|}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with Visual Basic .NET==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
Visual Basic .NET programs on Windows depend on the following files, which the installers above put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
You will also need one of the following two files, depending on the .NET framework version you are targeting:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;2.0&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET1.1.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.1&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt;. Your compiler has to know where this file is. By default, is is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
You can optionally install the following files:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.XML}}&amp;lt;/b&amp;gt; provides the IntelliSense in-line documentation for the .NET library in Visual Studio/MonoDevelop. This documentation is also visible in the Object Browser in Visual Studio. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Policy.2.1.Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the policy assembly for {{Code|Phidget21.NET.dll}}. Our installer places this file in the Global Assembly Cache(GAC) directory. It directs any programs compiled against version 2.1.0 or higher of {{Code|Phidget21.NET.dll}} to use the most recent installed version. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the five [http://www.phidgets.com/downloads/libraries/Phidget21-windevel.zip files].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly environment-specific, so we include instructions for [[#Visual Studio 2005/2008/2010 | Visual Studio 2005/2008/2010]], [[#Visual Studio 2003 | Visual Studio 2003]], [[#MonoDevelop | MonoDevelop]] and the [[#Mono | Mono command line compiler]].&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2005/2008/2010===&lt;br /&gt;
&lt;br /&gt;
Microsoft makes free versions of Visual Studio available known as Express Editions.  The Express editions are suitable for most applications, but are limited in features for more complex applications. Please see [http://www.microsoft.com/visualstudio Microsoft Visual Studio] for more information.&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Please start by downloading the [http://www.phidgets.com/downloads/examples/VBNET.zip examples] and unpack them into a folder.  While these examples were written in Visual Studio 2005 and Visual Studio 2008, Visual Studio 2010 will easily open and upgrade them with the Visual Studio Conversion Wizard.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Conversion Wizard.PNG|link=|alt=Conversion Wizard]]&lt;br /&gt;
&lt;br /&gt;
To load all projects in Visual Studio, go to File &amp;amp;rarr; Open &amp;amp;rarr; Project, and open {{Code|AllExamples/AllExamples.sln}} or {{Code|AllExamples/AllExamples_vs2008.sln}} for Visual Studio 2005 and 2008, respectively.&lt;br /&gt;
&lt;br /&gt;
This will load all of the examples available for Visual Basic .NET, and then you can set your main project to be the HelloWorld project that will work with any Phidget board.  Or you can choose the example that matches your device.  {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Click on Debug &amp;amp;rarr; Start Debugging. Please note that the projects, by default try to find the {{Code|Phidget21.NET.dll}} in {{Code|C:\Program Files\Phidgets}}. If you have it installed in another location, please change the path to the file&#039;s location accordingly. If you are receiving an error message regarding that the type Phidget is not defined, please re-add the reference to {{Code|Phidget21.NET.dll}}. Please see the [[#Write Your Own Code | Write Your Own Code ]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:VBNET VS2005 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
Once you have the Visual Basic .NET examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your environment to properly link the Phidget .NET library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual Basic .NET Console Application project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:VBNET VS2005 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
[[File:VBNET VS2005 Add Reference 1.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Under the .NET tab, select {{Code|Phidget21.NET.dll}}.&lt;br /&gt;
If you used our installer, these files are installed in {{Code|C:\Program Files\Phidgets}}, by default. If it does not appear in this list, then you can browse to the Phidget Framework installation directory and add the file.&lt;br /&gt;
&lt;br /&gt;
[[File:VBNET VS2005 Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching ]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2003===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
As the Visual Basic .NET examples were written in Visual Studio 2005 and 2008, Visual Studio 2003 is not able to open the examples. Furthermore, it will be difficult to import the examples into your Visual Studio 2003 project as you will need to recreate the GUI components. Fortunately, taking a look at the source code will give you valuable programming insight. We have a [[#Follow the Examples|teaching ]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget .NET library. &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual Basic Console Application project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:VBNET VS2003 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
[[File:VBNET VS2003 Add Reference 1.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Under the .NET tab, select {{Code|Phidget21.NET1.1.dll}}.&lt;br /&gt;
If you used our installer, these files are installed in {{Code|C:\Program Files\Phidgets}}, by default. If it does not appear in this list, then you can browse to the Phidget Framework installation directory and add the file.&lt;br /&gt;
&lt;br /&gt;
[[File:VBNET VS2003 Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget21 function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The [[#Follow the Examples|teaching ]] section also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Mono===&lt;br /&gt;
&lt;br /&gt;
This section will provide instructions on how to compile using the {{Code|vbnc}} compiler.&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
We do not have Visual Basic .NET examples for the Mono framework. Fortunately, you can take a look at the source code for our [http://www.phidgets.com/downloads/examples/CSharp.zip Visual Studio 2005 and 2008 examples] for valuable programming insight. We have a [[#Follow the Examples|teaching ]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your compiler to properly link the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
Place the {{Code|Phidget21.NET.dll}} in the same directory as your source code. &lt;br /&gt;
To compile and build an executable, run:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
vbnc /out:example.exe /r:Phidget21.NET.dll Example.vb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Afterwards, you will have an executable named {{Code|example.exe}} that you can run. Type the following to run the program:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
mono example.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The [[#Follow the Examples|teaching]] section also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===MonoDevelop===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Download the [http://www.phidgets.com/downloads/examples/VBNET.zip examples] and unpack them into a folder. Here, you can find example programs for all the devices, as well as a HelloWorld program that will run with any Phidget. &lt;br /&gt;
&lt;br /&gt;
These examples were written in Visual Studio 2005 and 2008, but they are also compatible with MonoDevelop. Please note that the examples are only designed to be run under the .NET framework. The examples are not compatible with the Mono framework. Despite this, if you are using the Mono framework, you can use the code within the examples for valuable programming insight. &lt;br /&gt;
&lt;br /&gt;
The rest of this section will explain the steps needed to run our examples under the .NET framework. To load all projects in MonoDevelop, go to File &amp;amp;rarr; Open, and open {{Code|AllExamples/AllExamples.sln}}&lt;br /&gt;
&lt;br /&gt;
This will load all of the examples available for Visual Basic .NET, and then you can set your main project to be the one that matches your device.  {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
[[File:VBNET Win MonoDevelop Startup Project.PNG|link=|alt=Start Up Project]]&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Right click the project, and click on {{Code|Run With}} and select the Microsoft .NET framework. Please note that the projects, by default try to find the {{Code|Phidget21.NET.dll}} in the {{Code|C\Program Files\Phidgets}}. If you have it installed in another location, please change the path to the file&#039;s location accordingly. If you are receiving an error message regarding that the Phidget is not defined, please re-add the reference to {{Code|Phidget21.NET.dll}}. Please see the [[#Write Your Own Code 4 | Write Your Own Code]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:VBNET Win MonoDevelop Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
Once you have the Visual Basic .NET examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your  development environment to properly link the Phidget .NET library. To begin:&lt;br /&gt;
&lt;br /&gt;
1. Create a new Visual Basic .NET console project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:VBNET Win MonoDevelop New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library. &lt;br /&gt;
&lt;br /&gt;
[[File:VBNET Win MonoDevelop Add Reference 1.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Select {{Code|Phidget21.NET.dll}}. If you used our installer, by default, this file is placed in {{Code|C:\Program Files\Phidgets}}. If it is in another location, please change the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:VBNET Win MonoDevelop Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
Visual Basic .NET has excellent support on OS X through the Mono framework. &lt;br /&gt;
&lt;br /&gt;
The first step in using Visual Basic .NET on Mac is to install the Phidget libraries.  Compile and install them as explained on the [[OS - OS X]] page, which also describes the different Phidget files, their installed locations, and their roles....  &lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
 &lt;br /&gt;
The first thing you are going to need to do is install [http://www.mono-project.com/Main_Page Mono] (Note that Mono is only available for Intel Macs and not PowerPC).  You will need both the SDK and the runtime.  &lt;br /&gt;
&lt;br /&gt;
Then, you will need the Phidget .NET libraries.  These are part of the Windows library zip file download:&lt;br /&gt;
&lt;br /&gt;
* [http://www.phidgets.com/downloads/libraries/Phidget21-windevel.zip Phidget Windows Library Zip File]&lt;br /&gt;
&lt;br /&gt;
Extract the library zip file.  Descriptions for the files are available on the [[OS - Windows]] page, but for now we only need the {{Code|Phidget21.NET.dll}} file to run the Phidget VB.NET examples in Mono.  So remember where you unzipped these Windows libraries - you will need to copy the {{Code|Phidget21.NET.dll}} file into your example directory shortly.&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to download and extract the Phidget Visual Basic .NET Examples (not the ones for .NET Compact):&lt;br /&gt;
&lt;br /&gt;
* [http://www.phidgets.com/downloads/examples/VBNET.zip Visual Basic .NET Examples for Windows]&lt;br /&gt;
&lt;br /&gt;
One more thing needs to be done before you can compile and run the examples.  You need to set up a special configuration file so that Mono knows where to find the phidget21.dll.  Since Mac does not use dll&#039;s you need to redirect it to the appropriate file.  Create a new file in the same directory as the example you wish to compile and name it &amp;lt;code&amp;gt;Phidget21.NET.dll.config&amp;lt;/code&amp;gt;.  Put the following into the file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=xml&amp;gt;&lt;br /&gt;
&amp;lt;configuration&amp;gt;&lt;br /&gt;
	&amp;lt;dllmap dll=&amp;quot;phidget21.dll&amp;quot; target=&amp;quot;/Library/Frameworks/Phidget21.framework/Versions/Current/Phidget21&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/configuration&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All that is left is to compile and run the code.  When compiling, you need to link to the Phidget library. As the Phidget21.NET file is an &amp;quot;additional assembly&amp;quot; in VB.NET/Mono, you can link to the assembly using the {{Code|-r}} &amp;quot;reference&amp;quot; switch:&lt;br /&gt;
&lt;br /&gt;
To check that your Mac, Phidget, and Mono setup is all working together, you&#039;ll want to run the Visual Basic (VB) examples.  You&#039;ll probably want to start with the Hello World VB example.  Alternatively, you could find the source code for your device. {{Template:FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
All of the .NET examples are much larger projects through Visual Studio, so you&#039;ll need to dig around within the project and find the source code and compile only that source code using Mono.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s say you&#039;re running the Hello World example.  The source code for the example is in the directory: &lt;br /&gt;
&lt;br /&gt;
:{{Code|VBNET/}} &amp;amp;rarr; {{Code|Hello World/}} &amp;amp;rarr; {{Code|Module1.vb}}&lt;br /&gt;
&lt;br /&gt;
Other examples will be in directories named appropriately for their software object name, rather than {{Code|Hello World}}.  Once you have found the example you want to run, copy the {{Code|Phidget21.NET.dll}} file that you unzipped earlier into that example directory where the {{Code|Module1.vb}} file is.  &lt;br /&gt;
&lt;br /&gt;
Then, compile the code.  When compiling, you need to link to the Phidget library. As the Phidget21.NET file is an &amp;quot;additional assembly&amp;quot; in Visual Basic/Mono, you can link to the assembly using the {{Code|-r}} &amp;quot;reference&amp;quot; switch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
vbnc Module1.vb -r:Phidget21.NET.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will compile a {{Code|*.exe}} file - in this case, {{Code|Module1.exe}}.  This you can then run under Mono:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo mono Program.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember that the {{Code|sudo}} is needed unless you have your [[OS - Linux#Setting udev Rules|udev rules set on your Linux system]].&lt;br /&gt;
&lt;br /&gt;
If you will be compiling with an IDE such as GTK# or MonoDevelop, we don&#039;t have explicit instructions by IDE for Linux.  However, you will probably find the [[#MonoDevelop | MonoDevelop]] section in the Windows portion above useful.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any Visual Basic code on OS X, such as within a text editor. In your .vb source code file, you must include a reference to the Phidget software object.  In the case of a Phidget interface kit device, this would look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=vbnet&amp;gt;&lt;br /&gt;
Public Class Form1&lt;br /&gt;
   &#039;The Phidget object declaration&lt;br /&gt;
		&lt;br /&gt;
   Dim WithEvents ifKit As Phidgets.InterfaceKit&lt;br /&gt;
		&lt;br /&gt;
   &#039;... Form1_Load and Form1_OnClosing here&lt;br /&gt;
End Class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other devices, check the API for your device on our webpage for the software object name, and the [http://www.phidgets.com/documentation/Phidget21.NET.zip API for .NET] for the specific syntax to use.  Then, you would compile your completed VB code the same way as the examples above.&lt;br /&gt;
&lt;br /&gt;
Mono also has a few different IDEs which you can use to develop code, and these are especially useful if you are doing GUI development.  We provide instructions for MonoDevelop - one such IDE - being used [[#MonoDevelop|under Windows]].&lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching section]] to help you follow the provided VB examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
Visual Basic .NET has support on Linux through the Mono framework.  &lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
 &lt;br /&gt;
The first step in using Visual Basic .NET with Phidgets on Linux is to install Mono.  Although you probably have already done this if you&#039;re a Visual Basic .NET programmer, you want to make sure you have all of the packages you&#039;ll need.  Try:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo apt-get mono-complete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Visual Basic Mono framework also requires the Visual Basic .NET compiler, {{Code|vbnc}}.  This can be installed via another Mono package:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo apt-get install mono-vbnc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to install the main Phidget Libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
Then, you will need the Phidget .NET libraries.  These are part of the Windows library zip file download:&lt;br /&gt;
&lt;br /&gt;
* [http://www.phidgets.com/downloads/libraries/Phidget21-windevel.zip Phidget Windows Library Zip File]&lt;br /&gt;
&lt;br /&gt;
Extract the library zip file.  Descriptions for the files are available on the [[OS - Windows]] page, but for now we only need the {{Code|Phidget21.NET.dll}} file to run the Phidget Visual Basic examples in Mono.  So remember where you unzipped these Windows libraries - you will need to copy the {{Code|Phidget21.NET.dll}} file into your example directory shortly.&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to download and extract the Phidget Visual Basic .NET Examples (not the ones for .NET Compact):&lt;br /&gt;
&lt;br /&gt;
* [http://www.phidgets.com/downloads/examples/VBNET.zip Visual Basic .NET Examples for Windows]&lt;br /&gt;
&lt;br /&gt;
To check that your Linux, Phidget, and Mono setup is all working together, you&#039;ll want to run the Visual Basic (VB) examples.  You&#039;ll probably want to start with the Hello World VB example.  Alternatively, you could find the source code for your device. {{Template:FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
All of the .NET examples are much larger projects through Visual Studio, so you&#039;ll need to dig around within the project and find the source code and compile only that source code using Mono.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s say you&#039;re running the Hello World example.  The source code for the example is in the directory: &lt;br /&gt;
&lt;br /&gt;
:{{Code|VBNET/}} &amp;amp;rarr; {{Code|Hello World/}} &amp;amp;rarr; {{Code|Module1.vb}}&lt;br /&gt;
&lt;br /&gt;
Other examples will be in directories named appropriately for their software object name, rather than {{Code|Hello World}}.  Once you have found the example you want to run, copy the {{Code|Phidget21.NET.dll}} file that you unzipped earlier into that example directory where the {{Code|Module1.vb}} file is.  &lt;br /&gt;
&lt;br /&gt;
Then, compile the code.  When compiling, you need to link to the Phidget library. As the Phidget21.NET file is an &amp;quot;additional assembly&amp;quot; in Visual Basic/Mono, you can link to the assembly using the {{Code|-r}} &amp;quot;reference&amp;quot; switch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
vbnc Module1.vb -r:Phidget21.NET.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will compile a {{Code|*.exe}} file - in this case, {{Code|Module1.exe}}.  This you can then run under Mono:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo mono Program.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember that the {{Code|sudo}} is needed unless you have your [[OS - Linux#Setting udev Rules|udev rules set on your Linux system]].&lt;br /&gt;
&lt;br /&gt;
If you will be compiling with an IDE such as GTK# or MonoDevelop, we don&#039;t have explicit instructions by IDE for Linux.  However, you will probably find the [[#MonoDevelop | MonoDevelop]] section in the Windows portion above useful.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any Visual Basic code on Linux, such as within a text editor like Emacs, Vi, Gedit, or Kate. In your .vb source code file, you must include a reference to the Phidget software object.  In the case of a Phidget interface kit device, this would look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=vbnet&amp;gt;&lt;br /&gt;
Public Class Form1&lt;br /&gt;
   &#039;The Phidget object declaration&lt;br /&gt;
		&lt;br /&gt;
   Dim WithEvents ifKit As Phidgets.InterfaceKit&lt;br /&gt;
		&lt;br /&gt;
   &#039;... Form1_Load and Form1_OnClosing here&lt;br /&gt;
End Class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other devices, check the API for your device on our webpage for the software object name, and the [http://www.phidgets.com/documentation/Phidget21.NET.zip API for .NET] for the specific syntax to use.  Then, you would compile your completed VB code the same way as the examples above.&lt;br /&gt;
&lt;br /&gt;
Mono also has a few different IDEs which you can use to develop code, and these are especially useful if you are doing GUI development.  We provide instructions for MonoDevelop - one such IDE - being used [[#MonoDevelop|under Windows]].&lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching section]] to help you follow the provided VB examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  This teaching section has resources for you to learn from the examples and write your own.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing Visual Basic .NET code will be our .NET API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in .NET|[http://www.phidgets.com/documentation/Phidget21.NET.zip .NET API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In Visual Basic .NET, you can name these &#039;&#039;&#039;event&#039;&#039;&#039; functions whatever you like, although you must catch the events by name in the &amp;quot;Handles&amp;quot; portion of the function declaration.  The &amp;quot;Handles&amp;quot; portion of the function hooks them into the actual events when they occur. See our examples for details.&amp;lt;br&amp;gt; &lt;br /&gt;
In the example code, the event functions common to all Phidgets are called things like &#039;&#039;&#039;AttachHandler()&#039;&#039;&#039; and &#039;&#039;&#039;DetachHandler()&#039;&#039;&#039;, etc.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Some event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.&lt;br /&gt;
Other functions are given in the device-specific examples to show you more detail on using your Phidget.  &lt;br /&gt;
|Creating a Phidget software object in Visual Basic .NET is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating a {{Code|Spatial}} object.  The examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The object provides device specific methods and properties which are available from the API for your specific Phidget.|&lt;br /&gt;
[http://www.phidgets.com/documentation/Phidget21.NET.zip .NET API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
Specific calls in Visual Basic (VB) .NET will differ in syntax from those on the [[General Phidget Programming]] page, but the concepts stay the same.  &lt;br /&gt;
&lt;br /&gt;
It may help to have the [[General Phidget Programming]] page and this section open at the same time, because they parallel each other and you can refer to the VB .NET syntax.  However, &#039;&#039;many&#039;&#039; additional concepts are covered on the General Phidget Programming page on a high level, such as using multiple Phidgets, handling errors, and different styles of programming.&lt;br /&gt;
&lt;br /&gt;
====Step One: Initialize and Open====&lt;br /&gt;
&lt;br /&gt;
The open() function opens the software object, but not hardware. So, it is not a guarantee you can use the Phidget immediately.&lt;br /&gt;
&lt;br /&gt;
The different types of open can be used with parameters to try and get the first device it can find, open based on its serial number, or even open across the network. The API manual lists and [[General Phidget Programming]] discusses all of the available modes that open provides.&lt;br /&gt;
&lt;br /&gt;
For example, if we were using an Interface Kit Phidget board as our device, the create and open calls would look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=vbnet&amp;gt;&lt;br /&gt;
ifKit = New Phidgets.InterfaceKit&lt;br /&gt;
ifKit.open()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Two: Wait for Attachment (plugging in) of the Phidget====&lt;br /&gt;
&lt;br /&gt;
To use the Phidget, it must be plugged in (attached). We can handle this by using event driven programming and tracking the AttachEvents and DetachEvents, or we can handle this by calling waitForAttachment. This function works for any Phidget. WaitForAttachment will block indefinitely until a connection is made to the Phidget, or an optional timeout is exceeded.&lt;br /&gt;
&lt;br /&gt;
When combined in your initialization function with the initialization and open from above, the wait for attachment would look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=vbnet&amp;gt;&lt;br /&gt;
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)&lt;br /&gt;
Handles MyBase.Load&lt;br /&gt;
    ifKit = New Phidgets.InterfaceKit&lt;br /&gt;
    ifKit.open()&lt;br /&gt;
    ifKit.waitForAttachment(3000)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Three: Do Things with the Phidget====&lt;br /&gt;
&lt;br /&gt;
We recommend the use of event driven programming when working with Phidgets. In VB.NET we can hook an event handler into the event of a sensor changing on an Interface Kit board with the following code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=vbnet&amp;gt;&lt;br /&gt;
Private Sub ifKit_SensorChange(ByVal sender As Object, ByVal e As Phidgets.Events.SensorChangeEventArgs) Handles ifKit.SensorChange&lt;br /&gt;
    TextBox1.Text = &amp;quot;Index &amp;quot; + e.Index.ToString() + &amp;quot; Value: &amp;quot; + e.Value.ToString()&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With this function, the code inside ifKit_SensorChange will get executed every time the Phidget Interface Kit reports a change on one of its analog inputs. This is because it &amp;quot;Handles&amp;quot; the SensorChange event.  Some events such as Attach and Detach belong to the base Phidget object and thus are common to all types of Phidgets. &lt;br /&gt;
&lt;br /&gt;
Some values can be read and sent directly to the Phidget, simply use the instance members and properties. This is also how you would set properties on the Phidget such as the output state or&lt;br /&gt;
sensor sensitivity.  For example, obtaining the value of analog input (sensor) 0 on an Interface Kit board would be via:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=vbnet&amp;gt;&lt;br /&gt;
Dim val As Integer = ifKit.sensors(0).Value&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Four: Close and Delete====&lt;br /&gt;
&lt;br /&gt;
At the end of your program, unhook any events and call Application.DoEvents(). This will make sure there are no outstanding events being processed before calling close.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=vbnet&amp;gt;&lt;br /&gt;
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing&lt;br /&gt;
    RemoveHandler ifKit.SensorChange, AddressOf ifKit_SensorChange&lt;br /&gt;
    Application.DoEvents()&lt;br /&gt;
    ifKit.close()&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{MoreHowTos}}&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;complete&#039;&#039; set of functions you have available for all Phidgets can be found in the [http://www.phidgets.com/documentation/Phidget21.NET.zip .NET API].  You can also find more description on any device-specific function in the Device API page for your specific Phidget, which can be found on its product page on our [http://www.phidgets.com main website].&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
==={{ProblemSolution|All Operating Systems|The Phidgets.Events.ErrorEventHandler conflicts with System.IO.ErrorEventHandler.}}===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using Phidgets;&lt;br /&gt;
using Phidgets.Events;&lt;br /&gt;
...&lt;br /&gt;
spatial.Error += new ErrorEventHandler(spatial_Error);&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
void spatial_Error(object sender, ErrorEventArgs e){&lt;br /&gt;
   ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code produces the following errors:&lt;br /&gt;
&lt;br /&gt;
{{Code|&#039;ErrorEventHandler&#039; is an ambiguous reference between &#039;System.IO.ErrorEventHandler&#039; and &#039;Phidgets.Events.ErrorEventHandler&#039;}}.&lt;br /&gt;
&lt;br /&gt;
and&lt;br /&gt;
&lt;br /&gt;
{{Code|&#039;ErrorEventArgs&#039; is an ambiguous reference between &#039;System.IO.ErrorEventArgs&#039; and &#039;Phidgets.Events.ErrorEventArgs&#039;}}.&lt;br /&gt;
&lt;br /&gt;
The error is due to the {{Code|System.IO}} and {{Code|Phidgets.Events}} namespaces both having a class called {{Code|ErrorEventHandler}}.&lt;br /&gt;
&lt;br /&gt;
To get around this issue, use the fully qualified namespace when referring to the {{Code|ErrorEventHandler}} and {{Code|ErrorEventArgs}} classes:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using Phidgets;&lt;br /&gt;
using Phidgets.Events;&lt;br /&gt;
...&lt;br /&gt;
spatial.Error += new Phidgets.Events.ErrorEventHandler(spatial_Error);&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
void spatial_Error(object sender, Phidgets.Events.ErrorEventArgs e){&lt;br /&gt;
   ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>192.168.3.183</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Visual_Basic&amp;diff=19956</id>
		<title>Language - Visual Basic</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Visual_Basic&amp;diff=19956"/>
		<updated>2012-05-23T20:32:50Z</updated>

		<summary type="html">&lt;p&gt;192.168.3.183: /* OS X */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-Visual Basic Net.png|64x64px|link=|alt=]]|Visual Basic .NET, developed by [http://www.microsoft.com Microsoft] is a modern object oriented programming language and the successor to [[Language - Visual Basic 6.0 | Visual Basic 6.0]].}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|Visual Basic .NET|the complete Phidget API, including events|all Phidget devices.|the .NET or Mono framework. Both of the frameworks are supported on Windows. For Linux and OS X, only the Mono framework can be used. We provide instructions on how to set up your environment/compilers for [[#Visual Studio 2005/2008/2010 | Visual Studio 2005/2008/2010]], [[#Visual Studio 2003 | Visual Studio 2003]], [[#MonoDevelop | MonoDevelop]] and the [[#Mono | Mono command line compilers]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
{{QuickDownloads|Visual Basic .NET|&lt;br /&gt;
{{APIQuickDownloads|http://www.phidgets.com/documentation/Phidget21.NET.zip .NET}}|&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/VBNET.zip|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|http://www.phidgets.com/downloads/libraries/phidget21-x86.zip|.NET Framework Files|}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with Visual Basic .NET==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
Visual Basic .NET programs on Windows depend on the following files, which the installers above put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
You will also need one of the following two files, depending on the .NET framework version you are targeting:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;2.0&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET1.1.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.1&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt;. Your compiler has to know where this file is. By default, is is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
You can optionally install the following files:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.XML}}&amp;lt;/b&amp;gt; provides the IntelliSense in-line documentation for the .NET library in Visual Studio/MonoDevelop. This documentation is also visible in the Object Browser in Visual Studio. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Policy.2.1.Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the policy assembly for {{Code|Phidget21.NET.dll}}. Our installer places this file in the Global Assembly Cache(GAC) directory. It directs any programs compiled against version 2.1.0 or higher of {{Code|Phidget21.NET.dll}} to use the most recent installed version. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the five [http://www.phidgets.com/downloads/libraries/Phidget21-windevel.zip files].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly environment-specific, so we include instructions for [[#Visual Studio 2005/2008/2010 | Visual Studio 2005/2008/2010]], [[#Visual Studio 2003 | Visual Studio 2003]], [[#MonoDevelop | MonoDevelop]] and the [[#Mono | Mono command line compiler]].&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2005/2008/2010===&lt;br /&gt;
&lt;br /&gt;
Microsoft makes free versions of Visual Studio available known as Express Editions.  The Express editions are suitable for most applications, but are limited in features for more complex applications. Please see [http://www.microsoft.com/visualstudio Microsoft Visual Studio] for more information.&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Please start by downloading the [http://www.phidgets.com/downloads/examples/VBNET.zip examples] and unpack them into a folder.  While these examples were written in Visual Studio 2005 and Visual Studio 2008, Visual Studio 2010 will easily open and upgrade them with the Visual Studio Conversion Wizard.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Conversion Wizard.PNG|link=|alt=Conversion Wizard]]&lt;br /&gt;
&lt;br /&gt;
To load all projects in Visual Studio, go to File &amp;amp;rarr; Open &amp;amp;rarr; Project, and open {{Code|AllExamples/AllExamples.sln}} or {{Code|AllExamples/AllExamples_vs2008.sln}} for Visual Studio 2005 and 2008, respectively.&lt;br /&gt;
&lt;br /&gt;
This will load all of the examples available for Visual Basic .NET, and then you can set your main project to be the HelloWorld project that will work with any Phidget board.  Or you can choose the example that matches your device.  {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Click on Debug &amp;amp;rarr; Start Debugging. Please note that the projects, by default try to find the {{Code|Phidget21.NET.dll}} in {{Code|C:\Program Files\Phidgets}}. If you have it installed in another location, please change the path to the file&#039;s location accordingly. If you are receiving an error message regarding that the type Phidget is not defined, please re-add the reference to {{Code|Phidget21.NET.dll}}. Please see the [[#Write Your Own Code | Write Your Own Code ]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:VBNET VS2005 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
Once you have the Visual Basic .NET examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your environment to properly link the Phidget .NET library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual Basic .NET Console Application project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:VBNET VS2005 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
[[File:VBNET VS2005 Add Reference 1.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Under the .NET tab, select {{Code|Phidget21.NET.dll}}.&lt;br /&gt;
If you used our installer, these files are installed in {{Code|C:\Program Files\Phidgets}}, by default. If it does not appear in this list, then you can browse to the Phidget Framework installation directory and add the file.&lt;br /&gt;
&lt;br /&gt;
[[File:VBNET VS2005 Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching ]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2003===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
As the Visual Basic .NET examples were written in Visual Studio 2005 and 2008, Visual Studio 2003 is not able to open the examples. Furthermore, it will be difficult to import the examples into your Visual Studio 2003 project as you will need to recreate the GUI components. Fortunately, taking a look at the source code will give you valuable programming insight. We have a [[#Follow the Examples|teaching ]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget .NET library. &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual Basic Console Application project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:VBNET VS2003 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
[[File:VBNET VS2003 Add Reference 1.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Under the .NET tab, select {{Code|Phidget21.NET1.1.dll}}.&lt;br /&gt;
If you used our installer, these files are installed in {{Code|C:\Program Files\Phidgets}}, by default. If it does not appear in this list, then you can browse to the Phidget Framework installation directory and add the file.&lt;br /&gt;
&lt;br /&gt;
[[File:VBNET VS2003 Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget21 function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The [[#Follow the Examples|teaching ]] section also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Mono===&lt;br /&gt;
&lt;br /&gt;
This section will provide instructions on how to compile using the {{Code|vbnc}} compiler.&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
We do not have Visual Basic .NET examples for the Mono framework. Fortunately, you can take a look at the source code for our [http://www.phidgets.com/downloads/examples/CSharp.zip Visual Studio 2005 and 2008 examples] for valuable programming insight. We have a [[#Follow the Examples|teaching ]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your compiler to properly link the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
Place the {{Code|Phidget21.NET.dll}} in the same directory as your source code. &lt;br /&gt;
To compile and build an executable, run:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
vbnc /out:example.exe /r:Phidget21.NET.dll Example.vb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Afterwards, you will have an executable named {{Code|example.exe}} that you can run. Type the following to run the program:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
mono example.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The [[#Follow the Examples|teaching]] section also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===MonoDevelop===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Download the [http://www.phidgets.com/downloads/examples/VBNET.zip examples] and unpack them into a folder. Here, you can find example programs for all the devices, as well as a HelloWorld program that will run with any Phidget. &lt;br /&gt;
&lt;br /&gt;
These examples were written in Visual Studio 2005 and 2008, but they are also compatible with MonoDevelop. Please note that the examples are only designed to be run under the .NET framework. The examples are not compatible with the Mono framework. Despite this, if you are using the Mono framework, you can use the code within the examples for valuable programming insight. &lt;br /&gt;
&lt;br /&gt;
The rest of this section will explain the steps needed to run our examples under the .NET framework. To load all projects in MonoDevelop, go to File &amp;amp;rarr; Open, and open {{Code|AllExamples/AllExamples.sln}}&lt;br /&gt;
&lt;br /&gt;
This will load all of the examples available for Visual Basic .NET, and then you can set your main project to be the one that matches your device.  {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
[[File:VBNET Win MonoDevelop Startup Project.PNG|link=|alt=Start Up Project]]&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Right click the project, and click on {{Code|Run With}} and select the Microsoft .NET framework. Please note that the projects, by default try to find the {{Code|Phidget21.NET.dll}} in the {{Code|C\Program Files\Phidgets}}. If you have it installed in another location, please change the path to the file&#039;s location accordingly. If you are receiving an error message regarding that the Phidget is not defined, please re-add the reference to {{Code|Phidget21.NET.dll}}. Please see the [[#Write Your Own Code 4 | Write Your Own Code]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:VBNET Win MonoDevelop Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
Once you have the Visual Basic .NET examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your  development environment to properly link the Phidget .NET library. To begin:&lt;br /&gt;
&lt;br /&gt;
1. Create a new Visual Basic .NET console project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:VBNET Win MonoDevelop New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library. &lt;br /&gt;
&lt;br /&gt;
[[File:VBNET Win MonoDevelop Add Reference 1.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Select {{Code|Phidget21.NET.dll}}. If you used our installer, by default, this file is placed in {{Code|C:\Program Files\Phidgets}}. If it is in another location, please change the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:VBNET Win MonoDevelop Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
Visual Basic .NET has excellent support on OS X through the Mono framework. &lt;br /&gt;
&lt;br /&gt;
The first step in using Visual Basic .NET on Mac is to install the Phidget libraries.  Compile and install them as explained on the [[OS - OS X]] page, which also describes the different Phidget files, their installed locations, and their roles....  &lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
 &lt;br /&gt;
The first thing you are going to need to do is install [http://www.mono-project.com/Main_Page Mono] (Note that Mono is only available for Intel Macs and not PowerPC).  You will need both the SDK and the runtime.  &lt;br /&gt;
&lt;br /&gt;
Then, you will need the Phidget .NET libraries.  These are part of the Windows library zip file download:&lt;br /&gt;
&lt;br /&gt;
* [http://www.phidgets.com/downloads/libraries/Phidget21-windevel.zip Phidget Windows Library Zip File]&lt;br /&gt;
&lt;br /&gt;
Extract the library zip file.  Descriptions for the files are available on the [[OS - Windows]] page, but for now we only need the {{Code|Phidget21.NET.dll}} file to run the Phidget C# examples in Mono.  So remember where you unzipped these Windows libraries - you will need to copy the {{Code|Phidget21.NET.dll}} file into your example directory shortly.&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to download and extract the Phidget Visual Basic .NET Examples (not the ones for .NET Compact):&lt;br /&gt;
&lt;br /&gt;
* [http://www.phidgets.com/downloads/examples/VBNET.zip Visual Basic .NET Examples for Windows]&lt;br /&gt;
&lt;br /&gt;
One more thing needs to be done before you can compile and run the examples.  You need to set up a special configuration file so that Mono knows where to find the phidget21.dll.  Since Mac does not use dll&#039;s you need to redirect it to the appropriate file.  Create a new file in the same directory as the example you wish to compile and name it &amp;lt;code&amp;gt;Phidget21.NET.dll.config&amp;lt;/code&amp;gt;.  Put the following into the file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=xml&amp;gt;&lt;br /&gt;
&amp;lt;configuration&amp;gt;&lt;br /&gt;
	&amp;lt;dllmap dll=&amp;quot;phidget21.dll&amp;quot; target=&amp;quot;/Library/Frameworks/Phidget21.framework/Versions/Current/Phidget21&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/configuration&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All that is left is to compile and run the code.  When compiling, you need to link to the Phidget library. As the Phidget21.NET file is an &amp;quot;additional assembly&amp;quot; in VB.NET/Mono, you can link to the assembly using the {{Code|-r}} &amp;quot;reference&amp;quot; switch:&lt;br /&gt;
&lt;br /&gt;
To check that your Mac, Phidget, and Mono setup is all working together, you&#039;ll want to run the Visual Basic (VB) examples.  You&#039;ll probably want to start with the Hello World VB example.  Alternatively, you could find the source code for your device. {{Template:FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
All of the .NET examples are much larger projects through Visual Studio, so you&#039;ll need to dig around within the project and find the source code and compile only that source code using Mono.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s say you&#039;re running the Hello World example.  The source code for the example is in the directory: &lt;br /&gt;
&lt;br /&gt;
:{{Code|VBNET/}} &amp;amp;rarr; {{Code|Hello World/}} &amp;amp;rarr; {{Code|Module1.vb}}&lt;br /&gt;
&lt;br /&gt;
Other examples will be in directories named appropriately for their software object name, rather than {{Code|Hello World}}.  Once you have found the example you want to run, copy the {{Code|Phidget21.NET.dll}} file that you unzipped earlier into that example directory where the {{Code|Module1.vb}} file is.  &lt;br /&gt;
&lt;br /&gt;
Then, compile the code.  When compiling, you need to link to the Phidget library. As the Phidget21.NET file is an &amp;quot;additional assembly&amp;quot; in Visual Basic/Mono, you can link to the assembly using the {{Code|-r}} &amp;quot;reference&amp;quot; switch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
vbnc Module1.vb -r:Phidget21.NET.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will compile a {{Code|*.exe}} file - in this case, {{Code|Module1.exe}}.  This you can then run under Mono:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo mono Program.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember that the {{Code|sudo}} is needed unless you have your [[OS - Linux#Setting udev Rules|udev rules set on your Linux system]].&lt;br /&gt;
&lt;br /&gt;
If you will be compiling with an IDE such as GTK# or MonoDevelop, we don&#039;t have explicit instructions by IDE for Linux.  However, you will probably find the [[#MonoDevelop | MonoDevelop]] section in the Windows portion above useful.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any Visual Basic code on OS X, such as within a text editor. In your .vb source code file, you must include a reference to the Phidget software object.  In the case of a Phidget interface kit device, this would look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=vbnet&amp;gt;&lt;br /&gt;
Public Class Form1&lt;br /&gt;
   &#039;The Phidget object declaration&lt;br /&gt;
		&lt;br /&gt;
   Dim WithEvents ifKit As Phidgets.InterfaceKit&lt;br /&gt;
		&lt;br /&gt;
   &#039;... Form1_Load and Form1_OnClosing here&lt;br /&gt;
End Class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other devices, check the API for your device on our webpage for the software object name, and the [http://www.phidgets.com/documentation/Phidget21.NET.zip API for .NET] for the specific syntax to use.  Then, you would compile your completed VB code the same way as the examples above.&lt;br /&gt;
&lt;br /&gt;
Mono also has a few different IDEs which you can use to develop code, and these are especially useful if you are doing GUI development.  We provide instructions for MonoDevelop - one such IDE - being used [[#MonoDevelop|under Windows]].&lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching section]] to help you follow the provided VB examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
Visual Basic .NET has support on Linux through the Mono framework.  &lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
 &lt;br /&gt;
The first step in using Visual Basic .NET with Phidgets on Linux is to install Mono.  Although you probably have already done this if you&#039;re a Visual Basic .NET programmer, you want to make sure you have all of the packages you&#039;ll need.  Try:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo apt-get mono-complete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Visual Basic Mono framework also requires the Visual Basic .NET compiler, {{Code|vbnc}}.  This can be installed via another Mono package:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo apt-get install mono-vbnc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to install the main Phidget Libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
Then, you will need the Phidget .NET libraries.  These are part of the Windows library zip file download:&lt;br /&gt;
&lt;br /&gt;
* [http://www.phidgets.com/downloads/libraries/Phidget21-windevel.zip Phidget Windows Library Zip File]&lt;br /&gt;
&lt;br /&gt;
Extract the library zip file.  Descriptions for the files are available on the [[OS - Windows]] page, but for now we only need the {{Code|Phidget21.NET.dll}} file to run the Phidget Visual Basic examples in Mono.  So remember where you unzipped these Windows libraries - you will need to copy the {{Code|Phidget21.NET.dll}} file into your example directory shortly.&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to download and extract the Phidget Visual Basic .NET Examples (not the ones for .NET Compact):&lt;br /&gt;
&lt;br /&gt;
* [http://www.phidgets.com/downloads/examples/VBNET.zip Visual Basic .NET Examples for Windows]&lt;br /&gt;
&lt;br /&gt;
To check that your Linux, Phidget, and Mono setup is all working together, you&#039;ll want to run the Visual Basic (VB) examples.  You&#039;ll probably want to start with the Hello World VB example.  Alternatively, you could find the source code for your device. {{Template:FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
All of the .NET examples are much larger projects through Visual Studio, so you&#039;ll need to dig around within the project and find the source code and compile only that source code using Mono.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s say you&#039;re running the Hello World example.  The source code for the example is in the directory: &lt;br /&gt;
&lt;br /&gt;
:{{Code|VBNET/}} &amp;amp;rarr; {{Code|Hello World/}} &amp;amp;rarr; {{Code|Module1.vb}}&lt;br /&gt;
&lt;br /&gt;
Other examples will be in directories named appropriately for their software object name, rather than {{Code|Hello World}}.  Once you have found the example you want to run, copy the {{Code|Phidget21.NET.dll}} file that you unzipped earlier into that example directory where the {{Code|Module1.vb}} file is.  &lt;br /&gt;
&lt;br /&gt;
Then, compile the code.  When compiling, you need to link to the Phidget library. As the Phidget21.NET file is an &amp;quot;additional assembly&amp;quot; in Visual Basic/Mono, you can link to the assembly using the {{Code|-r}} &amp;quot;reference&amp;quot; switch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
vbnc Module1.vb -r:Phidget21.NET.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will compile a {{Code|*.exe}} file - in this case, {{Code|Module1.exe}}.  This you can then run under Mono:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo mono Program.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember that the {{Code|sudo}} is needed unless you have your [[OS - Linux#Setting udev Rules|udev rules set on your Linux system]].&lt;br /&gt;
&lt;br /&gt;
If you will be compiling with an IDE such as GTK# or MonoDevelop, we don&#039;t have explicit instructions by IDE for Linux.  However, you will probably find the [[#MonoDevelop | MonoDevelop]] section in the Windows portion above useful.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any Visual Basic code on Linux, such as within a text editor like Emacs, Vi, Gedit, or Kate. In your .vb source code file, you must include a reference to the Phidget software object.  In the case of a Phidget interface kit device, this would look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=vbnet&amp;gt;&lt;br /&gt;
Public Class Form1&lt;br /&gt;
   &#039;The Phidget object declaration&lt;br /&gt;
		&lt;br /&gt;
   Dim WithEvents ifKit As Phidgets.InterfaceKit&lt;br /&gt;
		&lt;br /&gt;
   &#039;... Form1_Load and Form1_OnClosing here&lt;br /&gt;
End Class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other devices, check the API for your device on our webpage for the software object name, and the [http://www.phidgets.com/documentation/Phidget21.NET.zip API for .NET] for the specific syntax to use.  Then, you would compile your completed VB code the same way as the examples above.&lt;br /&gt;
&lt;br /&gt;
Mono also has a few different IDEs which you can use to develop code, and these are especially useful if you are doing GUI development.  We provide instructions for MonoDevelop - one such IDE - being used [[#MonoDevelop|under Windows]].&lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching section]] to help you follow the provided VB examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  This teaching section has resources for you to learn from the examples and write your own.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing Visual Basic .NET code will be our .NET API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in .NET|[http://www.phidgets.com/documentation/Phidget21.NET.zip .NET API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In Visual Basic .NET, you can name these &#039;&#039;&#039;event&#039;&#039;&#039; functions whatever you like, although you must catch the events by name in the &amp;quot;Handles&amp;quot; portion of the function declaration.  The &amp;quot;Handles&amp;quot; portion of the function hooks them into the actual events when they occur. See our examples for details.&amp;lt;br&amp;gt; &lt;br /&gt;
In the example code, the event functions common to all Phidgets are called things like &#039;&#039;&#039;AttachHandler()&#039;&#039;&#039; and &#039;&#039;&#039;DetachHandler()&#039;&#039;&#039;, etc.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Some event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.&lt;br /&gt;
Other functions are given in the device-specific examples to show you more detail on using your Phidget.  &lt;br /&gt;
|Creating a Phidget software object in Visual Basic .NET is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating a {{Code|Spatial}} object.  The examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The object provides device specific methods and properties which are available from the API for your specific Phidget.|&lt;br /&gt;
[http://www.phidgets.com/documentation/Phidget21.NET.zip .NET API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
Specific calls in Visual Basic (VB) .NET will differ in syntax from those on the [[General Phidget Programming]] page, but the concepts stay the same.  &lt;br /&gt;
&lt;br /&gt;
It may help to have the [[General Phidget Programming]] page and this section open at the same time, because they parallel each other and you can refer to the VB .NET syntax.  However, &#039;&#039;many&#039;&#039; additional concepts are covered on the General Phidget Programming page on a high level, such as using multiple Phidgets, handling errors, and different styles of programming.&lt;br /&gt;
&lt;br /&gt;
====Step One: Initialize and Open====&lt;br /&gt;
&lt;br /&gt;
The open() function opens the software object, but not hardware. So, it is not a guarantee you can use the Phidget immediately.&lt;br /&gt;
&lt;br /&gt;
The different types of open can be used with parameters to try and get the first device it can find, open based on its serial number, or even open across the network. The API manual lists and [[General Phidget Programming]] discusses all of the available modes that open provides.&lt;br /&gt;
&lt;br /&gt;
For example, if we were using an Interface Kit Phidget board as our device, the create and open calls would look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=vbnet&amp;gt;&lt;br /&gt;
ifKit = New Phidgets.InterfaceKit&lt;br /&gt;
ifKit.open()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Two: Wait for Attachment (plugging in) of the Phidget====&lt;br /&gt;
&lt;br /&gt;
To use the Phidget, it must be plugged in (attached). We can handle this by using event driven programming and tracking the AttachEvents and DetachEvents, or we can handle this by calling waitForAttachment. This function works for any Phidget. WaitForAttachment will block indefinitely until a connection is made to the Phidget, or an optional timeout is exceeded.&lt;br /&gt;
&lt;br /&gt;
When combined in your initialization function with the initialization and open from above, the wait for attachment would look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=vbnet&amp;gt;&lt;br /&gt;
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)&lt;br /&gt;
Handles MyBase.Load&lt;br /&gt;
    ifKit = New Phidgets.InterfaceKit&lt;br /&gt;
    ifKit.open()&lt;br /&gt;
    ifKit.waitForAttachment(3000)&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Three: Do Things with the Phidget====&lt;br /&gt;
&lt;br /&gt;
We recommend the use of event driven programming when working with Phidgets. In VB.NET we can hook an event handler into the event of a sensor changing on an Interface Kit board with the following code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=vbnet&amp;gt;&lt;br /&gt;
Private Sub ifKit_SensorChange(ByVal sender As Object, ByVal e As Phidgets.Events.SensorChangeEventArgs) Handles ifKit.SensorChange&lt;br /&gt;
    TextBox1.Text = &amp;quot;Index &amp;quot; + e.Index.ToString() + &amp;quot; Value: &amp;quot; + e.Value.ToString()&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With this function, the code inside ifKit_SensorChange will get executed every time the Phidget Interface Kit reports a change on one of its analog inputs. This is because it &amp;quot;Handles&amp;quot; the SensorChange event.  Some events such as Attach and Detach belong to the base Phidget object and thus are common to all types of Phidgets. &lt;br /&gt;
&lt;br /&gt;
Some values can be read and sent directly to the Phidget, simply use the instance members and properties. This is also how you would set properties on the Phidget such as the output state or&lt;br /&gt;
sensor sensitivity.  For example, obtaining the value of analog input (sensor) 0 on an Interface Kit board would be via:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=vbnet&amp;gt;&lt;br /&gt;
Dim val As Integer = ifKit.sensors(0).Value&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Four: Close and Delete====&lt;br /&gt;
&lt;br /&gt;
At the end of your program, unhook any events and call Application.DoEvents(). This will make sure there are no outstanding events being processed before calling close.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=vbnet&amp;gt;&lt;br /&gt;
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing&lt;br /&gt;
    RemoveHandler ifKit.SensorChange, AddressOf ifKit_SensorChange&lt;br /&gt;
    Application.DoEvents()&lt;br /&gt;
    ifKit.close()&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{MoreHowTos}}&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;complete&#039;&#039; set of functions you have available for all Phidgets can be found in the [http://www.phidgets.com/documentation/Phidget21.NET.zip .NET API].  You can also find more description on any device-specific function in the Device API page for your specific Phidget, which can be found on its product page on our [http://www.phidgets.com main website].&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
==={{ProblemSolution|All Operating Systems|The Phidgets.Events.ErrorEventHandler conflicts with System.IO.ErrorEventHandler.}}===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using Phidgets;&lt;br /&gt;
using Phidgets.Events;&lt;br /&gt;
...&lt;br /&gt;
spatial.Error += new ErrorEventHandler(spatial_Error);&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
void spatial_Error(object sender, ErrorEventArgs e){&lt;br /&gt;
   ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code produces the following errors:&lt;br /&gt;
&lt;br /&gt;
{{Code|&#039;ErrorEventHandler&#039; is an ambiguous reference between &#039;System.IO.ErrorEventHandler&#039; and &#039;Phidgets.Events.ErrorEventHandler&#039;}}.&lt;br /&gt;
&lt;br /&gt;
and&lt;br /&gt;
&lt;br /&gt;
{{Code|&#039;ErrorEventArgs&#039; is an ambiguous reference between &#039;System.IO.ErrorEventArgs&#039; and &#039;Phidgets.Events.ErrorEventArgs&#039;}}.&lt;br /&gt;
&lt;br /&gt;
The error is due to the {{Code|System.IO}} and {{Code|Phidgets.Events}} namespaces both having a class called {{Code|ErrorEventHandler}}.&lt;br /&gt;
&lt;br /&gt;
To get around this issue, use the fully qualified namespace when referring to the {{Code|ErrorEventHandler}} and {{Code|ErrorEventArgs}} classes:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using Phidgets;&lt;br /&gt;
using Phidgets.Events;&lt;br /&gt;
...&lt;br /&gt;
spatial.Error += new Phidgets.Events.ErrorEventHandler(spatial_Error);&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
void spatial_Error(object sender, Phidgets.Events.ErrorEventArgs e){&lt;br /&gt;
   ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>192.168.3.183</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Max&amp;diff=19936</id>
		<title>Language - Max</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Max&amp;diff=19936"/>
		<updated>2012-05-23T19:27:20Z</updated>

		<summary type="html">&lt;p&gt;192.168.3.183: /* OS X */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-MaxMSP.png|link=|alt=MaxMSP|64x64px]]|Max/MSP, developed by [http://cycling74.com Cycling74] is a visual programming language for creating music and media applications.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|Max/MSP|most of the Phidget API, including events. All the supported functions for Max/MSP will be documented in the {{Code|.help}} files|all Phidget devices.| Windows and OS X|&lt;br /&gt;
&lt;br /&gt;
Only Max/MSP 4.5 or higher is supported.}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
{{QuickDownloads|Max/MSP|&lt;br /&gt;
* [http://www.phidgets.com/downloads/examples/WinMaxMSP_2.1.8.20120123.zip {{Code|.help}} file(Windows - same file as Max/MSP Examples and Libraries)]&lt;br /&gt;
* [http://www.phidgets.com/downloads/examples/WinMaxMSP_2.1.8.20120123.zip {{Code|.help}} file(OS X - same file as Max/MSP Examples and Libraries)]|&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/WinMaxMSP_2.1.8.20120123.zip|(Windows - same file as Max/MSP Documentation and Libraries)}}&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/WinMaxMSP_2.1.8.20120123.zip|(OS X - same file as Max/MSP Documentation and Libraries)}}|{{ExtraLibraryQuickDownloads|http://www.phidgets.com/downloads/examples/WinMaxMSP_2.1.8.20120123.zip|Max/MSP|(Windows - same file as Max/MSP Documentation and Examples)}}&lt;br /&gt;
{{ExtraLibraryQuickDownloads|http://www.phidgets.com/downloads/examples/WinMaxMSP_2.1.8.20120123.zip|Max/MSP|(OS X - same file as Max/MSP Documentation and Examples)}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with Max/MSP==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
  &lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
Max/MSP programs on Windows depend on the following files. The installers in the [[#Libraries and Drivers | Quick Downloads]] section put only the {{Code|phidget21.dll}} into your system. You will need to manually put the {{Code|PhidgetXXX.mxe}} onto your system. &lt;br /&gt;
* &amp;lt;b&amp;gt;&amp;lt;code&amp;gt;phidget21.dll&amp;lt;/code&amp;gt;&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time. By default, the installer places it in &amp;lt;code&amp;gt;C:\Windows\System32&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &amp;lt;b&amp;gt;&amp;lt;code&amp;gt;PhidgetXXX.mxe&amp;lt;/code&amp;gt;&amp;lt;/b&amp;gt; is the Phidget library for your specific device. XXX denotes the name of your device, Please make sure the &amp;lt;code&amp;gt;.mxe&amp;lt;/code&amp;gt; file corresponds with the device you are using. For example, if you are using the PhidgetInterfaceKit, you will need the {{Code|PhidgetInterfaceKit.mxe}}. It is to be placed in the same directory as your Max/MSP application or anywhere in the Max/MSP search path.&lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the {{Code|[http://www.phidgets.com/downloads/libraries/phidget21-x86_2.1.8.20110615.zip phidget21.dll]}} and manually install it where you want; refer to our [[OS_-_Windows#Manual_File_Installation|Manual Installation Instructions]].&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
Please start by downloading the [http://www.phidgets.com/downloads/examples/WinMaxMSP_2.1.8.20120123.zip  Max/MSP Examples and Library] and unpack them into a folder.  These examples were written in Max/MSP 4.6, but any version above 4.5 are also supported.&lt;br /&gt;
&lt;br /&gt;
Here, you will find example programs, in {{code | .help}} format for all the devices. If you aren&#039;t sure what the software example for your device is called, check the software object listed in the [[Device List | Getting Started guide for your device]].&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Open the {{code| .help}} file in the Max environment.&lt;br /&gt;
&lt;br /&gt;
Once you have the Max/MSP examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure the Max/MSP environment to properly link the Phidget Max/MSP libraries. To begin: &lt;br /&gt;
&lt;br /&gt;
Place the {{Code|.mxe}} in the same directory as the patcher, or anywhere in the Max/MSP search path. You can verify the search path locations by navigating to Options &amp;amp;rarr; File Preferences. &lt;br /&gt;
&lt;br /&gt;
[[File:MaxMSP Path.PNG|link=|alt=Search Path]]&lt;br /&gt;
&lt;br /&gt;
The best way to start writing your patch is to modify an example, and saving it as a {{Code|.pat}} file.&lt;br /&gt;
&lt;br /&gt;
If you wish to start a new patch. All you need to do is create an object named PhidgetXXX where XXX is the name of your device. For example, the [[Product - 1023 1 - PhidgetRFID | PhidgetRFID device]] will have the {{Code|PhidgetRFID}} object name. &lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
Max/MSP has excellent support on OS X.&lt;br /&gt;
&lt;br /&gt;
The first step in using Max/MSP on Mac is to install the Phidget library.  Compile and install them as explained on the [[Device List|getting started guide for your device]].  Then, the [[OS - OS X]] page also describes the different Phidget files, their installed locations, and their roles....&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
Please start by downloading the [http://www.phidgets.com/downloads/examples/MaxMSP_2.1.8.20120507.zip  Max/MSP Examples and Library] and unpack them into a folder.  These examples were written in Max/MSP 4.6, but any version above 4.5 are also supported.&lt;br /&gt;
&lt;br /&gt;
Here, you will find example programs, in {{code | .help}} format for all the devices. If you aren&#039;t sure what the software example for your device is called, check the software object listed in the [[Device List | Getting Started guide for your device]].&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Open the {{code| .help}} file in the Max environment.&lt;br /&gt;
&lt;br /&gt;
Once you have the Max/MSP examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure the Max/MSP environment to properly link the Phidget Max/MSP libraries. To begin: &lt;br /&gt;
&lt;br /&gt;
Place the {{Code|.mxe}} in the same directory as the patcher, or anywhere in the Max/MSP search path. You can verify the search path locations by navigating to Options &amp;amp;rarr; File Preferences. &lt;br /&gt;
&lt;br /&gt;
[[File:MaxMSP Path.PNG|link=|alt=Search Path]]&lt;br /&gt;
&lt;br /&gt;
The best way to start writing your patch is to modify an example, and saving it as a {{Code|.pat}} file.&lt;br /&gt;
&lt;br /&gt;
If you wish to start a new patch. All you need to do is create an object named PhidgetXXX where XXX is the name of your device. For example, the [[Product - 1023 1 - PhidgetRFID | PhidgetRFID device]] will have the {{Code|PhidgetRFID}} object name. &lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system, you probably now have a working example and want to understand it better so you can change it to do what you want.  This teaching section has resources for you to learn from the examples and write your own.&lt;br /&gt;
&lt;br /&gt;
First, let&#039;s explain how to operate the example. &lt;br /&gt;
&lt;br /&gt;
[[File:MaxMSP Example.PNG|link=|alt=Example]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot is what shows up when you open the example for the PhidgetInterfaceKit. If you are using a different device, your example patch will be different, but the idea is the same.&lt;br /&gt;
&lt;br /&gt;
For this particular example, the Max object is called {{Code|PhidgetInterfaceKit}}, which is located in the center of the screen. Objects/message boxes are connected to the inputs and outputs of the PhidgetInterfaceKit object. The input objects will either cause a property of the device to change or request for a property to be retrieved. The output objects return the retrieved information. All the supported features of the device are shown in the {{Code|.help}} file. &lt;br /&gt;
&lt;br /&gt;
Try it for yourself! Click on the {{Code | getSerial}} message box to request the Phidget to retrieve the serial number of the device. You should see the last output object of {{Code|route}} changed to the serial number of your device. All devices support the {{Code|getSerial}} object, and is the easiest way to determine if the Phidget libraries are correctly set up, and whether the Max/MSP application is connected to your device.&lt;br /&gt;
&lt;br /&gt;
[[File:MaxMSP getSerial.PNG|link=|alt=getSerial]]&lt;br /&gt;
&lt;br /&gt;
If your example contains the {{Code|read}} message box, click on it. This will return device specific values to the screen.&lt;br /&gt;
&lt;br /&gt;
[[File:MaxMSP read.PNG|link=|alt=Read Data]]&lt;br /&gt;
&lt;br /&gt;
If your example contains the {{Code|start}} message box, you can continuously poll for events. Set the sample rate input for the {{Code|setSampleRate}} object. Then, press the {{Code|start}} message box to start sampling. When a noteworthy event occurs on a Phidget(i.e., when an analog sensor senses a change in the environment), the value will be displayed onto the screen. Press the {{Code|stop}} message box to stop sampling.&lt;br /&gt;
&lt;br /&gt;
For the PhidgetInterfaceKit example, there also a {{Code|setoutput}} message box. Clicking on the check boxes will cause the digital outputs of the PhidgetInterfaceKit device to change. Your example may contain device specific message boxes/objects to click on. See for yourself what they do!&lt;br /&gt;
&lt;br /&gt;
For information regarding calls specific to your device, please see the [[Device List | API for your specific device]]. Please note that some device functionality are not supported in Max/MSP; the {{Code|.help}} example shows the complete list of functionality supported under Max/MSP.&lt;br /&gt;
&lt;br /&gt;
==Code Snippets==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
openRemote object&lt;br /&gt;
&lt;br /&gt;
multiple phidgets&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
{{ProblemSolution|Crash|When a patch file is closed in the Max/MSP environment, the program crashes}}&lt;br /&gt;
&lt;br /&gt;
If in your Max/MSP environment, you have more patches(of the same Phidget object) than you have of the actual hardware device, the Max/MSP environment may crash. This is due to the fact that a single Phidget Max/MSP object &amp;lt;i&amp;gt;only&amp;lt;/i&amp;gt; corresponds to a single Phidget device hardware. For example, your Max/MSP environment may experience unexpected behavior while you have one PhidgetInterfaceKit device connected to the computer, but you have a two seperate patches opened with a single PhidgetInterfaceKit Max object in each one.&lt;br /&gt;
&lt;br /&gt;
Likely Fix: Please ensure that you do not use more patches(of the same Phidget object) than you have of the actual Phidget device.&lt;/div&gt;</summary>
		<author><name>192.168.3.183</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Python&amp;diff=19807</id>
		<title>Language - Python</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Python&amp;diff=19807"/>
		<updated>2012-05-17T19:11:36Z</updated>

		<summary type="html">&lt;p&gt;192.168.3.183: /* OS X */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-Python.png|64x64px|link=|alt=Python]]|Python is an object oriented programming language developed by the [http://www.python.org/psf/summary/ Python Software Foundation], is powerful and easy to learn.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|Python|the complete Phidget API, including events|all Phidget devices.|Windows, OS X and Linux. We provide instructions on how to set up your environment for [[#Command line | command line]], [[#IDLE | IDLE]], and [[#Eclipse with PyDev | Eclipse with PyDev]]|&lt;br /&gt;
&lt;br /&gt;
Only Python 2.5 or higher is supported.}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
&lt;br /&gt;
{{QuickDownloads|Python|&lt;br /&gt;
{{APIQuickDownloads|http://www.phidgets.com/documentation/PythonDoc.zip}}|&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/Python.zip|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|http://www.phidgets.com/downloads/libraries/PhidgetsPython.zip|Python|}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
==Getting started with Python==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library===&lt;br /&gt;
Python programs on Windows depend on the following. The installers in the [[#Libraries and Drivers | Quick Downloads]] section put only the {{Code|phidget21.dll}} into your system. You will need to manually put the Phidget Python Module into your system.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget Python Module}}&amp;lt;/b&amp;gt; is the Phidget library for Python.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|setup.py}}&amp;lt;/b&amp;gt; is used to install the Phidget module into the standard location for third party Python modules. On typical Python environments, this setup will install the Phidget Python module in the {{Code|site-packages}} directory. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the [http://www.phidgets.com/downloads/libraries/Phidget21-windevel.zip {{Code|phidget21.dll}}] and refer to our [[OS - Windows|Windows page]] for manual installation instructions.&lt;br /&gt;
&lt;br /&gt;
The first thing you will have to do is to [[#Installing the Phidget Python Module |install the {{Code|Phidget Python Module}}]]. &lt;br /&gt;
Afterwards, Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each environment below.&lt;br /&gt;
&lt;br /&gt;
===Installing the Phidget Python Module===&lt;br /&gt;
&lt;br /&gt;
Please start by downloading [http://www.phidgets.com/downloads/libraries/PhidgetsPython.zip Phidget Python Module]. After extracting the file, open up a command line terminal, traverse to the directory containing {{Code|setup.py}} and enter the following to install the Phidget Python module into the Python environment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
python setup.py install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Command Line===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
Please ensure that the Phidget Python Module is [[#Installing the Phidget Python Module | installed]] onto your system.&lt;br /&gt;
&lt;br /&gt;
Next, download the [http://www.phidgets.com/downloads/examples/Python.zip examples] and unpack them into a folder.  While these examples were written in Python 3.0, they are also compatible with Python 2.5 (with a [[#All Operating Systems: The examples produces an error while running in a Python 2.5 environment. | minor modification]]). It is probably best to start with the HelloWorld program, which will work with any Phidget.  There is also an example file for your specific Phidget device.  {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Now, open up a command line prompt and navigate to the directory of the example folder. &lt;br /&gt;
&lt;br /&gt;
Next, enter the following to run the example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
python example.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have the Python examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your environment to properly link the Phidgets Python libraries. Please see the [[#Use Our Examples| Use Our Examples ]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to reference to the Phidget Python library.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
from Phidgets.PhidgetException import *&lt;br /&gt;
from Phidgets.Events.Events import *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you will also have to add a reference to your particular Phidget.  For example, you would include the following line for a PhidgetInterfaceKit:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
from Phidgets.Devices.InterfaceKit import *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please see the [http://www.phidgets.com/downloads/examples/Python.zip examples] on how to add a reference to your particular Phidget.&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching ]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===IDLE===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Please ensure that the Phidget Python Module is [[#Installing the Phidget Python Module | installed]] onto your system. &lt;br /&gt;
&lt;br /&gt;
Next, download the [http://www.phidgets.com/downloads/examples/Python.zip examples] and unpack them into a folder.  While these examples were written in Python 3.0, they are also compatible with Python 2.5 (with a [[#All Operating Systems: The examples produces an error while running in a Python 2.5 environment. | minor modification]]). It is probably best to start with the HelloWorld program, which will work with any Phidget.  There is also an example file for your specific Phidget device.  {{FindYourDevice}}  Now, open the example in the IDLE editor.&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Click on Run &amp;amp;rarr; Run Module.&lt;br /&gt;
&lt;br /&gt;
[[File:Python IDLE Run.PNG|link=|alt=Run?]]&lt;br /&gt;
&lt;br /&gt;
Once you have the Python examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your environment to properly link the Phidget Python library. Please see the [[#Use Our Examples 2| Use Our Examples ]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to reference to the Phidget Python library.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
from Phidgets.PhidgetException import *&lt;br /&gt;
from Phidgets.Events.Events import *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you will also have to add a reference to your particular Phidget.  For example, you would include the following line for a PhidgetInterfaceKit:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
from Phidgets.Devices.InterfaceKit import *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please see the [http://www.phidgets.com/downloads/examples/Python.zip examples] on how to add a reference to your particular Phidget.&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching ]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Eclipse with PyDev===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
1. Please ensure that the Phidget Python Module is [[#Installing the Phidget Python Module | installed]] onto your system. &lt;br /&gt;
&lt;br /&gt;
2. Next, download the [http://www.phidgets.com/downloads/examples/Python.zip examples] and unpack them into a folder.  While these examples were written in Python 3.0, they are also compatible with Python 2.5 (with a [[#All Operating Systems: The examples produces an error while running in a Python 2.5 environment. | minor modification]]). It is probably best to start with the HelloWorld program, which will work with any Phidget.  There is also an example file for your specific Phidget device.  {{FindYourDevice}}  You will need this example source code to be imported into your project later on.&lt;br /&gt;
&lt;br /&gt;
3. Next, a new project will need to be created. Generate a new PyDev project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:Python PyDev New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
4. To import the example program into your project, right click the Project and select {{Code|Import}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Python PyDev Import File 1.PNG|link=|alt=Import File]]&lt;br /&gt;
&lt;br /&gt;
5. On the next screen, select {{Code|File System}} and proceed to the next screen.&lt;br /&gt;
&lt;br /&gt;
[[File:Python PyDev Import File 2.PNG|link=|alt=Import File]]&lt;br /&gt;
&lt;br /&gt;
6. Browse to the directory where you extracted the examples into, and select the example you wish to open.&lt;br /&gt;
&lt;br /&gt;
[[File:Python PyDev Import File 3.PNG|link=|alt=Import File]]&lt;br /&gt;
&lt;br /&gt;
7. The only thing left to do is to run the examples! Click on Run &amp;amp;rarr; Run.&lt;br /&gt;
&lt;br /&gt;
[[File:Python PyDev Run.PNG|link=|alt=Run?]]&lt;br /&gt;
&lt;br /&gt;
Once you have the Python examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your environment to properly link the Phidget Python library. Please see the [[#Use Our Examples 3 | Use Our Examples ]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include a reference to the Phidget Python library.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
from Phidgets.PhidgetException import *&lt;br /&gt;
from Phidgets.Events.Events import *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will also have to add a reference to your particular Phidget.  For example, you would include the following line for a PhidgetInterfaceKit:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
from Phidgets.Devices.InterfaceKit import *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please see the [http://www.phidgets.com/downloads/examples/Python.zip examples] on how to add a reference to your particular Phidget.&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching ]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
The first step in using Python on Mac is to install the Phidget libraries.  Compile and install them as explained on the [[OS - OS X]] page, which also describes the different Phidget files, their installed locations, and their roles....&lt;br /&gt;
&lt;br /&gt;
The next step is to install the Phidget Python module.  Download it here:&lt;br /&gt;
* [http://www.phidgets.com/downloads/libraries/PhidgetsPython.zip Phidget Python Module]&lt;br /&gt;
&lt;br /&gt;
Then, unpack the module and enter the root of the newly unzipped directory.  There will be a script in the base directory called {{Code|setup.py}}.  This is used the same way as most other distributed Python modules - from a command line type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
python setup.py install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will build the module and install the built python module files into your {{Code|site-packages}} directory.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
First, download the examples:&lt;br /&gt;
*[http://www.phidgets.com/downloads/examples/Python.zip Phidget Python Examples]&lt;br /&gt;
&lt;br /&gt;
Unpack them, and enter the root directory.  You will find examples specific to each Phidget device, as well as a {{Code|HelloWorld.py}} example.  The {{Code|HelloWorld.py}} code is probably the easiest example to run as it will work with any Phidget device.  Or you can use the example specific to your Phidget.  {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
The Phidget examples were written in Python 3.0 and this tutorial assumes its use. However, they should still be compatible with Python 2.6. To run the examples using Python 2.5, you will need to modify the example code in the exception handling to read “except RuntimeError, e:”, instead of “except RuntimeError as e:”.&lt;br /&gt;
&lt;br /&gt;
If needed, make those changes to the {{Code|HelloWorld.py}} example or the one for your Phidget.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
python HelloWorld.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any Python code, such as within a text editor like Emacs, Vi, Gedit, or Kate.  In your &#039;&#039;&#039;{{Code|.py}}&#039;&#039;&#039; source code file, you must include a reference to the Phidget module:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
from Phidgets.PhidgetException import *&lt;br /&gt;
from Phidgets.Events.Events import *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In addition, you should include the module functions for your specific device.  In the case of the Interface Kit, this would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
from Phidgets.Devices.InterfaceKit import *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other devices, it would be the software object you found when running the examples above.  Then, you would run your Python code the same way as the examples.&lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided Python examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
Python has excellent support on Linux.  &lt;br /&gt;
&lt;br /&gt;
The first step in using Python on Linux is to install the Phidget libraries.  These are the core Phidget libraries, written in C, which when compiled become part of the programming libraries available to your system.  Download, compile, and install from the links and instructions on the main [[OS - Linux | Linux page]].  That Linux page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
The next step is to install the Phidget Python module.  Download it here:&lt;br /&gt;
* [http://www.phidgets.com/downloads/libraries/PhidgetsPython.zip Phidget Python Module]&lt;br /&gt;
&lt;br /&gt;
Then, unpack the module and enter the root of the newly unzipped directory.  There will be a script in the base directory called {{Code|setup.py}}.  This is used the same way as most other distributed Python modules - from a command line type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
python setup.py install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will build the module and install the built python module files into your {{Code|site-packages}} directory.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
First, download the examples:&lt;br /&gt;
*[http://www.phidgets.com/downloads/examples/Python.zip Phidget Python Examples]&lt;br /&gt;
&lt;br /&gt;
Unpack them, and enter the root directory.  You will find examples specific to each Phidget device, as well as a {{Code|HelloWorld.py}} example.  The {{Code|HelloWorld.py}} code is probably the easiest example to run as it will work with any Phidget device.  Or you can use the example specific to your Phidget.  {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
The Phidget examples were written in Python 3.0 and this tutorial assumes its use. However, they should still be compatible with Python 2.6. To run the examples using Python 2.5, you will need to modify the example code in the exception handling to read “except RuntimeError, e:”, instead of “except RuntimeError as e:”.&lt;br /&gt;
&lt;br /&gt;
If needed, make those changes to the {{Code|HelloWorld.py}} example or the one for your Phidget.  &lt;br /&gt;
&lt;br /&gt;
Then, if you have not set up [[OS_-_Linux#Setting_udev_Rules|your udev rules for USB access]], you will need to run the Python example as &#039;&#039;&#039;root&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo python HelloWorld.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any Python code on Linux, such as within a text editor like Emacs, Vi, Gedit, or Kate.  In your &#039;&#039;&#039;{{Code|.py}}&#039;&#039;&#039; source code file, you must include a reference to the Phidget module:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
from Phidgets.PhidgetException import *&lt;br /&gt;
from Phidgets.Events.Events import *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In addition, you should include the module functions for your specific device.  In the case of the Interface Kit, this would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
from Phidgets.Devices.InterfaceKit import *&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other devices, it would be the software object you found when running the examples above.  Then, you would run your Python code the same way as the examples.&lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided Python examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  This teaching section has resources for you to learn from the examples and write your own.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing Python code will be our Python API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in Python|[http://www.phidgets.com/documentation/PythonDoc.zip Python API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In Python, you can name these &#039;&#039;&#039;event&#039;&#039;&#039; functions whatever you like.  You will then pass their function names to the Phidget library below in the Main Code section.  This hooks them into the actual events when they occur. &amp;lt;br&amp;gt; &lt;br /&gt;
In the example code, the event functions common to all Phidgets are called things like &#039;&#039;&#039;AttachHandler()&#039;&#039;&#039; and &#039;&#039;&#039;DetachHandler()&#039;&#039;&#039;, etc.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Some event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.&lt;br /&gt;
Other functions are given in the examples to show you more detail on using your Phidget.  For example, &#039;&#039;&#039;DeviceInitialize()&#039;&#039;&#039; will show what needs to be set up for your Phidget before using it.&lt;br /&gt;
|Creating a Phidget software object in Python is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating a {{Code|Spatial}} object.  The examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The object provides device specific methods and properties which are available from the API for your specific Phidget.|&lt;br /&gt;
[http://www.phidgets.com/documentation/PythonDoc.zip Python API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
Specific calls in Python will differ in syntax from those on the [[General Phidget Programming]] page, but the concepts stay the same.  &lt;br /&gt;
&lt;br /&gt;
It may help to have the [[General Phidget Programming]] page and this section open at the same time, because they parallel each other and you can refer to the Python syntax.  However, many additional concepts are covered on the General Phidget Programming page on a high level, such as using multiple Phidgets, handling errors, and different styles of programming.&lt;br /&gt;
&lt;br /&gt;
For example, if we were using a [[Product - 1018 - PhidgetInterfaceKit 8/8/8 | Phidget Interface Kit]] as our device, the general calls would look like this:&lt;br /&gt;
&lt;br /&gt;
====Step One: Initialize and Open====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
# Create&lt;br /&gt;
try:&lt;br /&gt;
  device = InterfaceKit()	&lt;br /&gt;
except RuntimeError as e:&lt;br /&gt;
  print(&amp;quot;Runtime Error: %s&amp;quot; % e.message)&lt;br /&gt;
&lt;br /&gt;
# Open&lt;br /&gt;
try:&lt;br /&gt;
  device.openPhidget()&lt;br /&gt;
except PhidgetException as e:&lt;br /&gt;
  print (“Phidget Exception %i: %s” % (e.code, e.detail))		&lt;br /&gt;
  exit(1)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The variable {{Code|device}} is now a handle for the Phidget.  This example is &#039;&#039;specific to the Interface Kit&#039;&#039; because the call InterfaceKit() is used.  For another device, use the correspondingly named call in the Python API. &lt;br /&gt;
&lt;br /&gt;
The handle &#039;&#039;&#039;device&#039;&#039;&#039; is then used for all the Python function calls using the Phidget for its device-specific functions - in this case, Interface Kit specific functions.  Every type of Phidget also inherits functionality from the Phidget base class.&lt;br /&gt;
&lt;br /&gt;
Note that open() opens the software object, but not hardware.  So, it is not a guarantee you can use the Phidget immediately.  The different types of open can be used with parameters to try and get the first device it can find, open based on its serial number, or even open across the network. The API manual lists all of the available modes that open provides.&lt;br /&gt;
&lt;br /&gt;
Also note that you can catch exceptions thrown by the Phidget library as we did above when using the openPhidget() call.  In other words, this should probably be present around most of your Phidget calls, especially when you are learning how to use the Phidget and debugging your code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
try:&lt;br /&gt;
  # Your code goes here&lt;br /&gt;
except PhidgetException as e:&lt;br /&gt;
  print (“Phidget Exception %i: %s” % (e.code, e.detail))		&lt;br /&gt;
  exit(1)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Two: Wait for Attachment (plugging in) of the Phidget==== &lt;br /&gt;
&lt;br /&gt;
To use the Phidget, it must be plugged in (attached).  We can handle this simply by calling waitForAttachment. This function works for any Phidget. WaitForAttachment will block indefinitely until a connection is made to the Phidget, or an optional timeout is exceeded:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
device.waitForAttach(10000)&lt;br /&gt;
print (&amp;quot;%d attached!&amp;quot; % (device.getSerialNum()))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sometimes, it makes more sense to handle the attachment via an event.  This would be in instances where the Phidget is being plugged and unplugged, and you want to handle these incidents.  Or, when you want to use event-driven programming because you have a GUI-driven program.  In these cases, an event-driven code snippet to handle the attachment might look something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
def AttachHandler(event):&lt;br /&gt;
    attachedDevice = event.device&lt;br /&gt;
    serialNumber = attachedDevice.getSerialNum()&lt;br /&gt;
    deviceName = attachedDevice.getDeviceName()&lt;br /&gt;
    print(&amp;quot;Hello to Device &amp;quot; + str(deviceName) + &amp;quot;, Serial Number: &amp;quot; + str(serialNumber))&lt;br /&gt;
&lt;br /&gt;
# Insert code for -creating- device here....&lt;br /&gt;
&lt;br /&gt;
try:&lt;br /&gt;
    device.setOnAttachHandler(AttachHandler)&lt;br /&gt;
except PhidgetException as e: &lt;br /&gt;
    # Insert code for handling any exceptions&lt;br /&gt;
    # A common exception will occur if you do not create the device properly above&lt;br /&gt;
&lt;br /&gt;
# Insert code for -opening- device here....&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Three: Do Things with the Phidget====&lt;br /&gt;
&lt;br /&gt;
You can read data and interact with your Phidget both by polling it for its current state (or to set a state), or by catching events that trigger when the data changes.&lt;br /&gt;
&lt;br /&gt;
For our [[Product - 1018 - PhidgetInterfaceKit 8/8/8 | Phidget Interface Kit]], the polling method of getting the current sensor state and setting an output state looks something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Get a data point from Analog Port 0&lt;br /&gt;
device.getSensorValue(0)&lt;br /&gt;
&lt;br /&gt;
# Set digital output port 0 to be on&lt;br /&gt;
device.setOutputState(0, 1)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To catch data changes via events, you would use something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
&lt;br /&gt;
def sensorChanged(e):&lt;br /&gt;
  print (“Sensor %i: %i” % (e.index, e.value))&lt;br /&gt;
  return 0&lt;br /&gt;
&lt;br /&gt;
# Insert code to create an Interface Kit called &#039;device&#039;&lt;br /&gt;
&lt;br /&gt;
# Hook our function above into the device object&lt;br /&gt;
device.setOnSensorChangeHandler(sensorChanged)&lt;br /&gt;
&lt;br /&gt;
# Insert code to open &#039;device&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Four: Close and Delete====&lt;br /&gt;
&lt;br /&gt;
At the end of your program, don’t forget to call closePhidget() to free any locks on the Phidget that the openPhidget() call put in place!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
&lt;br /&gt;
device.closePhidget()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{MoreHowTos}}&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;complete&#039;&#039; set of functions you have available for all Phidgets can be found in the [http://www.phidgets.com/documentation/PythonDoc.zip Python API]. You can also find more description on any device-specific function in the Device API page for your specific Phidget, which can be found on its product page on our [http://www.phidgets.com main website].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
==={{ProblemSolution|OS X|My application hangs when using multiple devices in a single Python application.}}===&lt;br /&gt;
&lt;br /&gt;
A call to {{Code|open}} may hang indefinitely if multiple devices are being programmed in a single Python application. To circumvent this, allow the application to delay a short period between {{Code|open}} calls. For most environments, a 1.25 millisecond delay is enough. For example:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
import time&lt;br /&gt;
...&lt;br /&gt;
interface_kit.openPhidget(94695)&lt;br /&gt;
time.sleep(0.00125)&lt;br /&gt;
rfid.openPhidget(33502)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==={{ProblemSolution|All Operating Systems|The examples produce an error while running in a Python 2.5 environment.}}===&lt;br /&gt;
&lt;br /&gt;
Running the examples produces an error similar to the following:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
InterfaceKit-simple.py:33: Warning: &#039;as&#039; will become a reserved keyword in Python 2.6&lt;br /&gt;
  File &amp;quot;InterfaceKit-simple.py&amp;quot;, line 33&lt;br /&gt;
    except RuntimeError as e:&lt;br /&gt;
SyntaxError: invalid syntax&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run the example code in Python 2.5, all the lines containing:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
except RuntimeError as e:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
will need to be replaced with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
except Runtime, e:&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>192.168.3.183</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=19805</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=19805"/>
		<updated>2012-05-17T17:47:52Z</updated>

		<summary type="html">&lt;p&gt;192.168.3.183: /* Installation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-Java.png|64x64px|link=|alt=Java]]|Java is a modern, object-oriented programming language maintained by Oracle.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|Java|the complete Phidget API, including events|all Phidget devices.|the {{Code|javac}} command line compiler as well as in integrated development environments(IDEs) such as [[#NetBeans | NetBeans]] and [[#Eclipse | Eclipse]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
&lt;br /&gt;
{{QuickDownloads|Java|&lt;br /&gt;
{{APIQuickDownloads|http://www.phidgets.com/documentation/JavaDoc.zip}}|&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/JavaJNI.zip|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|http://www.phidgets.com/downloads/libraries/phidget21jar.zip|Java|(phidget21.jar)}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with Java==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
Java programs on Windows depend on two files, which the installers in the [[#Libraries and Drivers | Quick Downloads]] section put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.  &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.jar}}&amp;lt;/b&amp;gt; is the Phidget Java library for JDK &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.4.2&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. So, you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. For more information, please see the section for your specific compiler/environment. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the [http://www.phidgets.com/downloads/libraries/phidget21-x86.zip {{Code|phidget21.dll}}] as well as the [http://www.phidgets.com/downloads/libraries/phidget21jar_2.1.8.20120131.zip {{Code|phidget21.jar}}] and manually install them where you want; refer to our [[OS_-_Windows#Manual_File_Installation|Manual Installation Instructions]].&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each compiler below.&lt;br /&gt;
&lt;br /&gt;
You can program Phidgets with Java in command line with the {{Code|javac}} compiler as well as in IDEs such as NetBeans and Eclipse. &lt;br /&gt;
&lt;br /&gt;
===Javac (Command Line)===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip example] and unpack them into a folder. Here, you can find an example program called HelloWorld which will work with any Phidget.  You can also find example programs for all the devices. {{FindYourDevice}} Please only use the simple examples. The full examples are intended for the [[#NetBeans | NetBeans IDE]].&lt;br /&gt;
&lt;br /&gt;
Ensure that the {{Code|phidget21.jar}} is in the same directory as the source code.&lt;br /&gt;
&lt;br /&gt;
To compile in Windows command prompt:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .;phidget21.jar example.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create Java bytecode in the form of {{Code|.class}} files. Type the following to run the program:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .;phidget21.jar example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you wish, you can compile the project as a {{Code|.jar}} so there are fewer files to maintain. The [http://www.oracle.com/java Java SDK] provides the {{Code|jar}} utility which packages all the {{Code|.class}} files into a single {{Code|.jar}} file. &lt;br /&gt;
To begin, you will have to provide a Manifest file to indicate the program entry point. With your favourite text editor, create a new file with the following content:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;  &lt;br /&gt;
Ensure that the file ends in a single new line or a carriage return character. &lt;br /&gt;
Save the file as {{Code|example.mf}} and place it in the same directory as the other {{Code|.class}} files.&lt;br /&gt;
Next, create the .{{Code|jar}} with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar -cfm example.jar example.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Afterwards, you can run the {{Code|.jar}} with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -jar example.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#Use Our Examples| previous]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
You first download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip examples], unpack them into a folder, and then find the source code for your device. {{FindYourDevice}} The full examples were written in NetBeans, so the rest of this section will use these examples. To use the simple examples, you will have to import the source code into a new NetBeans project. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Open Project.PNG|link=|alt=Open Project]]&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Click on Run &amp;amp;rarr; Run Project. The project, by default tries to find the {{Code|phidget21.jar}} in {{Code|..\..\lib}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Create a new Java application project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget Java library. In the projects pane, right click {{Code|Libraries}} and add the {{Code|jar}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Add Jar.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
3. Find and select {{Code|phidget21.jar}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Add Jar 2.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip examples] and unpack them into a folder. Here, you can find an example program called HelloWorld which will work with any Phidget.  You will also find example programs for all the devices. {{FindYourDevice}} &lt;br /&gt;
&lt;br /&gt;
Please use the simple examples. The full examples were written in NetBeans, and are not compatible with Eclipse. The rest of this guide will assume that the simple examples are used. The example source code will be copied into your Eclipse project later on. Keep note of the file name of the example as a Java class will be created with the same name.&lt;br /&gt;
&lt;br /&gt;
2. Generate a new Java project with a descriptive name such as PhidgetTest. Click next.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. On the next screen, go to the libraries panel and add an external {{Code|jar}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Add Jar 1.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
4. Find and select {{Code|phidget21.jar}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Add Jar 2.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
5. Add a new Java class to the project.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Class.PNG|link=|alt=New Class]]&lt;br /&gt;
&lt;br /&gt;
6. Name this class with the same name as the simple example&#039;s name. &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Class 2.PNG|link=|alt=New Class]]&lt;br /&gt;
&lt;br /&gt;
7. Copy and paste the example source code over to the class you created.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
8. The only thing left to do is to run the examples! &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#Use Our Examples 3| Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
The first step in using Java on Mac is to install the Phidget libraries.  Compile and install them as explained on the [[OS - OS X|main Mac OS page]].  That page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
The commands to compile in a OS X and Windows terminal are slightly different. Rather than prefixing {{Code|phidget21.jar}} with a semi-colon( {{Code|;}} ), a colon( {{Code|:}} ) is used.  Make sure that the {{Code|phidget21.jar}} file is in the same directory as the code you are trying to compile.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar example.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, to run the program:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .:phidget21.jar example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can be used on any of the simple examples.  If you are interested in using an IDE then refer to the [[Language - Java#Windows (2000/XP/Vista/7)|Windows]] section for information about setting up Phidgets projects in Eclipse or NetBeans.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
With the method just discussed, notice that you need to link the {{Code|phidget21.jar}} both at compile, and runtime.  An alternative is to make a jar file of your program which includes the Phidget Java library.  To do this first create a manifest file. A manifest is a text file used to define package related data.  Make a text file called {{Code|MyProgram.mf}}, where {{Code|MyProgram}} is replaced by the name of your main class.  Put the following lines into {{Code|MyProgram.mf}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: MyProgram&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; The manifest file should end with a carriage return. So, there should be an extra line at the bottom of the file.&lt;br /&gt;
&lt;br /&gt;
After creating the manifest file, you can use the {{Code|jar}} function to create one self-contained file with your classes and the correct classpath.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar –cfm MyProgram.jar MyProgram.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If porting this for an external system, such as one that your customer would be running, the Phidget library would need to be compiled and distributed along with the {{Code|.jar}}.  Although we do not directly support this, if you are interested in how to construct this, we provide both a distribution example and information on cross-compiling:&lt;br /&gt;
* The [[Language - Android Java | Android Java]] libraries have an ARM-compiled {{Code|libphidget21.so}} file included, as an example of distributing a compiled libphidget21.so with the jar file&lt;br /&gt;
* The [[OS - Linux#Cross-Compiling with a Custom Toolchain|Linux page]] has more detail for compiling the Phidget C Libraries for an external target.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
We offer in-depth tutorials on using our examples in NetBeans and Eclipse in the [[#NetBeans|Windows NetBeans]] and [[#Eclipse|Windows Eclipse]] sections.&lt;br /&gt;
&lt;br /&gt;
As our full examples are written with NetBeans, but NetBeans is not part of the standard OS X application suite., we offer installation instructions here before referring to the Windows sections.&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
To install NetBeans on a Mac, all  you have to do is download the installer from [http://netbeans.org/ their website] and run it.&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Once you have NetBeans installed, running our examples will be very similar to the process described in the [[#NetBeans|Windows NetBeans]] section.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#NetBeans| Windows NetBeans]] section for instructions if you are unfamiliar with NetBeans.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The [[#Follow the Examples|teaching]] section - which describes the examples - also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
Java has excellent support on Linux - there is an established implementation of the Java compiler and interpreter, and several Integrated Development Environments (IDEs) including NetBeans and Eclipse. &lt;br /&gt;
&lt;br /&gt;
The first step in using Java on Linux is to install the base Phidget libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different basic Phidget library files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
You will also need the [http://www.phidgets.com/downloads/libraries/phidget21jar.zip Phidget Java Libraries (phidget21.jar)].&lt;br /&gt;
&lt;br /&gt;
Once downloaded, the {{Code|phidget21.jar}} library file does not get &#039;installed&#039; (i.e. do not run {{Code| java -jar phidget21.jar}}).  Rather, the library file gets put into the path of whatever program you write, and you will link it via both the java compiler and the java interpreter.  We walk you through this below.&lt;br /&gt;
&lt;br /&gt;
We have two different types of Phidget examples in Java: &lt;br /&gt;
*Simple examples, to be run on the command line, and&lt;br /&gt;
*Full examples, to be run in NetBeans&lt;br /&gt;
&lt;br /&gt;
Both are contained within the [http://www.phidgets.com/downloads/examples/JavaJNI.zip Phidget Java example download package].&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
&lt;br /&gt;
The Phidget Java libraries depend on the C libraries being installed as explained on the main [[OS - Linux | Linux page]].  If you browse around within the phidget21.jar archive, you will find Java class files (too many to reasonably list here) that have names related to the devices they provide an API for.&lt;br /&gt;
&lt;br /&gt;
These Java class files use the functions available in the &#039;&#039;dynamic&#039;&#039; Phidget21 C-language library on Linux.  Dynamic libraries end with {{Code|.so}}, and so the C library that the Phidget Java class files use is {{Code|/usr/lib/libphidget21.so}}.&lt;br /&gt;
&lt;br /&gt;
===Javac (Command Line)===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Linux gets somewhat complicated in that two Java compilers exist: {{Code|openjdk}} and {{Code|gcj}}.  Furthermore, a given IDE can &#039;&#039;usually&#039;&#039; use either compiler. That being said, we only offer support here for openJDK and IDEs running openJDK.&lt;br /&gt;
&lt;br /&gt;
To find out which type of compiler your computer has, use the {{Code|-version}} option on the command line.  You can use the same option for your runtime environment (interpreter):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
$&amp;gt; java -version&lt;br /&gt;
java version &amp;quot;1.6.0_23&amp;quot;&lt;br /&gt;
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.1)&lt;br /&gt;
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)&lt;br /&gt;
&lt;br /&gt;
$&amp;gt; javac -version&lt;br /&gt;
javac 1.6.0_23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The good news is that you can have both {{Code|openjdk}} and {{Code|gcj}} on your machine, co-habitating happily.  There can be only one linked java and javac in {{Code|/usr/bin/}} however, and so this will correspond to whichever java compiler and interpreter you installed last.&lt;br /&gt;
&lt;br /&gt;
If you do not have {{Code|openjdk}} installed already (this is the default Java installation for most Linux machines, so you will probably know), and you choose to install it for Phidget purposes, it is important is that the {{Code|java}} version be greater than the {{Code|javac}} version.  Otherwise, your runtime environment will consider the stuff your compiler produces to be newfangled nonsense.  So when installing Java from a repository, you should install both the jdk and the jre.  These are, unfortunately, usually separate packages in a repository (e.g. {{Code|openjdk-7-jre}} and {{Code|openjdk-7-jdk}}).&lt;br /&gt;
&lt;br /&gt;
The simple examples in Java are meant to be compiled and run on the command line.  The example package includes a {{Code|Makefile}} so you can either make all of the examples at once, with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
make all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...Or you can make them individually.  You can either use:&lt;br /&gt;
* The HelloWorld example, which will work with any Phidget, or&lt;br /&gt;
* The example with the name that corresponds to the family (software object) of your Phidget hardware.  &lt;br /&gt;
{{FindYourDevice}}  Once you&#039;ve identified the right example - say, {{Code|HelloWorld.java}} - compile it on the command line with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar HelloWorld.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run the example on a Linux machine [[OS - Linux#Setting udev Rules| without your udev USB rules set]], you will need to run the Java example as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo java -classpath .:phidget21.jar HelloWorld&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
You&#039;ll note that the Phidget Java library file {{Code|phidget21.jar}} needs to be explicitly linked at both points in the compile and run process.  Alternatively, you can make a jar file which includes the Phidget Java library.  This process takes two steps, the first of which is creating a text file called {{Code|MyProgram.mf}}, where {{Code|MyProgram}} is replaced by the name of your main class in both the filename and the text below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: MyProgram&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; The manifest file should end with a carriage return. So, there should be an extra line at the bottom of the file.&lt;br /&gt;
&lt;br /&gt;
After creating the manifest file, you can use the {{Code|jar}} function to create one self-contained file with your classes and the correct classpath.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar –cfm MyProgram.jar MyProgram.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If porting this for an external system, such as one that your customer would be running, the Phidget library would need to be compiled and distributed along with the {{Code|.jar}}.  Although we do not directly support this, if you are interested in how to construct this, we provide both a distribution example and information on cross-compiling:&lt;br /&gt;
* The [[Language - Android Java | Android Java]] libraries have an ARM-compiled {{Code|libphidget21.so}} file included, as an example of distributing a compiled libphidget21.so with the jar file&lt;br /&gt;
* The [[OS - Linux#Cross-Compiling with a Custom Toolchain|Linux page]] has more detail for compiling the Phidget C Libraries for an external target.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
We offer in-depth tutorials on using our examples in NetBeans and Eclipse in the [[#NetBeans|Windows NetBeans]] and [[#Eclipse|Windows Eclipse]] sections.&lt;br /&gt;
&lt;br /&gt;
As our full examples are written with NetBeans, but NetBeans is not part of the standard Linux package repository, we offer installation instructions here before referring to the Windows sections.&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
&lt;br /&gt;
Although Eclipse is standard in the Debian/Ubuntu package repository, NetBeans is no longer standard.  What is more, Netbeans does not install by default into a folder within your path.  As our Phidget full Java examples are written using NetBeans, we provide basic installation instructions here so you can actually run them.&lt;br /&gt;
&lt;br /&gt;
To install NetBeans:&lt;br /&gt;
&lt;br /&gt;
1. Download the install script from website: [http://netbeans.org/downloads/ http://netbeans.org/downloads/]&amp;lt;br&amp;gt;&lt;br /&gt;
2. Change the permissions of the downloaded file to be executable.  Usually, this is something like:&lt;br /&gt;
:{{Code|chmod +x netbeans-7.1-ml-javase-linux.sh}}&amp;lt;br&amp;gt;&lt;br /&gt;
3. Run the downloaded file as a script. (This will result in a GUI interaction that walks you through installation.)&amp;lt;br&amp;gt;&lt;br /&gt;
4. To find the location where the NetBeans installation occurred, run:&amp;lt;br&amp;gt;&lt;br /&gt;
:{{Code|updatedb}}&lt;br /&gt;
:{{Code|locate netbeans | grep bin}}&amp;lt;br&amp;gt;&lt;br /&gt;
5. Usually, the location of the binary is {{Code|/usr/local/netbeans-7.1/bin/netbeans}}, where 7.1 is the installed version.&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Once you have NetBeans installed, running our examples will be very similar to the process described in the [[#NetBeans|Windows NetBeans]] section.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#NetBeans| Windows NetBeans]] section for instructions if you are unfamiliar with NetBeans.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The [[#Follow the Examples|teaching]] section - which describes the examples - also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  This teaching section has resources for you to learn from the examples and write your own.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing Java code will be our Java API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in Java|[http://www.phidgets.com/documentation/JavaDoc.zip Java API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In Java, it is easiest if you name these &#039;&#039;&#039;event&#039;&#039;&#039; functions the same as in our examples.  You can change the main function pointer variable name, but none of the other names.  Our examples show how to immediately hook these functions into the events that will call them &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
In the example code, the event functions common to all Phidgets are called things like &#039;&#039;&#039;AttachHandler()&#039;&#039;&#039; and &#039;&#039;&#039;DetachHandler()&#039;&#039;&#039;, etc.&amp;lt;br&amp;gt;&lt;br /&gt;
But some event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.  Some &#039;get data&#039; functions are also specific to each device.&lt;br /&gt;
|Creating a Phidget software object in Java - when you are not using the Manager - is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating a {{Code|SpatialPhidget}} object.  The device-specific examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The software object provides device specific methods which are available from the API for your specific Phidget.|&lt;br /&gt;
[http://www.phidgets.com/documentation/JavaDoc.zip Java API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
When programming in Java, you&#039;re in luck.  All of our code snippet examples on our [[General Phidget Programming]] page are in both C++ and Java.  Therefore, we do not include any here, because that page is much more in-depth, and you won&#039;t have to have two pages open at once.  So head over there, and start writing code!&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
None yet.&lt;/div&gt;</summary>
		<author><name>192.168.3.183</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=19804</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=19804"/>
		<updated>2012-05-17T17:46:56Z</updated>

		<summary type="html">&lt;p&gt;192.168.3.183: /* Eclipse */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-Java.png|64x64px|link=|alt=Java]]|Java is a modern, object-oriented programming language maintained by Oracle.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|Java|the complete Phidget API, including events|all Phidget devices.|the {{Code|javac}} command line compiler as well as in integrated development environments(IDEs) such as [[#NetBeans | NetBeans]] and [[#Eclipse | Eclipse]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
&lt;br /&gt;
{{QuickDownloads|Java|&lt;br /&gt;
{{APIQuickDownloads|http://www.phidgets.com/documentation/JavaDoc.zip}}|&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/JavaJNI.zip|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|http://www.phidgets.com/downloads/libraries/phidget21jar.zip|Java|(phidget21.jar)}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with Java==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
Java programs on Windows depend on two files, which the installers in the [[#Libraries and Drivers | Quick Downloads]] section put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.  &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.jar}}&amp;lt;/b&amp;gt; is the Phidget Java library for JDK &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.4.2&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. So, you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. For more information, please see the section for your specific compiler/environment. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the [http://www.phidgets.com/downloads/libraries/phidget21-x86.zip {{Code|phidget21.dll}}] as well as the [http://www.phidgets.com/downloads/libraries/phidget21jar_2.1.8.20120131.zip {{Code|phidget21.jar}}] and manually install them where you want; refer to our [[OS_-_Windows#Manual_File_Installation|Manual Installation Instructions]].&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each compiler below.&lt;br /&gt;
&lt;br /&gt;
You can program Phidgets with Java in command line with the {{Code|javac}} compiler as well as in IDEs such as NetBeans and Eclipse. &lt;br /&gt;
&lt;br /&gt;
===Javac (Command Line)===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip example] and unpack them into a folder. Here, you can find an example program called HelloWorld which will work with any Phidget.  You can also find example programs for all the devices. {{FindYourDevice}} Please only use the simple examples. The full examples are intended for the [[#NetBeans | NetBeans IDE]].&lt;br /&gt;
&lt;br /&gt;
Ensure that the {{Code|phidget21.jar}} is in the same directory as the source code.&lt;br /&gt;
&lt;br /&gt;
To compile in Windows command prompt:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .;phidget21.jar example.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create Java bytecode in the form of {{Code|.class}} files. Type the following to run the program:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .;phidget21.jar example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you wish, you can compile the project as a {{Code|.jar}} so there are fewer files to maintain. The [http://www.oracle.com/java Java SDK] provides the {{Code|jar}} utility which packages all the {{Code|.class}} files into a single {{Code|.jar}} file. &lt;br /&gt;
To begin, you will have to provide a Manifest file to indicate the program entry point. With your favourite text editor, create a new file with the following content:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;  &lt;br /&gt;
Ensure that the file ends in a single new line or a carriage return character. &lt;br /&gt;
Save the file as {{Code|example.mf}} and place it in the same directory as the other {{Code|.class}} files.&lt;br /&gt;
Next, create the .{{Code|jar}} with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar -cfm example.jar example.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Afterwards, you can run the {{Code|.jar}} with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -jar example.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#Use Our Examples| previous]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
You first download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip examples], unpack them into a folder, and then find the source code for your device. {{FindYourDevice}} The full examples were written in NetBeans, so the rest of this section will use these examples. To use the simple examples, you will have to import the source code into a new NetBeans project. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Open Project.PNG|link=|alt=Open Project]]&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Click on Run &amp;amp;rarr; Run Project. The project, by default tries to find the {{Code|phidget21.jar}} in {{Code|..\..\lib}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Create a new Java application project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget Java library. In the projects pane, right click {{Code|Libraries}} and add the {{Code|jar}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Add Jar.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
3. Find and select {{Code|phidget21.jar}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Add Jar 2.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip examples] and unpack them into a folder. Here, you can find an example program called HelloWorld which will work with any Phidget.  You will also find example programs for all the devices. {{FindYourDevice}} &lt;br /&gt;
&lt;br /&gt;
Please use the simple examples. The full examples were written in NetBeans, and are not compatible with Eclipse. The rest of this guide will assume that the simple examples are used. The example source code will be copied into your Eclipse project later on. Keep note of the file name of the example as a Java class will be created with the same name.&lt;br /&gt;
&lt;br /&gt;
2. Generate a new Java project with a descriptive name such as PhidgetTest. Click next.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. On the next screen, go to the libraries panel and add an external {{Code|jar}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Add Jar 1.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
4. Find and select {{Code|phidget21.jar}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Add Jar 2.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
5. Add a new Java class to the project.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Class.PNG|link=|alt=New Class]]&lt;br /&gt;
&lt;br /&gt;
6. Name this class with the same name as the simple example&#039;s name. &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Class 2.PNG|link=|alt=New Class]]&lt;br /&gt;
&lt;br /&gt;
7. Copy and paste the example source code over to the class you created.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
8. The only thing left to do is to run the examples! &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#Use Our Examples 3| Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
The first step in using Java on Mac is to install the Phidget libraries.  Compile and install them as explained on the [[OS - OS X|main Mac OS page]].  That page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
The commands to compile in a OS X and Windows terminal are slightly different. Rather than prefixing {{Code|phidget21.jar}} with a semi-colon( {{Code|;}} ), a colon( {{Code|:}} ) is used.  Make sure that the {{Code|phidget21.jar}} file is in the same directory as the code you are trying to compile.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar example.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, to run the program:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .:phidget21.jar example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can be used on any of the simple examples.  If you are interested in using an IDE then refer to the [[Language - Java#Windows (2000/XP/Vista/7)|Windows]] section for information about setting up Phidgets projects in Eclipse or NetBeans.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
With the method just discussed, notice that you need to link the {{Code|phidget21.jar}} both at compile, and runtime.  An alternative is to make a jar file of your program which includes the Phidget Java library.  To do this first create a manifest file. A manifest is a text file used to define package related data.  Make a text file called {{Code|MyProgram.mf}}, where {{Code|MyProgram}} is replaced by the name of your main class.  Put the following lines into {{Code|MyProgram.mf}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: MyProgram&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; The manifest file should end with a carriage return. So, there should be an extra line at the bottom of the file.&lt;br /&gt;
&lt;br /&gt;
After creating the manifest file, you can use the {{Code|jar}} function to create one self-contained file with your classes and the correct classpath.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar –cfm MyProgram.jar MyProgram.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If porting this for an external system, such as one that your customer would be running, the Phidget library would need to be compiled and distributed along with the {{Code|.jar}}.  Although we do not directly support this, if you are interested in how to construct this, we provide both a distribution example and information on cross-compiling:&lt;br /&gt;
* The [[Language - Android Java | Android Java]] libraries have an ARM-compiled {{Code|libphidget21.so}} file included, as an example of distributing a compiled libphidget21.so with the jar file&lt;br /&gt;
* The [[OS - Linux#Cross-Compiling with a Custom Toolchain|Linux page]] has more detail for compiling the Phidget C Libraries for an external target.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
We offer in-depth tutorials on using our examples in NetBeans and Eclipse in the [[#NetBeans|Windows NetBeans]] and [[#Eclipse|Windows Eclipse]] sections.&lt;br /&gt;
&lt;br /&gt;
As our full examples are written with NetBeans, but NetBeans is not part of the standard OS X application suite., we offer installation instructions here before referring to the Windows sections.&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
To install NetBeans on a Mac, all  you have to do is download the installer from [www.netbeans.org their website] and run it.&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Once you have NetBeans installed, running our examples will be very similar to the process described in the [[#NetBeans|Windows NetBeans]] section.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#NetBeans| Windows NetBeans]] section for instructions if you are unfamiliar with NetBeans.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The [[#Follow the Examples|teaching]] section - which describes the examples - also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
Java has excellent support on Linux - there is an established implementation of the Java compiler and interpreter, and several Integrated Development Environments (IDEs) including NetBeans and Eclipse. &lt;br /&gt;
&lt;br /&gt;
The first step in using Java on Linux is to install the base Phidget libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different basic Phidget library files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
You will also need the [http://www.phidgets.com/downloads/libraries/phidget21jar.zip Phidget Java Libraries (phidget21.jar)].&lt;br /&gt;
&lt;br /&gt;
Once downloaded, the {{Code|phidget21.jar}} library file does not get &#039;installed&#039; (i.e. do not run {{Code| java -jar phidget21.jar}}).  Rather, the library file gets put into the path of whatever program you write, and you will link it via both the java compiler and the java interpreter.  We walk you through this below.&lt;br /&gt;
&lt;br /&gt;
We have two different types of Phidget examples in Java: &lt;br /&gt;
*Simple examples, to be run on the command line, and&lt;br /&gt;
*Full examples, to be run in NetBeans&lt;br /&gt;
&lt;br /&gt;
Both are contained within the [http://www.phidgets.com/downloads/examples/JavaJNI.zip Phidget Java example download package].&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
&lt;br /&gt;
The Phidget Java libraries depend on the C libraries being installed as explained on the main [[OS - Linux | Linux page]].  If you browse around within the phidget21.jar archive, you will find Java class files (too many to reasonably list here) that have names related to the devices they provide an API for.&lt;br /&gt;
&lt;br /&gt;
These Java class files use the functions available in the &#039;&#039;dynamic&#039;&#039; Phidget21 C-language library on Linux.  Dynamic libraries end with {{Code|.so}}, and so the C library that the Phidget Java class files use is {{Code|/usr/lib/libphidget21.so}}.&lt;br /&gt;
&lt;br /&gt;
===Javac (Command Line)===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Linux gets somewhat complicated in that two Java compilers exist: {{Code|openjdk}} and {{Code|gcj}}.  Furthermore, a given IDE can &#039;&#039;usually&#039;&#039; use either compiler. That being said, we only offer support here for openJDK and IDEs running openJDK.&lt;br /&gt;
&lt;br /&gt;
To find out which type of compiler your computer has, use the {{Code|-version}} option on the command line.  You can use the same option for your runtime environment (interpreter):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
$&amp;gt; java -version&lt;br /&gt;
java version &amp;quot;1.6.0_23&amp;quot;&lt;br /&gt;
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.1)&lt;br /&gt;
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)&lt;br /&gt;
&lt;br /&gt;
$&amp;gt; javac -version&lt;br /&gt;
javac 1.6.0_23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The good news is that you can have both {{Code|openjdk}} and {{Code|gcj}} on your machine, co-habitating happily.  There can be only one linked java and javac in {{Code|/usr/bin/}} however, and so this will correspond to whichever java compiler and interpreter you installed last.&lt;br /&gt;
&lt;br /&gt;
If you do not have {{Code|openjdk}} installed already (this is the default Java installation for most Linux machines, so you will probably know), and you choose to install it for Phidget purposes, it is important is that the {{Code|java}} version be greater than the {{Code|javac}} version.  Otherwise, your runtime environment will consider the stuff your compiler produces to be newfangled nonsense.  So when installing Java from a repository, you should install both the jdk and the jre.  These are, unfortunately, usually separate packages in a repository (e.g. {{Code|openjdk-7-jre}} and {{Code|openjdk-7-jdk}}).&lt;br /&gt;
&lt;br /&gt;
The simple examples in Java are meant to be compiled and run on the command line.  The example package includes a {{Code|Makefile}} so you can either make all of the examples at once, with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
make all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...Or you can make them individually.  You can either use:&lt;br /&gt;
* The HelloWorld example, which will work with any Phidget, or&lt;br /&gt;
* The example with the name that corresponds to the family (software object) of your Phidget hardware.  &lt;br /&gt;
{{FindYourDevice}}  Once you&#039;ve identified the right example - say, {{Code|HelloWorld.java}} - compile it on the command line with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar HelloWorld.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run the example on a Linux machine [[OS - Linux#Setting udev Rules| without your udev USB rules set]], you will need to run the Java example as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo java -classpath .:phidget21.jar HelloWorld&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
You&#039;ll note that the Phidget Java library file {{Code|phidget21.jar}} needs to be explicitly linked at both points in the compile and run process.  Alternatively, you can make a jar file which includes the Phidget Java library.  This process takes two steps, the first of which is creating a text file called {{Code|MyProgram.mf}}, where {{Code|MyProgram}} is replaced by the name of your main class in both the filename and the text below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: MyProgram&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; The manifest file should end with a carriage return. So, there should be an extra line at the bottom of the file.&lt;br /&gt;
&lt;br /&gt;
After creating the manifest file, you can use the {{Code|jar}} function to create one self-contained file with your classes and the correct classpath.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar –cfm MyProgram.jar MyProgram.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If porting this for an external system, such as one that your customer would be running, the Phidget library would need to be compiled and distributed along with the {{Code|.jar}}.  Although we do not directly support this, if you are interested in how to construct this, we provide both a distribution example and information on cross-compiling:&lt;br /&gt;
* The [[Language - Android Java | Android Java]] libraries have an ARM-compiled {{Code|libphidget21.so}} file included, as an example of distributing a compiled libphidget21.so with the jar file&lt;br /&gt;
* The [[OS - Linux#Cross-Compiling with a Custom Toolchain|Linux page]] has more detail for compiling the Phidget C Libraries for an external target.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
We offer in-depth tutorials on using our examples in NetBeans and Eclipse in the [[#NetBeans|Windows NetBeans]] and [[#Eclipse|Windows Eclipse]] sections.&lt;br /&gt;
&lt;br /&gt;
As our full examples are written with NetBeans, but NetBeans is not part of the standard Linux package repository, we offer installation instructions here before referring to the Windows sections.&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
&lt;br /&gt;
Although Eclipse is standard in the Debian/Ubuntu package repository, NetBeans is no longer standard.  What is more, Netbeans does not install by default into a folder within your path.  As our Phidget full Java examples are written using NetBeans, we provide basic installation instructions here so you can actually run them.&lt;br /&gt;
&lt;br /&gt;
To install NetBeans:&lt;br /&gt;
&lt;br /&gt;
1. Download the install script from website: [http://netbeans.org/downloads/ http://netbeans.org/downloads/]&amp;lt;br&amp;gt;&lt;br /&gt;
2. Change the permissions of the downloaded file to be executable.  Usually, this is something like:&lt;br /&gt;
:{{Code|chmod +x netbeans-7.1-ml-javase-linux.sh}}&amp;lt;br&amp;gt;&lt;br /&gt;
3. Run the downloaded file as a script. (This will result in a GUI interaction that walks you through installation.)&amp;lt;br&amp;gt;&lt;br /&gt;
4. To find the location where the NetBeans installation occurred, run:&amp;lt;br&amp;gt;&lt;br /&gt;
:{{Code|updatedb}}&lt;br /&gt;
:{{Code|locate netbeans | grep bin}}&amp;lt;br&amp;gt;&lt;br /&gt;
5. Usually, the location of the binary is {{Code|/usr/local/netbeans-7.1/bin/netbeans}}, where 7.1 is the installed version.&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Once you have NetBeans installed, running our examples will be very similar to the process described in the [[#NetBeans|Windows NetBeans]] section.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#NetBeans| Windows NetBeans]] section for instructions if you are unfamiliar with NetBeans.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The [[#Follow the Examples|teaching]] section - which describes the examples - also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  This teaching section has resources for you to learn from the examples and write your own.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing Java code will be our Java API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in Java|[http://www.phidgets.com/documentation/JavaDoc.zip Java API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In Java, it is easiest if you name these &#039;&#039;&#039;event&#039;&#039;&#039; functions the same as in our examples.  You can change the main function pointer variable name, but none of the other names.  Our examples show how to immediately hook these functions into the events that will call them &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
In the example code, the event functions common to all Phidgets are called things like &#039;&#039;&#039;AttachHandler()&#039;&#039;&#039; and &#039;&#039;&#039;DetachHandler()&#039;&#039;&#039;, etc.&amp;lt;br&amp;gt;&lt;br /&gt;
But some event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.  Some &#039;get data&#039; functions are also specific to each device.&lt;br /&gt;
|Creating a Phidget software object in Java - when you are not using the Manager - is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating a {{Code|SpatialPhidget}} object.  The device-specific examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The software object provides device specific methods which are available from the API for your specific Phidget.|&lt;br /&gt;
[http://www.phidgets.com/documentation/JavaDoc.zip Java API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
When programming in Java, you&#039;re in luck.  All of our code snippet examples on our [[General Phidget Programming]] page are in both C++ and Java.  Therefore, we do not include any here, because that page is much more in-depth, and you won&#039;t have to have two pages open at once.  So head over there, and start writing code!&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
None yet.&lt;/div&gt;</summary>
		<author><name>192.168.3.183</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=19803</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=19803"/>
		<updated>2012-05-17T17:41:49Z</updated>

		<summary type="html">&lt;p&gt;192.168.3.183: /* Write Your Own Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-Java.png|64x64px|link=|alt=Java]]|Java is a modern, object-oriented programming language maintained by Oracle.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|Java|the complete Phidget API, including events|all Phidget devices.|the {{Code|javac}} command line compiler as well as in integrated development environments(IDEs) such as [[#NetBeans | NetBeans]] and [[#Eclipse | Eclipse]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
&lt;br /&gt;
{{QuickDownloads|Java|&lt;br /&gt;
{{APIQuickDownloads|http://www.phidgets.com/documentation/JavaDoc.zip}}|&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/JavaJNI.zip|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|http://www.phidgets.com/downloads/libraries/phidget21jar.zip|Java|(phidget21.jar)}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with Java==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
Java programs on Windows depend on two files, which the installers in the [[#Libraries and Drivers | Quick Downloads]] section put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.  &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.jar}}&amp;lt;/b&amp;gt; is the Phidget Java library for JDK &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.4.2&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. So, you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. For more information, please see the section for your specific compiler/environment. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the [http://www.phidgets.com/downloads/libraries/phidget21-x86.zip {{Code|phidget21.dll}}] as well as the [http://www.phidgets.com/downloads/libraries/phidget21jar_2.1.8.20120131.zip {{Code|phidget21.jar}}] and manually install them where you want; refer to our [[OS_-_Windows#Manual_File_Installation|Manual Installation Instructions]].&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each compiler below.&lt;br /&gt;
&lt;br /&gt;
You can program Phidgets with Java in command line with the {{Code|javac}} compiler as well as in IDEs such as NetBeans and Eclipse. &lt;br /&gt;
&lt;br /&gt;
===Javac (Command Line)===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip example] and unpack them into a folder. Here, you can find an example program called HelloWorld which will work with any Phidget.  You can also find example programs for all the devices. {{FindYourDevice}} Please only use the simple examples. The full examples are intended for the [[#NetBeans | NetBeans IDE]].&lt;br /&gt;
&lt;br /&gt;
Ensure that the {{Code|phidget21.jar}} is in the same directory as the source code.&lt;br /&gt;
&lt;br /&gt;
To compile in Windows command prompt:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .;phidget21.jar example.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create Java bytecode in the form of {{Code|.class}} files. Type the following to run the program:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .;phidget21.jar example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you wish, you can compile the project as a {{Code|.jar}} so there are fewer files to maintain. The [http://www.oracle.com/java Java SDK] provides the {{Code|jar}} utility which packages all the {{Code|.class}} files into a single {{Code|.jar}} file. &lt;br /&gt;
To begin, you will have to provide a Manifest file to indicate the program entry point. With your favourite text editor, create a new file with the following content:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;  &lt;br /&gt;
Ensure that the file ends in a single new line or a carriage return character. &lt;br /&gt;
Save the file as {{Code|example.mf}} and place it in the same directory as the other {{Code|.class}} files.&lt;br /&gt;
Next, create the .{{Code|jar}} with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar -cfm example.jar example.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Afterwards, you can run the {{Code|.jar}} with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -jar example.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#Use Our Examples| previous]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
You first download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip examples], unpack them into a folder, and then find the source code for your device. {{FindYourDevice}} The full examples were written in NetBeans, so the rest of this section will use these examples. To use the simple examples, you will have to import the source code into a new NetBeans project. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Open Project.PNG|link=|alt=Open Project]]&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Click on Run &amp;amp;rarr; Run Project. The project, by default tries to find the {{Code|phidget21.jar}} in {{Code|..\..\lib}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Create a new Java application project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget Java library. In the projects pane, right click {{Code|Libraries}} and add the {{Code|jar}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Add Jar.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
3. Find and select {{Code|phidget21.jar}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Add Jar 2.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip examples] and unpack them into a folder. Here, you can find an example program called HelloWorld which will work with any Phidget.  You will also find example programs for all the devices. {{FindYourDevice}} &lt;br /&gt;
&lt;br /&gt;
Please use the simple examples. The full examples were written in NetBeans, and are not compatible with Eclipse. The rest of this guide will assume that the simple examples are used. The example source code will be copied into your Eclipse project later on. Keep note of the file name of the example as a Java class will be created with the same name.&lt;br /&gt;
&lt;br /&gt;
2. Generate a new Java project with a descriptive name such as PhidgetTest. Click next.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. On the next screen, go to the libraries panel and add an external {{Code|jar}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Add Jar 1.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
4. Find and select {{Code|phidget21.jar}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Add Jar 2.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
5. Add a new Java class to the project.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Class.PNG|link=|alt=New Class]]&lt;br /&gt;
&lt;br /&gt;
6. Name this class with the same name as the simple example&#039;s name. &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Class 2.PNG|link=|alt=New Class]]&lt;br /&gt;
&lt;br /&gt;
7. Copy and paste the example source code over to the class you created.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
8. The only thing left to do is to run the examples! &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#Use Our Examples 3| Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
The first step in using Java on Mac is to install the Phidget libraries.  Compile and install them as explained on the [[OS - OS X|main Mac OS page]].  That page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
The commands to compile in a OS X and Windows terminal are slightly different. Rather than prefixing {{Code|phidget21.jar}} with a semi-colon( {{Code|;}} ), a colon( {{Code|:}} ) is used.  Make sure that the {{Code|phidget21.jar}} file is in the same directory as the code you are trying to compile.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar example.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, to run the program:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .:phidget21.jar example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can be used on any of the simple examples.  If you are interested in using an IDE then refer to the [[Language - Java#Windows (2000/XP/Vista/7)|Windows]] section for information about setting up Phidgets projects in Eclipse or NetBeans.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
With the method just discussed, notice that you need to link the {{Code|phidget21.jar}} both at compile, and runtime.  An alternative is to make a jar file of your program which includes the Phidget Java library.  To do this first create a manifest file. A manifest is a text file used to define package related data.  Make a text file called {{Code|MyProgram.mf}}, where {{Code|MyProgram}} is replaced by the name of your main class.  Put the following lines into {{Code|MyProgram.mf}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: MyProgram&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; The manifest file should end with a carriage return. So, there should be an extra line at the bottom of the file.&lt;br /&gt;
&lt;br /&gt;
After creating the manifest file, you can use the {{Code|jar}} function to create one self-contained file with your classes and the correct classpath.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar –cfm MyProgram.jar MyProgram.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If porting this for an external system, such as one that your customer would be running, the Phidget library would need to be compiled and distributed along with the {{Code|.jar}}.  Although we do not directly support this, if you are interested in how to construct this, we provide both a distribution example and information on cross-compiling:&lt;br /&gt;
* The [[Language - Android Java | Android Java]] libraries have an ARM-compiled {{Code|libphidget21.so}} file included, as an example of distributing a compiled libphidget21.so with the jar file&lt;br /&gt;
* The [[OS - Linux#Cross-Compiling with a Custom Toolchain|Linux page]] has more detail for compiling the Phidget C Libraries for an external target.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
We offer in-depth tutorials on using our examples in NetBeans and Eclipse in the [[#NetBeans|Windows NetBeans]] and [[#Eclipse|Windows Eclipse]] sections.&lt;br /&gt;
&lt;br /&gt;
As our full examples are written with NetBeans, but NetBeans is not part of the standard OS X application suite., we offer installation instructions here before referring to the Windows sections.&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
To install NetBeans on a Mac, all  you have to do is download the installer from [www.netbeans.org their website] and run it.&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Once you have NetBeans installed, running our examples will be very similar to the process described in the [[#NetBeans|Windows NetBeans]] section.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#NetBeans| Windows NetBeans]] section for instructions if you are unfamiliar with NetBeans.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The [[#Follow the Examples|teaching]] section - which describes the examples - also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Eclipse==&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
Java has excellent support on Linux - there is an established implementation of the Java compiler and interpreter, and several Integrated Development Environments (IDEs) including NetBeans and Eclipse. &lt;br /&gt;
&lt;br /&gt;
The first step in using Java on Linux is to install the base Phidget libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different basic Phidget library files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
You will also need the [http://www.phidgets.com/downloads/libraries/phidget21jar.zip Phidget Java Libraries (phidget21.jar)].&lt;br /&gt;
&lt;br /&gt;
Once downloaded, the {{Code|phidget21.jar}} library file does not get &#039;installed&#039; (i.e. do not run {{Code| java -jar phidget21.jar}}).  Rather, the library file gets put into the path of whatever program you write, and you will link it via both the java compiler and the java interpreter.  We walk you through this below.&lt;br /&gt;
&lt;br /&gt;
We have two different types of Phidget examples in Java: &lt;br /&gt;
*Simple examples, to be run on the command line, and&lt;br /&gt;
*Full examples, to be run in NetBeans&lt;br /&gt;
&lt;br /&gt;
Both are contained within the [http://www.phidgets.com/downloads/examples/JavaJNI.zip Phidget Java example download package].&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
&lt;br /&gt;
The Phidget Java libraries depend on the C libraries being installed as explained on the main [[OS - Linux | Linux page]].  If you browse around within the phidget21.jar archive, you will find Java class files (too many to reasonably list here) that have names related to the devices they provide an API for.&lt;br /&gt;
&lt;br /&gt;
These Java class files use the functions available in the &#039;&#039;dynamic&#039;&#039; Phidget21 C-language library on Linux.  Dynamic libraries end with {{Code|.so}}, and so the C library that the Phidget Java class files use is {{Code|/usr/lib/libphidget21.so}}.&lt;br /&gt;
&lt;br /&gt;
===Javac (Command Line)===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Linux gets somewhat complicated in that two Java compilers exist: {{Code|openjdk}} and {{Code|gcj}}.  Furthermore, a given IDE can &#039;&#039;usually&#039;&#039; use either compiler. That being said, we only offer support here for openJDK and IDEs running openJDK.&lt;br /&gt;
&lt;br /&gt;
To find out which type of compiler your computer has, use the {{Code|-version}} option on the command line.  You can use the same option for your runtime environment (interpreter):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
$&amp;gt; java -version&lt;br /&gt;
java version &amp;quot;1.6.0_23&amp;quot;&lt;br /&gt;
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.1)&lt;br /&gt;
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)&lt;br /&gt;
&lt;br /&gt;
$&amp;gt; javac -version&lt;br /&gt;
javac 1.6.0_23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The good news is that you can have both {{Code|openjdk}} and {{Code|gcj}} on your machine, co-habitating happily.  There can be only one linked java and javac in {{Code|/usr/bin/}} however, and so this will correspond to whichever java compiler and interpreter you installed last.&lt;br /&gt;
&lt;br /&gt;
If you do not have {{Code|openjdk}} installed already (this is the default Java installation for most Linux machines, so you will probably know), and you choose to install it for Phidget purposes, it is important is that the {{Code|java}} version be greater than the {{Code|javac}} version.  Otherwise, your runtime environment will consider the stuff your compiler produces to be newfangled nonsense.  So when installing Java from a repository, you should install both the jdk and the jre.  These are, unfortunately, usually separate packages in a repository (e.g. {{Code|openjdk-7-jre}} and {{Code|openjdk-7-jdk}}).&lt;br /&gt;
&lt;br /&gt;
The simple examples in Java are meant to be compiled and run on the command line.  The example package includes a {{Code|Makefile}} so you can either make all of the examples at once, with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
make all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...Or you can make them individually.  You can either use:&lt;br /&gt;
* The HelloWorld example, which will work with any Phidget, or&lt;br /&gt;
* The example with the name that corresponds to the family (software object) of your Phidget hardware.  &lt;br /&gt;
{{FindYourDevice}}  Once you&#039;ve identified the right example - say, {{Code|HelloWorld.java}} - compile it on the command line with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar HelloWorld.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run the example on a Linux machine [[OS - Linux#Setting udev Rules| without your udev USB rules set]], you will need to run the Java example as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo java -classpath .:phidget21.jar HelloWorld&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
You&#039;ll note that the Phidget Java library file {{Code|phidget21.jar}} needs to be explicitly linked at both points in the compile and run process.  Alternatively, you can make a jar file which includes the Phidget Java library.  This process takes two steps, the first of which is creating a text file called {{Code|MyProgram.mf}}, where {{Code|MyProgram}} is replaced by the name of your main class in both the filename and the text below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: MyProgram&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; The manifest file should end with a carriage return. So, there should be an extra line at the bottom of the file.&lt;br /&gt;
&lt;br /&gt;
After creating the manifest file, you can use the {{Code|jar}} function to create one self-contained file with your classes and the correct classpath.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar –cfm MyProgram.jar MyProgram.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If porting this for an external system, such as one that your customer would be running, the Phidget library would need to be compiled and distributed along with the {{Code|.jar}}.  Although we do not directly support this, if you are interested in how to construct this, we provide both a distribution example and information on cross-compiling:&lt;br /&gt;
* The [[Language - Android Java | Android Java]] libraries have an ARM-compiled {{Code|libphidget21.so}} file included, as an example of distributing a compiled libphidget21.so with the jar file&lt;br /&gt;
* The [[OS - Linux#Cross-Compiling with a Custom Toolchain|Linux page]] has more detail for compiling the Phidget C Libraries for an external target.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
We offer in-depth tutorials on using our examples in NetBeans and Eclipse in the [[#NetBeans|Windows NetBeans]] and [[#Eclipse|Windows Eclipse]] sections.&lt;br /&gt;
&lt;br /&gt;
As our full examples are written with NetBeans, but NetBeans is not part of the standard Linux package repository, we offer installation instructions here before referring to the Windows sections.&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
&lt;br /&gt;
Although Eclipse is standard in the Debian/Ubuntu package repository, NetBeans is no longer standard.  What is more, Netbeans does not install by default into a folder within your path.  As our Phidget full Java examples are written using NetBeans, we provide basic installation instructions here so you can actually run them.&lt;br /&gt;
&lt;br /&gt;
To install NetBeans:&lt;br /&gt;
&lt;br /&gt;
1. Download the install script from website: [http://netbeans.org/downloads/ http://netbeans.org/downloads/]&amp;lt;br&amp;gt;&lt;br /&gt;
2. Change the permissions of the downloaded file to be executable.  Usually, this is something like:&lt;br /&gt;
:{{Code|chmod +x netbeans-7.1-ml-javase-linux.sh}}&amp;lt;br&amp;gt;&lt;br /&gt;
3. Run the downloaded file as a script. (This will result in a GUI interaction that walks you through installation.)&amp;lt;br&amp;gt;&lt;br /&gt;
4. To find the location where the NetBeans installation occurred, run:&amp;lt;br&amp;gt;&lt;br /&gt;
:{{Code|updatedb}}&lt;br /&gt;
:{{Code|locate netbeans | grep bin}}&amp;lt;br&amp;gt;&lt;br /&gt;
5. Usually, the location of the binary is {{Code|/usr/local/netbeans-7.1/bin/netbeans}}, where 7.1 is the installed version.&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Once you have NetBeans installed, running our examples will be very similar to the process described in the [[#NetBeans|Windows NetBeans]] section.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#NetBeans| Windows NetBeans]] section for instructions if you are unfamiliar with NetBeans.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The [[#Follow the Examples|teaching]] section - which describes the examples - also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  This teaching section has resources for you to learn from the examples and write your own.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing Java code will be our Java API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in Java|[http://www.phidgets.com/documentation/JavaDoc.zip Java API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In Java, it is easiest if you name these &#039;&#039;&#039;event&#039;&#039;&#039; functions the same as in our examples.  You can change the main function pointer variable name, but none of the other names.  Our examples show how to immediately hook these functions into the events that will call them &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
In the example code, the event functions common to all Phidgets are called things like &#039;&#039;&#039;AttachHandler()&#039;&#039;&#039; and &#039;&#039;&#039;DetachHandler()&#039;&#039;&#039;, etc.&amp;lt;br&amp;gt;&lt;br /&gt;
But some event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.  Some &#039;get data&#039; functions are also specific to each device.&lt;br /&gt;
|Creating a Phidget software object in Java - when you are not using the Manager - is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating a {{Code|SpatialPhidget}} object.  The device-specific examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The software object provides device specific methods which are available from the API for your specific Phidget.|&lt;br /&gt;
[http://www.phidgets.com/documentation/JavaDoc.zip Java API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
When programming in Java, you&#039;re in luck.  All of our code snippet examples on our [[General Phidget Programming]] page are in both C++ and Java.  Therefore, we do not include any here, because that page is much more in-depth, and you won&#039;t have to have two pages open at once.  So head over there, and start writing code!&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
None yet.&lt;/div&gt;</summary>
		<author><name>192.168.3.183</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=19802</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=19802"/>
		<updated>2012-05-17T17:03:04Z</updated>

		<summary type="html">&lt;p&gt;192.168.3.183: /* NetBeans */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-Java.png|64x64px|link=|alt=Java]]|Java is a modern, object-oriented programming language maintained by Oracle.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|Java|the complete Phidget API, including events|all Phidget devices.|the {{Code|javac}} command line compiler as well as in integrated development environments(IDEs) such as [[#NetBeans | NetBeans]] and [[#Eclipse | Eclipse]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
&lt;br /&gt;
{{QuickDownloads|Java|&lt;br /&gt;
{{APIQuickDownloads|http://www.phidgets.com/documentation/JavaDoc.zip}}|&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/JavaJNI.zip|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|http://www.phidgets.com/downloads/libraries/phidget21jar.zip|Java|(phidget21.jar)}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with Java==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
Java programs on Windows depend on two files, which the installers in the [[#Libraries and Drivers | Quick Downloads]] section put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.  &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.jar}}&amp;lt;/b&amp;gt; is the Phidget Java library for JDK &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.4.2&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. So, you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. For more information, please see the section for your specific compiler/environment. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the [http://www.phidgets.com/downloads/libraries/phidget21-x86.zip {{Code|phidget21.dll}}] as well as the [http://www.phidgets.com/downloads/libraries/phidget21jar_2.1.8.20120131.zip {{Code|phidget21.jar}}] and manually install them where you want; refer to our [[OS_-_Windows#Manual_File_Installation|Manual Installation Instructions]].&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each compiler below.&lt;br /&gt;
&lt;br /&gt;
You can program Phidgets with Java in command line with the {{Code|javac}} compiler as well as in IDEs such as NetBeans and Eclipse. &lt;br /&gt;
&lt;br /&gt;
===Javac (Command Line)===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip example] and unpack them into a folder. Here, you can find an example program called HelloWorld which will work with any Phidget.  You can also find example programs for all the devices. {{FindYourDevice}} Please only use the simple examples. The full examples are intended for the [[#NetBeans | NetBeans IDE]].&lt;br /&gt;
&lt;br /&gt;
Ensure that the {{Code|phidget21.jar}} is in the same directory as the source code.&lt;br /&gt;
&lt;br /&gt;
To compile in Windows command prompt:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .;phidget21.jar example.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create Java bytecode in the form of {{Code|.class}} files. Type the following to run the program:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .;phidget21.jar example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you wish, you can compile the project as a {{Code|.jar}} so there are fewer files to maintain. The [http://www.oracle.com/java Java SDK] provides the {{Code|jar}} utility which packages all the {{Code|.class}} files into a single {{Code|.jar}} file. &lt;br /&gt;
To begin, you will have to provide a Manifest file to indicate the program entry point. With your favourite text editor, create a new file with the following content:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;  &lt;br /&gt;
Ensure that the file ends in a single new line or a carriage return character. &lt;br /&gt;
Save the file as {{Code|example.mf}} and place it in the same directory as the other {{Code|.class}} files.&lt;br /&gt;
Next, create the .{{Code|jar}} with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar -cfm example.jar example.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Afterwards, you can run the {{Code|.jar}} with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -jar example.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#Use Our Examples| previous]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
You first download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip examples], unpack them into a folder, and then find the source code for your device. {{FindYourDevice}} The full examples were written in NetBeans, so the rest of this section will use these examples. To use the simple examples, you will have to import the source code into a new NetBeans project. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Open Project.PNG|link=|alt=Open Project]]&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Click on Run &amp;amp;rarr; Run Project. The project, by default tries to find the {{Code|phidget21.jar}} in {{Code|..\..\lib}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Create a new Java application project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget Java library. In the projects pane, right click {{Code|Libraries}} and add the {{Code|jar}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Add Jar.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
3. Find and select {{Code|phidget21.jar}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Add Jar 2.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip examples] and unpack them into a folder. Here, you can find an example program called HelloWorld which will work with any Phidget.  You will also find example programs for all the devices. {{FindYourDevice}} &lt;br /&gt;
&lt;br /&gt;
Please use the simple examples. The full examples were written in NetBeans, and are not compatible with Eclipse. The rest of this guide will assume that the simple examples are used. The example source code will be copied into your Eclipse project later on. Keep note of the file name of the example as a Java class will be created with the same name.&lt;br /&gt;
&lt;br /&gt;
2. Generate a new Java project with a descriptive name such as PhidgetTest. Click next.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. On the next screen, go to the libraries panel and add an external {{Code|jar}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Add Jar 1.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
4. Find and select {{Code|phidget21.jar}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Add Jar 2.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
5. Add a new Java class to the project.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Class.PNG|link=|alt=New Class]]&lt;br /&gt;
&lt;br /&gt;
6. Name this class with the same name as the simple example&#039;s name. &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Class 2.PNG|link=|alt=New Class]]&lt;br /&gt;
&lt;br /&gt;
7. Copy and paste the example source code over to the class you created.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
8. The only thing left to do is to run the examples! &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#Use Our Examples 3| Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
The first step in using Java on Mac is to install the Phidget libraries.  Compile and install them as explained on the [[OS - OS X|main Mac OS page]].  That page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
The commands to compile in a OS X and Windows terminal are slightly different. Rather than prefixing {{Code|phidget21.jar}} with a semi-colon( {{Code|;}} ), a colon( {{Code|:}} ) is used.  Make sure that the {{Code|phidget21.jar}} file is in the same directory as the code you are trying to compile.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar example.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, to run the program:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .:phidget21.jar example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can be used on any of the simple examples.  If you are interested in using an IDE then refer to the [[Language - Java#Windows (2000/XP/Vista/7)|Windows]] section for information about setting up Phidgets projects in Eclipse or NetBeans.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
With the method just discussed, notice that you need to link the {{Code|phidget21.jar}} both at compile, and runtime.  An alternative is to make a jar file of your program which includes the Phidget Java library.  To do this first create a manifest file. A manifest is a text file used to define package related data.  Make a text file called {{Code|MyProgram.mf}}, where {{Code|MyProgram}} is replaced by the name of your main class.  Put the following lines into {{Code|MyProgram.mf}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: MyProgram&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; The manifest file should end with a carriage return. So, there should be an extra line at the bottom of the file.&lt;br /&gt;
&lt;br /&gt;
After creating the manifest file, you can use the {{Code|jar}} function to create one self-contained file with your classes and the correct classpath.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar –cfm MyProgram.jar MyProgram.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If porting this for an external system, such as one that your customer would be running, the Phidget library would need to be compiled and distributed along with the {{Code|.jar}}.  Although we do not directly support this, if you are interested in how to construct this, we provide both a distribution example and information on cross-compiling:&lt;br /&gt;
* The [[Language - Android Java | Android Java]] libraries have an ARM-compiled {{Code|libphidget21.so}} file included, as an example of distributing a compiled libphidget21.so with the jar file&lt;br /&gt;
* The [[OS - Linux#Cross-Compiling with a Custom Toolchain|Linux page]] has more detail for compiling the Phidget C Libraries for an external target.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
We offer in-depth tutorials on using our examples in NetBeans and Eclipse in the [[#NetBeans|Windows NetBeans]] and [[#Eclipse|Windows Eclipse]] sections.&lt;br /&gt;
&lt;br /&gt;
As our full examples are written with NetBeans, but NetBeans is not part of the standard OS X application suite., we offer installation instructions here before referring to the Windows sections.&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
To install NetBeans on a Mac, all  you have to do is download the installer from [www.netbeans.org their website] and run it.&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Once you have NetBeans installed, running our examples will be very similar to the process described in the [[#NetBeans|Windows NetBeans]] section.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#NetBeans| Windows NetBeans]] section for instructions if you are unfamiliar with NetBeans.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The [[#Follow the Examples|teaching]] section - which describes the examples - also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
Java has excellent support on Linux - there is an established implementation of the Java compiler and interpreter, and several Integrated Development Environments (IDEs) including NetBeans and Eclipse. &lt;br /&gt;
&lt;br /&gt;
The first step in using Java on Linux is to install the base Phidget libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different basic Phidget library files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
You will also need the [http://www.phidgets.com/downloads/libraries/phidget21jar.zip Phidget Java Libraries (phidget21.jar)].&lt;br /&gt;
&lt;br /&gt;
Once downloaded, the {{Code|phidget21.jar}} library file does not get &#039;installed&#039; (i.e. do not run {{Code| java -jar phidget21.jar}}).  Rather, the library file gets put into the path of whatever program you write, and you will link it via both the java compiler and the java interpreter.  We walk you through this below.&lt;br /&gt;
&lt;br /&gt;
We have two different types of Phidget examples in Java: &lt;br /&gt;
*Simple examples, to be run on the command line, and&lt;br /&gt;
*Full examples, to be run in NetBeans&lt;br /&gt;
&lt;br /&gt;
Both are contained within the [http://www.phidgets.com/downloads/examples/JavaJNI.zip Phidget Java example download package].&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
&lt;br /&gt;
The Phidget Java libraries depend on the C libraries being installed as explained on the main [[OS - Linux | Linux page]].  If you browse around within the phidget21.jar archive, you will find Java class files (too many to reasonably list here) that have names related to the devices they provide an API for.&lt;br /&gt;
&lt;br /&gt;
These Java class files use the functions available in the &#039;&#039;dynamic&#039;&#039; Phidget21 C-language library on Linux.  Dynamic libraries end with {{Code|.so}}, and so the C library that the Phidget Java class files use is {{Code|/usr/lib/libphidget21.so}}.&lt;br /&gt;
&lt;br /&gt;
===Javac (Command Line)===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Linux gets somewhat complicated in that two Java compilers exist: {{Code|openjdk}} and {{Code|gcj}}.  Furthermore, a given IDE can &#039;&#039;usually&#039;&#039; use either compiler. That being said, we only offer support here for openJDK and IDEs running openJDK.&lt;br /&gt;
&lt;br /&gt;
To find out which type of compiler your computer has, use the {{Code|-version}} option on the command line.  You can use the same option for your runtime environment (interpreter):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
$&amp;gt; java -version&lt;br /&gt;
java version &amp;quot;1.6.0_23&amp;quot;&lt;br /&gt;
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.1)&lt;br /&gt;
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)&lt;br /&gt;
&lt;br /&gt;
$&amp;gt; javac -version&lt;br /&gt;
javac 1.6.0_23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The good news is that you can have both {{Code|openjdk}} and {{Code|gcj}} on your machine, co-habitating happily.  There can be only one linked java and javac in {{Code|/usr/bin/}} however, and so this will correspond to whichever java compiler and interpreter you installed last.&lt;br /&gt;
&lt;br /&gt;
If you do not have {{Code|openjdk}} installed already (this is the default Java installation for most Linux machines, so you will probably know), and you choose to install it for Phidget purposes, it is important is that the {{Code|java}} version be greater than the {{Code|javac}} version.  Otherwise, your runtime environment will consider the stuff your compiler produces to be newfangled nonsense.  So when installing Java from a repository, you should install both the jdk and the jre.  These are, unfortunately, usually separate packages in a repository (e.g. {{Code|openjdk-7-jre}} and {{Code|openjdk-7-jdk}}).&lt;br /&gt;
&lt;br /&gt;
The simple examples in Java are meant to be compiled and run on the command line.  The example package includes a {{Code|Makefile}} so you can either make all of the examples at once, with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
make all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...Or you can make them individually.  You can either use:&lt;br /&gt;
* The HelloWorld example, which will work with any Phidget, or&lt;br /&gt;
* The example with the name that corresponds to the family (software object) of your Phidget hardware.  &lt;br /&gt;
{{FindYourDevice}}  Once you&#039;ve identified the right example - say, {{Code|HelloWorld.java}} - compile it on the command line with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar HelloWorld.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run the example on a Linux machine [[OS - Linux#Setting udev Rules| without your udev USB rules set]], you will need to run the Java example as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo java -classpath .:phidget21.jar HelloWorld&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
You&#039;ll note that the Phidget Java library file {{Code|phidget21.jar}} needs to be explicitly linked at both points in the compile and run process.  Alternatively, you can make a jar file which includes the Phidget Java library.  This process takes two steps, the first of which is creating a text file called {{Code|MyProgram.mf}}, where {{Code|MyProgram}} is replaced by the name of your main class in both the filename and the text below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: MyProgram&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; The manifest file should end with a carriage return. So, there should be an extra line at the bottom of the file.&lt;br /&gt;
&lt;br /&gt;
After creating the manifest file, you can use the {{Code|jar}} function to create one self-contained file with your classes and the correct classpath.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar –cfm MyProgram.jar MyProgram.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If porting this for an external system, such as one that your customer would be running, the Phidget library would need to be compiled and distributed along with the {{Code|.jar}}.  Although we do not directly support this, if you are interested in how to construct this, we provide both a distribution example and information on cross-compiling:&lt;br /&gt;
* The [[Language - Android Java | Android Java]] libraries have an ARM-compiled {{Code|libphidget21.so}} file included, as an example of distributing a compiled libphidget21.so with the jar file&lt;br /&gt;
* The [[OS - Linux#Cross-Compiling with a Custom Toolchain|Linux page]] has more detail for compiling the Phidget C Libraries for an external target.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
We offer in-depth tutorials on using our examples in NetBeans and Eclipse in the [[#NetBeans|Windows NetBeans]] and [[#Eclipse|Windows Eclipse]] sections.&lt;br /&gt;
&lt;br /&gt;
As our full examples are written with NetBeans, but NetBeans is not part of the standard Linux package repository, we offer installation instructions here before referring to the Windows sections.&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
&lt;br /&gt;
Although Eclipse is standard in the Debian/Ubuntu package repository, NetBeans is no longer standard.  What is more, Netbeans does not install by default into a folder within your path.  As our Phidget full Java examples are written using NetBeans, we provide basic installation instructions here so you can actually run them.&lt;br /&gt;
&lt;br /&gt;
To install NetBeans:&lt;br /&gt;
&lt;br /&gt;
1. Download the install script from website: [http://netbeans.org/downloads/ http://netbeans.org/downloads/]&amp;lt;br&amp;gt;&lt;br /&gt;
2. Change the permissions of the downloaded file to be executable.  Usually, this is something like:&lt;br /&gt;
:{{Code|chmod +x netbeans-7.1-ml-javase-linux.sh}}&amp;lt;br&amp;gt;&lt;br /&gt;
3. Run the downloaded file as a script. (This will result in a GUI interaction that walks you through installation.)&amp;lt;br&amp;gt;&lt;br /&gt;
4. To find the location where the NetBeans installation occurred, run:&amp;lt;br&amp;gt;&lt;br /&gt;
:{{Code|updatedb}}&lt;br /&gt;
:{{Code|locate netbeans | grep bin}}&amp;lt;br&amp;gt;&lt;br /&gt;
5. Usually, the location of the binary is {{Code|/usr/local/netbeans-7.1/bin/netbeans}}, where 7.1 is the installed version.&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Once you have NetBeans installed, running our examples will be very similar to the process described in the [[#NetBeans|Windows NetBeans]] section.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#NetBeans| Windows NetBeans]] section for instructions if you are unfamiliar with NetBeans.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The [[#Follow the Examples|teaching]] section - which describes the examples - also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  This teaching section has resources for you to learn from the examples and write your own.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing Java code will be our Java API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in Java|[http://www.phidgets.com/documentation/JavaDoc.zip Java API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In Java, it is easiest if you name these &#039;&#039;&#039;event&#039;&#039;&#039; functions the same as in our examples.  You can change the main function pointer variable name, but none of the other names.  Our examples show how to immediately hook these functions into the events that will call them &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
In the example code, the event functions common to all Phidgets are called things like &#039;&#039;&#039;AttachHandler()&#039;&#039;&#039; and &#039;&#039;&#039;DetachHandler()&#039;&#039;&#039;, etc.&amp;lt;br&amp;gt;&lt;br /&gt;
But some event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.  Some &#039;get data&#039; functions are also specific to each device.&lt;br /&gt;
|Creating a Phidget software object in Java - when you are not using the Manager - is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating a {{Code|SpatialPhidget}} object.  The device-specific examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The software object provides device specific methods which are available from the API for your specific Phidget.|&lt;br /&gt;
[http://www.phidgets.com/documentation/JavaDoc.zip Java API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
When programming in Java, you&#039;re in luck.  All of our code snippet examples on our [[General Phidget Programming]] page are in both C++ and Java.  Therefore, we do not include any here, because that page is much more in-depth, and you won&#039;t have to have two pages open at once.  So head over there, and start writing code!&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
None yet.&lt;/div&gt;</summary>
		<author><name>192.168.3.183</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=19801</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=19801"/>
		<updated>2012-05-17T16:50:46Z</updated>

		<summary type="html">&lt;p&gt;192.168.3.183: /* Write Your Own Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-Java.png|64x64px|link=|alt=Java]]|Java is a modern, object-oriented programming language maintained by Oracle.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|Java|the complete Phidget API, including events|all Phidget devices.|the {{Code|javac}} command line compiler as well as in integrated development environments(IDEs) such as [[#NetBeans | NetBeans]] and [[#Eclipse | Eclipse]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
&lt;br /&gt;
{{QuickDownloads|Java|&lt;br /&gt;
{{APIQuickDownloads|http://www.phidgets.com/documentation/JavaDoc.zip}}|&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/JavaJNI.zip|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|http://www.phidgets.com/downloads/libraries/phidget21jar.zip|Java|(phidget21.jar)}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with Java==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
Java programs on Windows depend on two files, which the installers in the [[#Libraries and Drivers | Quick Downloads]] section put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.  &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.jar}}&amp;lt;/b&amp;gt; is the Phidget Java library for JDK &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.4.2&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. So, you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. For more information, please see the section for your specific compiler/environment. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the [http://www.phidgets.com/downloads/libraries/phidget21-x86.zip {{Code|phidget21.dll}}] as well as the [http://www.phidgets.com/downloads/libraries/phidget21jar_2.1.8.20120131.zip {{Code|phidget21.jar}}] and manually install them where you want; refer to our [[OS_-_Windows#Manual_File_Installation|Manual Installation Instructions]].&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each compiler below.&lt;br /&gt;
&lt;br /&gt;
You can program Phidgets with Java in command line with the {{Code|javac}} compiler as well as in IDEs such as NetBeans and Eclipse. &lt;br /&gt;
&lt;br /&gt;
===Javac (Command Line)===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip example] and unpack them into a folder. Here, you can find an example program called HelloWorld which will work with any Phidget.  You can also find example programs for all the devices. {{FindYourDevice}} Please only use the simple examples. The full examples are intended for the [[#NetBeans | NetBeans IDE]].&lt;br /&gt;
&lt;br /&gt;
Ensure that the {{Code|phidget21.jar}} is in the same directory as the source code.&lt;br /&gt;
&lt;br /&gt;
To compile in Windows command prompt:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .;phidget21.jar example.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create Java bytecode in the form of {{Code|.class}} files. Type the following to run the program:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .;phidget21.jar example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you wish, you can compile the project as a {{Code|.jar}} so there are fewer files to maintain. The [http://www.oracle.com/java Java SDK] provides the {{Code|jar}} utility which packages all the {{Code|.class}} files into a single {{Code|.jar}} file. &lt;br /&gt;
To begin, you will have to provide a Manifest file to indicate the program entry point. With your favourite text editor, create a new file with the following content:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;  &lt;br /&gt;
Ensure that the file ends in a single new line or a carriage return character. &lt;br /&gt;
Save the file as {{Code|example.mf}} and place it in the same directory as the other {{Code|.class}} files.&lt;br /&gt;
Next, create the .{{Code|jar}} with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar -cfm example.jar example.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Afterwards, you can run the {{Code|.jar}} with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -jar example.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#Use Our Examples| previous]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
You first download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip examples], unpack them into a folder, and then find the source code for your device. {{FindYourDevice}} The full examples were written in NetBeans, so the rest of this section will use these examples. To use the simple examples, you will have to import the source code into a new NetBeans project. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Open Project.PNG|link=|alt=Open Project]]&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Click on Run &amp;amp;rarr; Run Project. The project, by default tries to find the {{Code|phidget21.jar}} in {{Code|..\..\lib}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Create a new Java application project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget Java library. In the projects pane, right click {{Code|Libraries}} and add the {{Code|jar}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Add Jar.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
3. Find and select {{Code|phidget21.jar}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Add Jar 2.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip examples] and unpack them into a folder. Here, you can find an example program called HelloWorld which will work with any Phidget.  You will also find example programs for all the devices. {{FindYourDevice}} &lt;br /&gt;
&lt;br /&gt;
Please use the simple examples. The full examples were written in NetBeans, and are not compatible with Eclipse. The rest of this guide will assume that the simple examples are used. The example source code will be copied into your Eclipse project later on. Keep note of the file name of the example as a Java class will be created with the same name.&lt;br /&gt;
&lt;br /&gt;
2. Generate a new Java project with a descriptive name such as PhidgetTest. Click next.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. On the next screen, go to the libraries panel and add an external {{Code|jar}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Add Jar 1.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
4. Find and select {{Code|phidget21.jar}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Add Jar 2.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
5. Add a new Java class to the project.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Class.PNG|link=|alt=New Class]]&lt;br /&gt;
&lt;br /&gt;
6. Name this class with the same name as the simple example&#039;s name. &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Class 2.PNG|link=|alt=New Class]]&lt;br /&gt;
&lt;br /&gt;
7. Copy and paste the example source code over to the class you created.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
8. The only thing left to do is to run the examples! &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#Use Our Examples 3| Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
The first step in using Java on Mac is to install the Phidget libraries.  Compile and install them as explained on the [[OS - OS X|main Mac OS page]].  That page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
The commands to compile in a OS X and Windows terminal are slightly different. Rather than prefixing {{Code|phidget21.jar}} with a semi-colon( {{Code|;}} ), a colon( {{Code|:}} ) is used.  Make sure that the {{Code|phidget21.jar}} file is in the same directory as the code you are trying to compile.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar example.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, to run the program:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .:phidget21.jar example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can be used on any of the simple examples.  If you are interested in using an IDE then refer to the [[Language - Java#Windows (2000/XP/Vista/7)|Windows]] section for information about setting up Phidgets projects in Eclipse or NetBeans.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
With the method just discussed, notice that you need to link the {{Code|phidget21.jar}} both at compile, and runtime.  An alternative is to make a jar file of your program which includes the Phidget Java library.  To do this first create a manifest file. A manifest is a text file used to define package related data.  Make a text file called {{Code|MyProgram.mf}}, where {{Code|MyProgram}} is replaced by the name of your main class.  Put the following lines into {{Code|MyProgram.mf}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: MyProgram&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; The manifest file should end with a carriage return. So, there should be an extra line at the bottom of the file.&lt;br /&gt;
&lt;br /&gt;
After creating the manifest file, you can use the {{Code|jar}} function to create one self-contained file with your classes and the correct classpath.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar –cfm MyProgram.jar MyProgram.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If porting this for an external system, such as one that your customer would be running, the Phidget library would need to be compiled and distributed along with the {{Code|.jar}}.  Although we do not directly support this, if you are interested in how to construct this, we provide both a distribution example and information on cross-compiling:&lt;br /&gt;
* The [[Language - Android Java | Android Java]] libraries have an ARM-compiled {{Code|libphidget21.so}} file included, as an example of distributing a compiled libphidget21.so with the jar file&lt;br /&gt;
* The [[OS - Linux#Cross-Compiling with a Custom Toolchain|Linux page]] has more detail for compiling the Phidget C Libraries for an external target.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
Java has excellent support on Linux - there is an established implementation of the Java compiler and interpreter, and several Integrated Development Environments (IDEs) including NetBeans and Eclipse. &lt;br /&gt;
&lt;br /&gt;
The first step in using Java on Linux is to install the base Phidget libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different basic Phidget library files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
You will also need the [http://www.phidgets.com/downloads/libraries/phidget21jar.zip Phidget Java Libraries (phidget21.jar)].&lt;br /&gt;
&lt;br /&gt;
Once downloaded, the {{Code|phidget21.jar}} library file does not get &#039;installed&#039; (i.e. do not run {{Code| java -jar phidget21.jar}}).  Rather, the library file gets put into the path of whatever program you write, and you will link it via both the java compiler and the java interpreter.  We walk you through this below.&lt;br /&gt;
&lt;br /&gt;
We have two different types of Phidget examples in Java: &lt;br /&gt;
*Simple examples, to be run on the command line, and&lt;br /&gt;
*Full examples, to be run in NetBeans&lt;br /&gt;
&lt;br /&gt;
Both are contained within the [http://www.phidgets.com/downloads/examples/JavaJNI.zip Phidget Java example download package].&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
&lt;br /&gt;
The Phidget Java libraries depend on the C libraries being installed as explained on the main [[OS - Linux | Linux page]].  If you browse around within the phidget21.jar archive, you will find Java class files (too many to reasonably list here) that have names related to the devices they provide an API for.&lt;br /&gt;
&lt;br /&gt;
These Java class files use the functions available in the &#039;&#039;dynamic&#039;&#039; Phidget21 C-language library on Linux.  Dynamic libraries end with {{Code|.so}}, and so the C library that the Phidget Java class files use is {{Code|/usr/lib/libphidget21.so}}.&lt;br /&gt;
&lt;br /&gt;
===Javac (Command Line)===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Linux gets somewhat complicated in that two Java compilers exist: {{Code|openjdk}} and {{Code|gcj}}.  Furthermore, a given IDE can &#039;&#039;usually&#039;&#039; use either compiler. That being said, we only offer support here for openJDK and IDEs running openJDK.&lt;br /&gt;
&lt;br /&gt;
To find out which type of compiler your computer has, use the {{Code|-version}} option on the command line.  You can use the same option for your runtime environment (interpreter):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
$&amp;gt; java -version&lt;br /&gt;
java version &amp;quot;1.6.0_23&amp;quot;&lt;br /&gt;
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.1)&lt;br /&gt;
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)&lt;br /&gt;
&lt;br /&gt;
$&amp;gt; javac -version&lt;br /&gt;
javac 1.6.0_23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The good news is that you can have both {{Code|openjdk}} and {{Code|gcj}} on your machine, co-habitating happily.  There can be only one linked java and javac in {{Code|/usr/bin/}} however, and so this will correspond to whichever java compiler and interpreter you installed last.&lt;br /&gt;
&lt;br /&gt;
If you do not have {{Code|openjdk}} installed already (this is the default Java installation for most Linux machines, so you will probably know), and you choose to install it for Phidget purposes, it is important is that the {{Code|java}} version be greater than the {{Code|javac}} version.  Otherwise, your runtime environment will consider the stuff your compiler produces to be newfangled nonsense.  So when installing Java from a repository, you should install both the jdk and the jre.  These are, unfortunately, usually separate packages in a repository (e.g. {{Code|openjdk-7-jre}} and {{Code|openjdk-7-jdk}}).&lt;br /&gt;
&lt;br /&gt;
The simple examples in Java are meant to be compiled and run on the command line.  The example package includes a {{Code|Makefile}} so you can either make all of the examples at once, with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
make all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...Or you can make them individually.  You can either use:&lt;br /&gt;
* The HelloWorld example, which will work with any Phidget, or&lt;br /&gt;
* The example with the name that corresponds to the family (software object) of your Phidget hardware.  &lt;br /&gt;
{{FindYourDevice}}  Once you&#039;ve identified the right example - say, {{Code|HelloWorld.java}} - compile it on the command line with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar HelloWorld.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run the example on a Linux machine [[OS - Linux#Setting udev Rules| without your udev USB rules set]], you will need to run the Java example as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo java -classpath .:phidget21.jar HelloWorld&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
You&#039;ll note that the Phidget Java library file {{Code|phidget21.jar}} needs to be explicitly linked at both points in the compile and run process.  Alternatively, you can make a jar file which includes the Phidget Java library.  This process takes two steps, the first of which is creating a text file called {{Code|MyProgram.mf}}, where {{Code|MyProgram}} is replaced by the name of your main class in both the filename and the text below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: MyProgram&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; The manifest file should end with a carriage return. So, there should be an extra line at the bottom of the file.&lt;br /&gt;
&lt;br /&gt;
After creating the manifest file, you can use the {{Code|jar}} function to create one self-contained file with your classes and the correct classpath.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar –cfm MyProgram.jar MyProgram.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If porting this for an external system, such as one that your customer would be running, the Phidget library would need to be compiled and distributed along with the {{Code|.jar}}.  Although we do not directly support this, if you are interested in how to construct this, we provide both a distribution example and information on cross-compiling:&lt;br /&gt;
* The [[Language - Android Java | Android Java]] libraries have an ARM-compiled {{Code|libphidget21.so}} file included, as an example of distributing a compiled libphidget21.so with the jar file&lt;br /&gt;
* The [[OS - Linux#Cross-Compiling with a Custom Toolchain|Linux page]] has more detail for compiling the Phidget C Libraries for an external target.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
We offer in-depth tutorials on using our examples in NetBeans and Eclipse in the [[#NetBeans|Windows NetBeans]] and [[#Eclipse|Windows Eclipse]] sections.&lt;br /&gt;
&lt;br /&gt;
As our full examples are written with NetBeans, but NetBeans is not part of the standard Linux package repository, we offer installation instructions here before referring to the Windows sections.&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
&lt;br /&gt;
Although Eclipse is standard in the Debian/Ubuntu package repository, NetBeans is no longer standard.  What is more, Netbeans does not install by default into a folder within your path.  As our Phidget full Java examples are written using NetBeans, we provide basic installation instructions here so you can actually run them.&lt;br /&gt;
&lt;br /&gt;
To install NetBeans:&lt;br /&gt;
&lt;br /&gt;
1. Download the install script from website: [http://netbeans.org/downloads/ http://netbeans.org/downloads/]&amp;lt;br&amp;gt;&lt;br /&gt;
2. Change the permissions of the downloaded file to be executable.  Usually, this is something like:&lt;br /&gt;
:{{Code|chmod +x netbeans-7.1-ml-javase-linux.sh}}&amp;lt;br&amp;gt;&lt;br /&gt;
3. Run the downloaded file as a script. (This will result in a GUI interaction that walks you through installation.)&amp;lt;br&amp;gt;&lt;br /&gt;
4. To find the location where the NetBeans installation occurred, run:&amp;lt;br&amp;gt;&lt;br /&gt;
:{{Code|updatedb}}&lt;br /&gt;
:{{Code|locate netbeans | grep bin}}&amp;lt;br&amp;gt;&lt;br /&gt;
5. Usually, the location of the binary is {{Code|/usr/local/netbeans-7.1/bin/netbeans}}, where 7.1 is the installed version.&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Once you have NetBeans installed, running our examples will be very similar to the process described in the [[#NetBeans|Windows NetBeans]] section.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#NetBeans| Windows NetBeans]] section for instructions if you are unfamiliar with NetBeans.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The [[#Follow the Examples|teaching]] section - which describes the examples - also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  This teaching section has resources for you to learn from the examples and write your own.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing Java code will be our Java API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in Java|[http://www.phidgets.com/documentation/JavaDoc.zip Java API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In Java, it is easiest if you name these &#039;&#039;&#039;event&#039;&#039;&#039; functions the same as in our examples.  You can change the main function pointer variable name, but none of the other names.  Our examples show how to immediately hook these functions into the events that will call them &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
In the example code, the event functions common to all Phidgets are called things like &#039;&#039;&#039;AttachHandler()&#039;&#039;&#039; and &#039;&#039;&#039;DetachHandler()&#039;&#039;&#039;, etc.&amp;lt;br&amp;gt;&lt;br /&gt;
But some event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.  Some &#039;get data&#039; functions are also specific to each device.&lt;br /&gt;
|Creating a Phidget software object in Java - when you are not using the Manager - is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating a {{Code|SpatialPhidget}} object.  The device-specific examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The software object provides device specific methods which are available from the API for your specific Phidget.|&lt;br /&gt;
[http://www.phidgets.com/documentation/JavaDoc.zip Java API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
When programming in Java, you&#039;re in luck.  All of our code snippet examples on our [[General Phidget Programming]] page are in both C++ and Java.  Therefore, we do not include any here, because that page is much more in-depth, and you won&#039;t have to have two pages open at once.  So head over there, and start writing code!&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
None yet.&lt;/div&gt;</summary>
		<author><name>192.168.3.183</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=19800</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=19800"/>
		<updated>2012-05-17T16:17:31Z</updated>

		<summary type="html">&lt;p&gt;192.168.3.183: /* Write Your Own Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-Java.png|64x64px|link=|alt=Java]]|Java is a modern, object-oriented programming language maintained by Oracle.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|Java|the complete Phidget API, including events|all Phidget devices.|the {{Code|javac}} command line compiler as well as in integrated development environments(IDEs) such as [[#NetBeans | NetBeans]] and [[#Eclipse | Eclipse]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
&lt;br /&gt;
{{QuickDownloads|Java|&lt;br /&gt;
{{APIQuickDownloads|http://www.phidgets.com/documentation/JavaDoc.zip}}|&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/JavaJNI.zip|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|http://www.phidgets.com/downloads/libraries/phidget21jar.zip|Java|(phidget21.jar)}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with Java==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
Java programs on Windows depend on two files, which the installers in the [[#Libraries and Drivers | Quick Downloads]] section put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.  &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.jar}}&amp;lt;/b&amp;gt; is the Phidget Java library for JDK &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.4.2&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. So, you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. For more information, please see the section for your specific compiler/environment. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the [http://www.phidgets.com/downloads/libraries/phidget21-x86.zip {{Code|phidget21.dll}}] as well as the [http://www.phidgets.com/downloads/libraries/phidget21jar_2.1.8.20120131.zip {{Code|phidget21.jar}}] and manually install them where you want; refer to our [[OS_-_Windows#Manual_File_Installation|Manual Installation Instructions]].&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each compiler below.&lt;br /&gt;
&lt;br /&gt;
You can program Phidgets with Java in command line with the {{Code|javac}} compiler as well as in IDEs such as NetBeans and Eclipse. &lt;br /&gt;
&lt;br /&gt;
===Javac (Command Line)===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip example] and unpack them into a folder. Here, you can find an example program called HelloWorld which will work with any Phidget.  You can also find example programs for all the devices. {{FindYourDevice}} Please only use the simple examples. The full examples are intended for the [[#NetBeans | NetBeans IDE]].&lt;br /&gt;
&lt;br /&gt;
Ensure that the {{Code|phidget21.jar}} is in the same directory as the source code.&lt;br /&gt;
&lt;br /&gt;
To compile in Windows command prompt:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .;phidget21.jar example.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create Java bytecode in the form of {{Code|.class}} files. Type the following to run the program:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .;phidget21.jar example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you wish, you can compile the project as a {{Code|.jar}} so there are fewer files to maintain. The [http://www.oracle.com/java Java SDK] provides the {{Code|jar}} utility which packages all the {{Code|.class}} files into a single {{Code|.jar}} file. &lt;br /&gt;
To begin, you will have to provide a Manifest file to indicate the program entry point. With your favourite text editor, create a new file with the following content:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;  &lt;br /&gt;
Ensure that the file ends in a single new line or a carriage return character. &lt;br /&gt;
Save the file as {{Code|example.mf}} and place it in the same directory as the other {{Code|.class}} files.&lt;br /&gt;
Next, create the .{{Code|jar}} with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar -cfm example.jar example.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Afterwards, you can run the {{Code|.jar}} with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -jar example.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#Use Our Examples| previous]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
You first download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip examples], unpack them into a folder, and then find the source code for your device. {{FindYourDevice}} The full examples were written in NetBeans, so the rest of this section will use these examples. To use the simple examples, you will have to import the source code into a new NetBeans project. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Open Project.PNG|link=|alt=Open Project]]&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Click on Run &amp;amp;rarr; Run Project. The project, by default tries to find the {{Code|phidget21.jar}} in {{Code|..\..\lib}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Create a new Java application project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget Java library. In the projects pane, right click {{Code|Libraries}} and add the {{Code|jar}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Add Jar.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
3. Find and select {{Code|phidget21.jar}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Add Jar 2.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip examples] and unpack them into a folder. Here, you can find an example program called HelloWorld which will work with any Phidget.  You will also find example programs for all the devices. {{FindYourDevice}} &lt;br /&gt;
&lt;br /&gt;
Please use the simple examples. The full examples were written in NetBeans, and are not compatible with Eclipse. The rest of this guide will assume that the simple examples are used. The example source code will be copied into your Eclipse project later on. Keep note of the file name of the example as a Java class will be created with the same name.&lt;br /&gt;
&lt;br /&gt;
2. Generate a new Java project with a descriptive name such as PhidgetTest. Click next.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. On the next screen, go to the libraries panel and add an external {{Code|jar}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Add Jar 1.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
4. Find and select {{Code|phidget21.jar}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Add Jar 2.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
5. Add a new Java class to the project.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Class.PNG|link=|alt=New Class]]&lt;br /&gt;
&lt;br /&gt;
6. Name this class with the same name as the simple example&#039;s name. &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Class 2.PNG|link=|alt=New Class]]&lt;br /&gt;
&lt;br /&gt;
7. Copy and paste the example source code over to the class you created.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
8. The only thing left to do is to run the examples! &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#Use Our Examples 3| Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
The first step in using Java on Mac is to install the Phidget libraries.  Compile and install them as explained on the [[OS - OS X|main Mac OS page]].  That page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
The commands to compile in a OS X and Windows terminal are slightly different. Rather than prefixing {{Code|phidget21.jar}} with a semi-colon( {{Code|;}} ), a colon( {{Code|:}} ) is used.  Make sure that the {{Code|phidget21.jar}} file is in the same directory as the code you are trying to compile.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar example.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, to run the program:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .:phidget21.jar example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can be used on any of the simple examples.  If you are interested in using an IDE then refer to the [[Language - Java#Windows (2000/XP/Vista/7)|Windows]] section for information about setting up Phidgets projects in Eclipse or NetBeans.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
With the method just discussed, notice that you need to link the {{Code|phidget21.jar}} both at compile, and runtime.  An alternative is to make a jar file of your program which includes the Phidget Java library.  To do this first create a manifest file. A manifest is a text file used to define package related data.  Make a text file called {{Code|MyProgram.mf}}, where {{Code|MyProgram}} is replaced by the name of your main class.  Put the following lines into {{Code|MyProgram.mf}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: MyProgram&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; The manifest file should end with a carriage return. So, there should be an extra line at the bottom of the file.&lt;br /&gt;
&lt;br /&gt;
After creating the manifest file, you can use the {{Code|jar}} function to create one self-contained file with your classes and the correct classpath.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar –cfm MyProgram.jar MyProgram.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If porting this for an external system, such as one that your customer would be running, the Phidget library would need to be compiled and distributed along with the {{Code|.jar}}.  Although we do not directly support this, if you are interested in how to construct this, we provide both a distribution example and information on cross-compiling:&lt;br /&gt;
* The [[Language - Android Java | Android Java]] libraries have an ARM-compiled {{Code|libphidget21.so}} file included, as an example of distributing a compiled libphidget21.so with the jar file&lt;br /&gt;
* The [[OS - Linux#Cross-Compiling with a Custom Toolchain|Linux page]] has more detail for compiling the Phidget C Libraries for an external target.&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
Java has excellent support on Linux - there is an established implementation of the Java compiler and interpreter, and several Integrated Development Environments (IDEs) including NetBeans and Eclipse. &lt;br /&gt;
&lt;br /&gt;
The first step in using Java on Linux is to install the base Phidget libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different basic Phidget library files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
You will also need the [http://www.phidgets.com/downloads/libraries/phidget21jar.zip Phidget Java Libraries (phidget21.jar)].&lt;br /&gt;
&lt;br /&gt;
Once downloaded, the {{Code|phidget21.jar}} library file does not get &#039;installed&#039; (i.e. do not run {{Code| java -jar phidget21.jar}}).  Rather, the library file gets put into the path of whatever program you write, and you will link it via both the java compiler and the java interpreter.  We walk you through this below.&lt;br /&gt;
&lt;br /&gt;
We have two different types of Phidget examples in Java: &lt;br /&gt;
*Simple examples, to be run on the command line, and&lt;br /&gt;
*Full examples, to be run in NetBeans&lt;br /&gt;
&lt;br /&gt;
Both are contained within the [http://www.phidgets.com/downloads/examples/JavaJNI.zip Phidget Java example download package].&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
&lt;br /&gt;
The Phidget Java libraries depend on the C libraries being installed as explained on the main [[OS - Linux | Linux page]].  If you browse around within the phidget21.jar archive, you will find Java class files (too many to reasonably list here) that have names related to the devices they provide an API for.&lt;br /&gt;
&lt;br /&gt;
These Java class files use the functions available in the &#039;&#039;dynamic&#039;&#039; Phidget21 C-language library on Linux.  Dynamic libraries end with {{Code|.so}}, and so the C library that the Phidget Java class files use is {{Code|/usr/lib/libphidget21.so}}.&lt;br /&gt;
&lt;br /&gt;
===Javac (Command Line)===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Linux gets somewhat complicated in that two Java compilers exist: {{Code|openjdk}} and {{Code|gcj}}.  Furthermore, a given IDE can &#039;&#039;usually&#039;&#039; use either compiler. That being said, we only offer support here for openJDK and IDEs running openJDK.&lt;br /&gt;
&lt;br /&gt;
To find out which type of compiler your computer has, use the {{Code|-version}} option on the command line.  You can use the same option for your runtime environment (interpreter):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
$&amp;gt; java -version&lt;br /&gt;
java version &amp;quot;1.6.0_23&amp;quot;&lt;br /&gt;
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.1)&lt;br /&gt;
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)&lt;br /&gt;
&lt;br /&gt;
$&amp;gt; javac -version&lt;br /&gt;
javac 1.6.0_23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The good news is that you can have both {{Code|openjdk}} and {{Code|gcj}} on your machine, co-habitating happily.  There can be only one linked java and javac in {{Code|/usr/bin/}} however, and so this will correspond to whichever java compiler and interpreter you installed last.&lt;br /&gt;
&lt;br /&gt;
If you do not have {{Code|openjdk}} installed already (this is the default Java installation for most Linux machines, so you will probably know), and you choose to install it for Phidget purposes, it is important is that the {{Code|java}} version be greater than the {{Code|javac}} version.  Otherwise, your runtime environment will consider the stuff your compiler produces to be newfangled nonsense.  So when installing Java from a repository, you should install both the jdk and the jre.  These are, unfortunately, usually separate packages in a repository (e.g. {{Code|openjdk-7-jre}} and {{Code|openjdk-7-jdk}}).&lt;br /&gt;
&lt;br /&gt;
The simple examples in Java are meant to be compiled and run on the command line.  The example package includes a {{Code|Makefile}} so you can either make all of the examples at once, with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
make all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...Or you can make them individually.  You can either use:&lt;br /&gt;
* The HelloWorld example, which will work with any Phidget, or&lt;br /&gt;
* The example with the name that corresponds to the family (software object) of your Phidget hardware.  &lt;br /&gt;
{{FindYourDevice}}  Once you&#039;ve identified the right example - say, {{Code|HelloWorld.java}} - compile it on the command line with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar HelloWorld.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run the example on a Linux machine [[OS - Linux#Setting udev Rules| without your udev USB rules set]], you will need to run the Java example as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo java -classpath .:phidget21.jar HelloWorld&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
You&#039;ll note that the Phidget Java library file {{Code|phidget21.jar}} needs to be explicitly linked at both points in the compile and run process.  Alternatively, you can make a jar file which includes the Phidget Java library.  This process takes two steps, the first of which is creating a text file called {{Code|MyProgram.mf}}, where {{Code|MyProgram}} is replaced by the name of your main class in both the filename and the text below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: MyProgram&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; The manifest file should end with a carriage return. So, there should be an extra line at the bottom of the file.&lt;br /&gt;
&lt;br /&gt;
After creating the manifest file, you can use the {{Code|jar}} function to create one self-contained file with your classes and the correct classpath.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar –cfm MyProgram.jar MyProgram.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If porting this for an external system, such as one that your customer would be running, the Phidget library would need to be compiled and distributed along with the {{Code|.jar}}.  Although we do not directly support this, if you are interested in how to construct this, we provide both a distribution example and information on cross-compiling:&lt;br /&gt;
* The [[Language - Android Java | Android Java]] libraries have an ARM-compiled {{Code|libphidget21.so}} file included, as an example of distributing a compiled libphidget21.so with the jar file&lt;br /&gt;
* The [[OS - Linux#Cross-Compiling with a Custom Toolchain|Linux page]] has more detail for compiling the Phidget C Libraries for an external target.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
We offer in-depth tutorials on using our examples in NetBeans and Eclipse in the [[#NetBeans|Windows NetBeans]] and [[#Eclipse|Windows Eclipse]] sections.&lt;br /&gt;
&lt;br /&gt;
As our full examples are written with NetBeans, but NetBeans is not part of the standard Linux package repository, we offer installation instructions here before referring to the Windows sections.&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
&lt;br /&gt;
Although Eclipse is standard in the Debian/Ubuntu package repository, NetBeans is no longer standard.  What is more, Netbeans does not install by default into a folder within your path.  As our Phidget full Java examples are written using NetBeans, we provide basic installation instructions here so you can actually run them.&lt;br /&gt;
&lt;br /&gt;
To install NetBeans:&lt;br /&gt;
&lt;br /&gt;
1. Download the install script from website: [http://netbeans.org/downloads/ http://netbeans.org/downloads/]&amp;lt;br&amp;gt;&lt;br /&gt;
2. Change the permissions of the downloaded file to be executable.  Usually, this is something like:&lt;br /&gt;
:{{Code|chmod +x netbeans-7.1-ml-javase-linux.sh}}&amp;lt;br&amp;gt;&lt;br /&gt;
3. Run the downloaded file as a script. (This will result in a GUI interaction that walks you through installation.)&amp;lt;br&amp;gt;&lt;br /&gt;
4. To find the location where the NetBeans installation occurred, run:&amp;lt;br&amp;gt;&lt;br /&gt;
:{{Code|updatedb}}&lt;br /&gt;
:{{Code|locate netbeans | grep bin}}&amp;lt;br&amp;gt;&lt;br /&gt;
5. Usually, the location of the binary is {{Code|/usr/local/netbeans-7.1/bin/netbeans}}, where 7.1 is the installed version.&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Once you have NetBeans installed, running our examples will be very similar to the process described in the [[#NetBeans|Windows NetBeans]] section.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#NetBeans| Windows NetBeans]] section for instructions if you are unfamiliar with NetBeans.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The [[#Follow the Examples|teaching]] section - which describes the examples - also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  This teaching section has resources for you to learn from the examples and write your own.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing Java code will be our Java API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in Java|[http://www.phidgets.com/documentation/JavaDoc.zip Java API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In Java, it is easiest if you name these &#039;&#039;&#039;event&#039;&#039;&#039; functions the same as in our examples.  You can change the main function pointer variable name, but none of the other names.  Our examples show how to immediately hook these functions into the events that will call them &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
In the example code, the event functions common to all Phidgets are called things like &#039;&#039;&#039;AttachHandler()&#039;&#039;&#039; and &#039;&#039;&#039;DetachHandler()&#039;&#039;&#039;, etc.&amp;lt;br&amp;gt;&lt;br /&gt;
But some event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.  Some &#039;get data&#039; functions are also specific to each device.&lt;br /&gt;
|Creating a Phidget software object in Java - when you are not using the Manager - is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating a {{Code|SpatialPhidget}} object.  The device-specific examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The software object provides device specific methods which are available from the API for your specific Phidget.|&lt;br /&gt;
[http://www.phidgets.com/documentation/JavaDoc.zip Java API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
When programming in Java, you&#039;re in luck.  All of our code snippet examples on our [[General Phidget Programming]] page are in both C++ and Java.  Therefore, we do not include any here, because that page is much more in-depth, and you won&#039;t have to have two pages open at once.  So head over there, and start writing code!&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
None yet.&lt;/div&gt;</summary>
		<author><name>192.168.3.183</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=19799</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=19799"/>
		<updated>2012-05-17T16:15:41Z</updated>

		<summary type="html">&lt;p&gt;192.168.3.183: /* Write Your Own Code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-Java.png|64x64px|link=|alt=Java]]|Java is a modern, object-oriented programming language maintained by Oracle.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|Java|the complete Phidget API, including events|all Phidget devices.|the {{Code|javac}} command line compiler as well as in integrated development environments(IDEs) such as [[#NetBeans | NetBeans]] and [[#Eclipse | Eclipse]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
&lt;br /&gt;
{{QuickDownloads|Java|&lt;br /&gt;
{{APIQuickDownloads|http://www.phidgets.com/documentation/JavaDoc.zip}}|&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/JavaJNI.zip|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|http://www.phidgets.com/downloads/libraries/phidget21jar.zip|Java|(phidget21.jar)}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with Java==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
Java programs on Windows depend on two files, which the installers in the [[#Libraries and Drivers | Quick Downloads]] section put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.  &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.jar}}&amp;lt;/b&amp;gt; is the Phidget Java library for JDK &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.4.2&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. So, you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. For more information, please see the section for your specific compiler/environment. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the [http://www.phidgets.com/downloads/libraries/phidget21-x86.zip {{Code|phidget21.dll}}] as well as the [http://www.phidgets.com/downloads/libraries/phidget21jar_2.1.8.20120131.zip {{Code|phidget21.jar}}] and manually install them where you want; refer to our [[OS_-_Windows#Manual_File_Installation|Manual Installation Instructions]].&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each compiler below.&lt;br /&gt;
&lt;br /&gt;
You can program Phidgets with Java in command line with the {{Code|javac}} compiler as well as in IDEs such as NetBeans and Eclipse. &lt;br /&gt;
&lt;br /&gt;
===Javac (Command Line)===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip example] and unpack them into a folder. Here, you can find an example program called HelloWorld which will work with any Phidget.  You can also find example programs for all the devices. {{FindYourDevice}} Please only use the simple examples. The full examples are intended for the [[#NetBeans | NetBeans IDE]].&lt;br /&gt;
&lt;br /&gt;
Ensure that the {{Code|phidget21.jar}} is in the same directory as the source code.&lt;br /&gt;
&lt;br /&gt;
To compile in Windows command prompt:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .;phidget21.jar example.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create Java bytecode in the form of {{Code|.class}} files. Type the following to run the program:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .;phidget21.jar example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you wish, you can compile the project as a {{Code|.jar}} so there are fewer files to maintain. The [http://www.oracle.com/java Java SDK] provides the {{Code|jar}} utility which packages all the {{Code|.class}} files into a single {{Code|.jar}} file. &lt;br /&gt;
To begin, you will have to provide a Manifest file to indicate the program entry point. With your favourite text editor, create a new file with the following content:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;  &lt;br /&gt;
Ensure that the file ends in a single new line or a carriage return character. &lt;br /&gt;
Save the file as {{Code|example.mf}} and place it in the same directory as the other {{Code|.class}} files.&lt;br /&gt;
Next, create the .{{Code|jar}} with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar -cfm example.jar example.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Afterwards, you can run the {{Code|.jar}} with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -jar example.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#Use Our Examples| previous]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
You first download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip examples], unpack them into a folder, and then find the source code for your device. {{FindYourDevice}} The full examples were written in NetBeans, so the rest of this section will use these examples. To use the simple examples, you will have to import the source code into a new NetBeans project. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Open Project.PNG|link=|alt=Open Project]]&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Click on Run &amp;amp;rarr; Run Project. The project, by default tries to find the {{Code|phidget21.jar}} in {{Code|..\..\lib}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Create a new Java application project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget Java library. In the projects pane, right click {{Code|Libraries}} and add the {{Code|jar}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Add Jar.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
3. Find and select {{Code|phidget21.jar}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Add Jar 2.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip examples] and unpack them into a folder. Here, you can find an example program called HelloWorld which will work with any Phidget.  You will also find example programs for all the devices. {{FindYourDevice}} &lt;br /&gt;
&lt;br /&gt;
Please use the simple examples. The full examples were written in NetBeans, and are not compatible with Eclipse. The rest of this guide will assume that the simple examples are used. The example source code will be copied into your Eclipse project later on. Keep note of the file name of the example as a Java class will be created with the same name.&lt;br /&gt;
&lt;br /&gt;
2. Generate a new Java project with a descriptive name such as PhidgetTest. Click next.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. On the next screen, go to the libraries panel and add an external {{Code|jar}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Add Jar 1.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
4. Find and select {{Code|phidget21.jar}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Add Jar 2.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
5. Add a new Java class to the project.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Class.PNG|link=|alt=New Class]]&lt;br /&gt;
&lt;br /&gt;
6. Name this class with the same name as the simple example&#039;s name. &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Class 2.PNG|link=|alt=New Class]]&lt;br /&gt;
&lt;br /&gt;
7. Copy and paste the example source code over to the class you created.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
8. The only thing left to do is to run the examples! &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#Use Our Examples 3| Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
The first step in using Java on Mac is to install the Phidget libraries.  Compile and install them as explained on the [[OS - OS X|main Mac OS page]].  That page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
The commands to compile in a OS X and Windows terminal are slightly different. Rather than prefixing {{Code|phidget21.jar}} with a semi-colon( {{Code|;}} ), a colon( {{Code|:}} ) is used.  Make sure that the {{Code|phidget21.jar}} file is in the same directory as the code you are trying to compile.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar example.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, to run the program:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .:phidget21.jar example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can be used on any of the simple examples.  If you are interested in using an IDE then refer to the [[Language - Java#Windows (2000/XP/Vista/7)|Windows]] section for information about setting up Phidgets projects in Eclipse or NetBeans.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
With the method just discussed, notice that you need to link the {{Code|phidget21.jar}} both at compile, and runtime.  An alternative is to make a jar file of your program which includes the Phidget Java library.  To do this first create a manifest file. A manifest is a text file used to define package related data.  Make a text file called {{Code|MyProgram.mf}}, where {{Code|MyProgram}} is replaced by the name of your main class.  Put the following lines into {{Code|MyProgram.mf}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: MyProgram&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; The manifest file should end with a carriage return. So, there should be an extra line at the bottom of the file.&lt;br /&gt;
&lt;br /&gt;
After creating the manifest file, you can use the {{Code|jar}} function to create one self-contained file with your classes and the correct classpath.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar –cfm MyProgram.jar MyProgram.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If porting this for an external system, such as one that your customer would be running, the Phidget library would need to be compiled and distributed along with the {{Code|.jar}}.  Although we do not directly support this, if you are interested in how to construct this, we provide both a distribution example and information on cross-compiling:&lt;br /&gt;
* The [[Language - Android Java | Android Java]] libraries have an ARM-compiled {{Code|libphidget21.so}} file included, as an example of distributing a compiled libphidget21.so with the jar file&lt;br /&gt;
* The [[OS - Linux#Cross-Compiling with a Custom Toolchain|Linux page]] has more detail for compiling the Phidget C Libraries for an external target.&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
Java has excellent support on Linux - there is an established implementation of the Java compiler and interpreter, and several Integrated Development Environments (IDEs) including NetBeans and Eclipse. &lt;br /&gt;
&lt;br /&gt;
The first step in using Java on Linux is to install the base Phidget libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different basic Phidget library files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
You will also need the [http://www.phidgets.com/downloads/libraries/phidget21jar.zip Phidget Java Libraries (phidget21.jar)].&lt;br /&gt;
&lt;br /&gt;
Once downloaded, the {{Code|phidget21.jar}} library file does not get &#039;installed&#039; (i.e. do not run {{Code| java -jar phidget21.jar}}).  Rather, the library file gets put into the path of whatever program you write, and you will link it via both the java compiler and the java interpreter.  We walk you through this below.&lt;br /&gt;
&lt;br /&gt;
We have two different types of Phidget examples in Java: &lt;br /&gt;
*Simple examples, to be run on the command line, and&lt;br /&gt;
*Full examples, to be run in NetBeans&lt;br /&gt;
&lt;br /&gt;
Both are contained within the [http://www.phidgets.com/downloads/examples/JavaJNI.zip Phidget Java example download package].&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
&lt;br /&gt;
The Phidget Java libraries depend on the C libraries being installed as explained on the main [[OS - Linux | Linux page]].  If you browse around within the phidget21.jar archive, you will find Java class files (too many to reasonably list here) that have names related to the devices they provide an API for.&lt;br /&gt;
&lt;br /&gt;
These Java class files use the functions available in the &#039;&#039;dynamic&#039;&#039; Phidget21 C-language library on Linux.  Dynamic libraries end with {{Code|.so}}, and so the C library that the Phidget Java class files use is {{Code|/usr/lib/libphidget21.so}}.&lt;br /&gt;
&lt;br /&gt;
===Javac (Command Line)===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Linux gets somewhat complicated in that two Java compilers exist: {{Code|openjdk}} and {{Code|gcj}}.  Furthermore, a given IDE can &#039;&#039;usually&#039;&#039; use either compiler. That being said, we only offer support here for openJDK and IDEs running openJDK.&lt;br /&gt;
&lt;br /&gt;
To find out which type of compiler your computer has, use the {{Code|-version}} option on the command line.  You can use the same option for your runtime environment (interpreter):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
$&amp;gt; java -version&lt;br /&gt;
java version &amp;quot;1.6.0_23&amp;quot;&lt;br /&gt;
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.1)&lt;br /&gt;
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)&lt;br /&gt;
&lt;br /&gt;
$&amp;gt; javac -version&lt;br /&gt;
javac 1.6.0_23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The good news is that you can have both {{Code|openjdk}} and {{Code|gcj}} on your machine, co-habitating happily.  There can be only one linked java and javac in {{Code|/usr/bin/}} however, and so this will correspond to whichever java compiler and interpreter you installed last.&lt;br /&gt;
&lt;br /&gt;
If you do not have {{Code|openjdk}} installed already (this is the default Java installation for most Linux machines, so you will probably know), and you choose to install it for Phidget purposes, it is important is that the {{Code|java}} version be greater than the {{Code|javac}} version.  Otherwise, your runtime environment will consider the stuff your compiler produces to be newfangled nonsense.  So when installing Java from a repository, you should install both the jdk and the jre.  These are, unfortunately, usually separate packages in a repository (e.g. {{Code|openjdk-7-jre}} and {{Code|openjdk-7-jdk}}).&lt;br /&gt;
&lt;br /&gt;
The simple examples in Java are meant to be compiled and run on the command line.  The example package includes a {{Code|Makefile}} so you can either make all of the examples at once, with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
make all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...Or you can make them individually.  You can either use:&lt;br /&gt;
* The HelloWorld example, which will work with any Phidget, or&lt;br /&gt;
* The example with the name that corresponds to the family (software object) of your Phidget hardware.  &lt;br /&gt;
{{FindYourDevice}}  Once you&#039;ve identified the right example - say, {{Code|HelloWorld.java}} - compile it on the command line with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar HelloWorld.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run the example on a Linux machine [[OS - Linux#Setting udev Rules| without your udev USB rules set]], you will need to run the Java example as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo java -classpath .:phidget21.jar HelloWorld&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
You&#039;ll note that the Phidget Java library file {{Code|phidget21.jar}} needs to be explicitly linked at both points in the compile and run process.  Alternatively, you can make a jar file which includes the Phidget Java library.  This process takes two steps, the first of which is creating a text file called {{Code|MyProgram.mf}}, where {{Code|MyProgram}} is replaced by the name of your main class in both the filename and the text below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: MyProgram&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; The manifest file should end with a carriage return. So, there should be an extra line at the bottom of the file.&lt;br /&gt;
&lt;br /&gt;
After creating the manifest file, you can use the {{Code|jar}} function to create one self-contained file with your classes and the correct classpath.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar –cfm MyProgram.jar MyProgram.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If porting this for an external system, such as one that your customer would be running, the Phidget library would need to be compiled and distributed along with the {{Code|.jar}}.  Although we do not directly support this, if you are interested in how to construct this, we provide both a distribution example and information on cross-compiling:&lt;br /&gt;
* The [[Language - Android Java | Android Java]] libraries have an ARM-compiled {{Code|libphidget21.so}} file included, as an example of distributing a compiled libphidget21.so with the jar file&lt;br /&gt;
* The [[OS - Linux#Cross-Compiling with a Custom Toolchain|Linux page]] has more detail for compiling the Phidget C Libraries for an external target.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
We offer in-depth tutorials on using our examples in NetBeans and Eclipse in the [[#NetBeans|Windows NetBeans]] and [[#Eclipse|Windows Eclipse]] sections.&lt;br /&gt;
&lt;br /&gt;
As our full examples are written with NetBeans, but NetBeans is not part of the standard Linux package repository, we offer installation instructions here before referring to the Windows sections.&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
&lt;br /&gt;
Although Eclipse is standard in the Debian/Ubuntu package repository, NetBeans is no longer standard.  What is more, Netbeans does not install by default into a folder within your path.  As our Phidget full Java examples are written using NetBeans, we provide basic installation instructions here so you can actually run them.&lt;br /&gt;
&lt;br /&gt;
To install NetBeans:&lt;br /&gt;
&lt;br /&gt;
1. Download the install script from website: [http://netbeans.org/downloads/ http://netbeans.org/downloads/]&amp;lt;br&amp;gt;&lt;br /&gt;
2. Change the permissions of the downloaded file to be executable.  Usually, this is something like:&lt;br /&gt;
:{{Code|chmod +x netbeans-7.1-ml-javase-linux.sh}}&amp;lt;br&amp;gt;&lt;br /&gt;
3. Run the downloaded file as a script. (This will result in a GUI interaction that walks you through installation.)&amp;lt;br&amp;gt;&lt;br /&gt;
4. To find the location where the NetBeans installation occurred, run:&amp;lt;br&amp;gt;&lt;br /&gt;
:{{Code|updatedb}}&lt;br /&gt;
:{{Code|locate netbeans | grep bin}}&amp;lt;br&amp;gt;&lt;br /&gt;
5. Usually, the location of the binary is {{Code|/usr/local/netbeans-7.1/bin/netbeans}}, where 7.1 is the installed version.&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Once you have NetBeans installed, running our examples will be very similar to the process described in the [[#NetBeans|Windows NetBeans]] section.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#NetBeans| Windows NetBeans]] section for instructions if you are unfamiliar with NetBeans.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The [[#Follow the Examples|teaching]] section - which describes the examples - also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  This teaching section has resources for you to learn from the examples and write your own.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing Java code will be our Java API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in Java|[http://www.phidgets.com/documentation/JavaDoc.zip Java API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In Java, it is easiest if you name these &#039;&#039;&#039;event&#039;&#039;&#039; functions the same as in our examples.  You can change the main function pointer variable name, but none of the other names.  Our examples show how to immediately hook these functions into the events that will call them &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
In the example code, the event functions common to all Phidgets are called things like &#039;&#039;&#039;AttachHandler()&#039;&#039;&#039; and &#039;&#039;&#039;DetachHandler()&#039;&#039;&#039;, etc.&amp;lt;br&amp;gt;&lt;br /&gt;
But some event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.  Some &#039;get data&#039; functions are also specific to each device.&lt;br /&gt;
|Creating a Phidget software object in Java - when you are not using the Manager - is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating a {{Code|SpatialPhidget}} object.  The device-specific examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The software object provides device specific methods which are available from the API for your specific Phidget.|&lt;br /&gt;
[http://www.phidgets.com/documentation/JavaDoc.zip Java API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
When programming in Java, you&#039;re in luck.  All of our code snippet examples on our [[General Phidget Programming]] page are in both C++ and Java.  Therefore, we do not include any here, because that page is much more in-depth, and you won&#039;t have to have two pages open at once.  So head over there, and start writing code!&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
None yet.&lt;/div&gt;</summary>
		<author><name>192.168.3.183</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=19798</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=19798"/>
		<updated>2012-05-17T16:00:31Z</updated>

		<summary type="html">&lt;p&gt;192.168.3.183: /* Use Our Examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-Java.png|64x64px|link=|alt=Java]]|Java is a modern, object-oriented programming language maintained by Oracle.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|Java|the complete Phidget API, including events|all Phidget devices.|the {{Code|javac}} command line compiler as well as in integrated development environments(IDEs) such as [[#NetBeans | NetBeans]] and [[#Eclipse | Eclipse]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
&lt;br /&gt;
{{QuickDownloads|Java|&lt;br /&gt;
{{APIQuickDownloads|http://www.phidgets.com/documentation/JavaDoc.zip}}|&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/JavaJNI.zip|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|http://www.phidgets.com/downloads/libraries/phidget21jar.zip|Java|(phidget21.jar)}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with Java==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
Java programs on Windows depend on two files, which the installers in the [[#Libraries and Drivers | Quick Downloads]] section put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.  &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.jar}}&amp;lt;/b&amp;gt; is the Phidget Java library for JDK &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.4.2&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. So, you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. For more information, please see the section for your specific compiler/environment. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the [http://www.phidgets.com/downloads/libraries/phidget21-x86.zip {{Code|phidget21.dll}}] as well as the [http://www.phidgets.com/downloads/libraries/phidget21jar_2.1.8.20120131.zip {{Code|phidget21.jar}}] and manually install them where you want; refer to our [[OS_-_Windows#Manual_File_Installation|Manual Installation Instructions]].&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each compiler below.&lt;br /&gt;
&lt;br /&gt;
You can program Phidgets with Java in command line with the {{Code|javac}} compiler as well as in IDEs such as NetBeans and Eclipse. &lt;br /&gt;
&lt;br /&gt;
===Javac (Command Line)===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip example] and unpack them into a folder. Here, you can find an example program called HelloWorld which will work with any Phidget.  You can also find example programs for all the devices. {{FindYourDevice}} Please only use the simple examples. The full examples are intended for the [[#NetBeans | NetBeans IDE]].&lt;br /&gt;
&lt;br /&gt;
Ensure that the {{Code|phidget21.jar}} is in the same directory as the source code.&lt;br /&gt;
&lt;br /&gt;
To compile in Windows command prompt:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .;phidget21.jar example.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create Java bytecode in the form of {{Code|.class}} files. Type the following to run the program:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .;phidget21.jar example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you wish, you can compile the project as a {{Code|.jar}} so there are fewer files to maintain. The [http://www.oracle.com/java Java SDK] provides the {{Code|jar}} utility which packages all the {{Code|.class}} files into a single {{Code|.jar}} file. &lt;br /&gt;
To begin, you will have to provide a Manifest file to indicate the program entry point. With your favourite text editor, create a new file with the following content:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;  &lt;br /&gt;
Ensure that the file ends in a single new line or a carriage return character. &lt;br /&gt;
Save the file as {{Code|example.mf}} and place it in the same directory as the other {{Code|.class}} files.&lt;br /&gt;
Next, create the .{{Code|jar}} with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar -cfm example.jar example.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Afterwards, you can run the {{Code|.jar}} with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -jar example.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#Use Our Examples| previous]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
You first download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip examples], unpack them into a folder, and then find the source code for your device. {{FindYourDevice}} The full examples were written in NetBeans, so the rest of this section will use these examples. To use the simple examples, you will have to import the source code into a new NetBeans project. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Open Project.PNG|link=|alt=Open Project]]&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Click on Run &amp;amp;rarr; Run Project. The project, by default tries to find the {{Code|phidget21.jar}} in {{Code|..\..\lib}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Create a new Java application project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget Java library. In the projects pane, right click {{Code|Libraries}} and add the {{Code|jar}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Add Jar.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
3. Find and select {{Code|phidget21.jar}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Add Jar 2.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip examples] and unpack them into a folder. Here, you can find an example program called HelloWorld which will work with any Phidget.  You will also find example programs for all the devices. {{FindYourDevice}} &lt;br /&gt;
&lt;br /&gt;
Please use the simple examples. The full examples were written in NetBeans, and are not compatible with Eclipse. The rest of this guide will assume that the simple examples are used. The example source code will be copied into your Eclipse project later on. Keep note of the file name of the example as a Java class will be created with the same name.&lt;br /&gt;
&lt;br /&gt;
2. Generate a new Java project with a descriptive name such as PhidgetTest. Click next.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. On the next screen, go to the libraries panel and add an external {{Code|jar}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Add Jar 1.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
4. Find and select {{Code|phidget21.jar}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Add Jar 2.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
5. Add a new Java class to the project.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Class.PNG|link=|alt=New Class]]&lt;br /&gt;
&lt;br /&gt;
6. Name this class with the same name as the simple example&#039;s name. &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Class 2.PNG|link=|alt=New Class]]&lt;br /&gt;
&lt;br /&gt;
7. Copy and paste the example source code over to the class you created.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
8. The only thing left to do is to run the examples! &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#Use Our Examples 3| Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
The first step in using Java on Mac is to install the Phidget libraries.  Compile and install them as explained on the [[OS - OS X|main Mac OS page]].  That page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
The commands to compile in a OS X and Windows terminal are slightly different. Rather than prefixing {{Code|phidget21.jar}} with a semi-colon( {{Code|;}} ), a colon( {{Code|:}} ) is used.  Make sure that the {{Code|phidget21.jar}} file is in the same directory as the code you are trying to compile.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar example.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, to run the program:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .:phidget21.jar example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can be used on any of the simple examples.  If you are interested in using an IDE then refer to the [[Language - Java#Windows (2000/XP/Vista/7)|Windows]] section for information about setting up Phidgets projects in Eclipse or NetBeans.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
Java has excellent support on Linux - there is an established implementation of the Java compiler and interpreter, and several Integrated Development Environments (IDEs) including NetBeans and Eclipse. &lt;br /&gt;
&lt;br /&gt;
The first step in using Java on Linux is to install the base Phidget libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different basic Phidget library files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
You will also need the [http://www.phidgets.com/downloads/libraries/phidget21jar.zip Phidget Java Libraries (phidget21.jar)].&lt;br /&gt;
&lt;br /&gt;
Once downloaded, the {{Code|phidget21.jar}} library file does not get &#039;installed&#039; (i.e. do not run {{Code| java -jar phidget21.jar}}).  Rather, the library file gets put into the path of whatever program you write, and you will link it via both the java compiler and the java interpreter.  We walk you through this below.&lt;br /&gt;
&lt;br /&gt;
We have two different types of Phidget examples in Java: &lt;br /&gt;
*Simple examples, to be run on the command line, and&lt;br /&gt;
*Full examples, to be run in NetBeans&lt;br /&gt;
&lt;br /&gt;
Both are contained within the [http://www.phidgets.com/downloads/examples/JavaJNI.zip Phidget Java example download package].&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
&lt;br /&gt;
The Phidget Java libraries depend on the C libraries being installed as explained on the main [[OS - Linux | Linux page]].  If you browse around within the phidget21.jar archive, you will find Java class files (too many to reasonably list here) that have names related to the devices they provide an API for.&lt;br /&gt;
&lt;br /&gt;
These Java class files use the functions available in the &#039;&#039;dynamic&#039;&#039; Phidget21 C-language library on Linux.  Dynamic libraries end with {{Code|.so}}, and so the C library that the Phidget Java class files use is {{Code|/usr/lib/libphidget21.so}}.&lt;br /&gt;
&lt;br /&gt;
===Javac (Command Line)===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Linux gets somewhat complicated in that two Java compilers exist: {{Code|openjdk}} and {{Code|gcj}}.  Furthermore, a given IDE can &#039;&#039;usually&#039;&#039; use either compiler. That being said, we only offer support here for openJDK and IDEs running openJDK.&lt;br /&gt;
&lt;br /&gt;
To find out which type of compiler your computer has, use the {{Code|-version}} option on the command line.  You can use the same option for your runtime environment (interpreter):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
$&amp;gt; java -version&lt;br /&gt;
java version &amp;quot;1.6.0_23&amp;quot;&lt;br /&gt;
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.1)&lt;br /&gt;
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)&lt;br /&gt;
&lt;br /&gt;
$&amp;gt; javac -version&lt;br /&gt;
javac 1.6.0_23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The good news is that you can have both {{Code|openjdk}} and {{Code|gcj}} on your machine, co-habitating happily.  There can be only one linked java and javac in {{Code|/usr/bin/}} however, and so this will correspond to whichever java compiler and interpreter you installed last.&lt;br /&gt;
&lt;br /&gt;
If you do not have {{Code|openjdk}} installed already (this is the default Java installation for most Linux machines, so you will probably know), and you choose to install it for Phidget purposes, it is important is that the {{Code|java}} version be greater than the {{Code|javac}} version.  Otherwise, your runtime environment will consider the stuff your compiler produces to be newfangled nonsense.  So when installing Java from a repository, you should install both the jdk and the jre.  These are, unfortunately, usually separate packages in a repository (e.g. {{Code|openjdk-7-jre}} and {{Code|openjdk-7-jdk}}).&lt;br /&gt;
&lt;br /&gt;
The simple examples in Java are meant to be compiled and run on the command line.  The example package includes a {{Code|Makefile}} so you can either make all of the examples at once, with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
make all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...Or you can make them individually.  You can either use:&lt;br /&gt;
* The HelloWorld example, which will work with any Phidget, or&lt;br /&gt;
* The example with the name that corresponds to the family (software object) of your Phidget hardware.  &lt;br /&gt;
{{FindYourDevice}}  Once you&#039;ve identified the right example - say, {{Code|HelloWorld.java}} - compile it on the command line with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar HelloWorld.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run the example on a Linux machine [[OS - Linux#Setting udev Rules| without your udev USB rules set]], you will need to run the Java example as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo java -classpath .:phidget21.jar HelloWorld&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
You&#039;ll note that the Phidget Java library file {{Code|phidget21.jar}} needs to be explicitly linked at both points in the compile and run process.  Alternatively, you can make a jar file which includes the Phidget Java library.  This process takes two steps, the first of which is creating a text file called {{Code|MyProgram.mf}}, where {{Code|MyProgram}} is replaced by the name of your main class in both the filename and the text below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: MyProgram&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; The manifest file should end with a carriage return. So, there should be an extra line at the bottom of the file.&lt;br /&gt;
&lt;br /&gt;
After creating the manifest file, you can use the {{Code|jar}} function to create one self-contained file with your classes and the correct classpath.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar –cfm MyProgram.jar MyProgram.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If porting this for an external system, such as one that your customer would be running, the Phidget library would need to be compiled and distributed along with the {{Code|.jar}}.  Although we do not directly support this, if you are interested in how to construct this, we provide both a distribution example and information on cross-compiling:&lt;br /&gt;
* The [[Language - Android Java | Android Java]] libraries have an ARM-compiled {{Code|libphidget21.so}} file included, as an example of distributing a compiled libphidget21.so with the jar file&lt;br /&gt;
* The [[OS - Linux#Cross-Compiling with a Custom Toolchain|Linux page]] has more detail for compiling the Phidget C Libraries for an external target.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
We offer in-depth tutorials on using our examples in NetBeans and Eclipse in the [[#NetBeans|Windows NetBeans]] and [[#Eclipse|Windows Eclipse]] sections.&lt;br /&gt;
&lt;br /&gt;
As our full examples are written with NetBeans, but NetBeans is not part of the standard Linux package repository, we offer installation instructions here before referring to the Windows sections.&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
&lt;br /&gt;
Although Eclipse is standard in the Debian/Ubuntu package repository, NetBeans is no longer standard.  What is more, Netbeans does not install by default into a folder within your path.  As our Phidget full Java examples are written using NetBeans, we provide basic installation instructions here so you can actually run them.&lt;br /&gt;
&lt;br /&gt;
To install NetBeans:&lt;br /&gt;
&lt;br /&gt;
1. Download the install script from website: [http://netbeans.org/downloads/ http://netbeans.org/downloads/]&amp;lt;br&amp;gt;&lt;br /&gt;
2. Change the permissions of the downloaded file to be executable.  Usually, this is something like:&lt;br /&gt;
:{{Code|chmod +x netbeans-7.1-ml-javase-linux.sh}}&amp;lt;br&amp;gt;&lt;br /&gt;
3. Run the downloaded file as a script. (This will result in a GUI interaction that walks you through installation.)&amp;lt;br&amp;gt;&lt;br /&gt;
4. To find the location where the NetBeans installation occurred, run:&amp;lt;br&amp;gt;&lt;br /&gt;
:{{Code|updatedb}}&lt;br /&gt;
:{{Code|locate netbeans | grep bin}}&amp;lt;br&amp;gt;&lt;br /&gt;
5. Usually, the location of the binary is {{Code|/usr/local/netbeans-7.1/bin/netbeans}}, where 7.1 is the installed version.&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Once you have NetBeans installed, running our examples will be very similar to the process described in the [[#NetBeans|Windows NetBeans]] section.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#NetBeans| Windows NetBeans]] section for instructions if you are unfamiliar with NetBeans.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The [[#Follow the Examples|teaching]] section - which describes the examples - also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  This teaching section has resources for you to learn from the examples and write your own.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing Java code will be our Java API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in Java|[http://www.phidgets.com/documentation/JavaDoc.zip Java API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In Java, it is easiest if you name these &#039;&#039;&#039;event&#039;&#039;&#039; functions the same as in our examples.  You can change the main function pointer variable name, but none of the other names.  Our examples show how to immediately hook these functions into the events that will call them &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
In the example code, the event functions common to all Phidgets are called things like &#039;&#039;&#039;AttachHandler()&#039;&#039;&#039; and &#039;&#039;&#039;DetachHandler()&#039;&#039;&#039;, etc.&amp;lt;br&amp;gt;&lt;br /&gt;
But some event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.  Some &#039;get data&#039; functions are also specific to each device.&lt;br /&gt;
|Creating a Phidget software object in Java - when you are not using the Manager - is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating a {{Code|SpatialPhidget}} object.  The device-specific examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The software object provides device specific methods which are available from the API for your specific Phidget.|&lt;br /&gt;
[http://www.phidgets.com/documentation/JavaDoc.zip Java API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
When programming in Java, you&#039;re in luck.  All of our code snippet examples on our [[General Phidget Programming]] page are in both C++ and Java.  Therefore, we do not include any here, because that page is much more in-depth, and you won&#039;t have to have two pages open at once.  So head over there, and start writing code!&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
None yet.&lt;/div&gt;</summary>
		<author><name>192.168.3.183</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=19797</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=19797"/>
		<updated>2012-05-17T15:59:56Z</updated>

		<summary type="html">&lt;p&gt;192.168.3.183: /* OS X */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-Java.png|64x64px|link=|alt=Java]]|Java is a modern, object-oriented programming language maintained by Oracle.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|Java|the complete Phidget API, including events|all Phidget devices.|the {{Code|javac}} command line compiler as well as in integrated development environments(IDEs) such as [[#NetBeans | NetBeans]] and [[#Eclipse | Eclipse]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
&lt;br /&gt;
{{QuickDownloads|Java|&lt;br /&gt;
{{APIQuickDownloads|http://www.phidgets.com/documentation/JavaDoc.zip}}|&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/JavaJNI.zip|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|http://www.phidgets.com/downloads/libraries/phidget21jar.zip|Java|(phidget21.jar)}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with Java==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
Java programs on Windows depend on two files, which the installers in the [[#Libraries and Drivers | Quick Downloads]] section put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.  &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.jar}}&amp;lt;/b&amp;gt; is the Phidget Java library for JDK &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.4.2&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. So, you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. For more information, please see the section for your specific compiler/environment. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the [http://www.phidgets.com/downloads/libraries/phidget21-x86.zip {{Code|phidget21.dll}}] as well as the [http://www.phidgets.com/downloads/libraries/phidget21jar_2.1.8.20120131.zip {{Code|phidget21.jar}}] and manually install them where you want; refer to our [[OS_-_Windows#Manual_File_Installation|Manual Installation Instructions]].&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each compiler below.&lt;br /&gt;
&lt;br /&gt;
You can program Phidgets with Java in command line with the {{Code|javac}} compiler as well as in IDEs such as NetBeans and Eclipse. &lt;br /&gt;
&lt;br /&gt;
===Javac (Command Line)===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip example] and unpack them into a folder. Here, you can find an example program called HelloWorld which will work with any Phidget.  You can also find example programs for all the devices. {{FindYourDevice}} Please only use the simple examples. The full examples are intended for the [[#NetBeans | NetBeans IDE]].&lt;br /&gt;
&lt;br /&gt;
Ensure that the {{Code|phidget21.jar}} is in the same directory as the source code.&lt;br /&gt;
&lt;br /&gt;
To compile in Windows command prompt:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .;phidget21.jar example.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create Java bytecode in the form of {{Code|.class}} files. Type the following to run the program:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .;phidget21.jar example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you wish, you can compile the project as a {{Code|.jar}} so there are fewer files to maintain. The [http://www.oracle.com/java Java SDK] provides the {{Code|jar}} utility which packages all the {{Code|.class}} files into a single {{Code|.jar}} file. &lt;br /&gt;
To begin, you will have to provide a Manifest file to indicate the program entry point. With your favourite text editor, create a new file with the following content:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;  &lt;br /&gt;
Ensure that the file ends in a single new line or a carriage return character. &lt;br /&gt;
Save the file as {{Code|example.mf}} and place it in the same directory as the other {{Code|.class}} files.&lt;br /&gt;
Next, create the .{{Code|jar}} with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar -cfm example.jar example.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Afterwards, you can run the {{Code|.jar}} with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -jar example.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#Use Our Examples| previous]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
You first download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip examples], unpack them into a folder, and then find the source code for your device. {{FindYourDevice}} The full examples were written in NetBeans, so the rest of this section will use these examples. To use the simple examples, you will have to import the source code into a new NetBeans project. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Open Project.PNG|link=|alt=Open Project]]&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Click on Run &amp;amp;rarr; Run Project. The project, by default tries to find the {{Code|phidget21.jar}} in {{Code|..\..\lib}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Create a new Java application project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget Java library. In the projects pane, right click {{Code|Libraries}} and add the {{Code|jar}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Add Jar.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
3. Find and select {{Code|phidget21.jar}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Add Jar 2.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip examples] and unpack them into a folder. Here, you can find an example program called HelloWorld which will work with any Phidget.  You will also find example programs for all the devices. {{FindYourDevice}} &lt;br /&gt;
&lt;br /&gt;
Please use the simple examples. The full examples were written in NetBeans, and are not compatible with Eclipse. The rest of this guide will assume that the simple examples are used. The example source code will be copied into your Eclipse project later on. Keep note of the file name of the example as a Java class will be created with the same name.&lt;br /&gt;
&lt;br /&gt;
2. Generate a new Java project with a descriptive name such as PhidgetTest. Click next.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. On the next screen, go to the libraries panel and add an external {{Code|jar}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Add Jar 1.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
4. Find and select {{Code|phidget21.jar}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Add Jar 2.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
5. Add a new Java class to the project.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Class.PNG|link=|alt=New Class]]&lt;br /&gt;
&lt;br /&gt;
6. Name this class with the same name as the simple example&#039;s name. &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Class 2.PNG|link=|alt=New Class]]&lt;br /&gt;
&lt;br /&gt;
7. Copy and paste the example source code over to the class you created.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
8. The only thing left to do is to run the examples! &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#Use Our Examples 3| Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
The first step in using Java on Mac is to install the Phidget libraries.  Compile and install them as explained on the [[OS - OS X|main Mac OS page]].  That page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
The commands to compile in a OS X and Windows terminal are slightly different. Rather than prefixing {{Code|phidget21.jar}} with a semi-colon( {{Code|;}} ), a colon( {{Code|:}} ) is used.  Make sure that the {{Code|phidget21.jar}} file is in the same directory as the code you are trying to compile.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar example.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, to run the program:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .:phidget21.jar example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can be used on any of the simple examples.  If you are interested in using an IDE then refer to the [[Language - Java#Windows|Windows (2000/XP/Vista/7)]] section for information about setting up Phidgets projects in Eclipse or NetBeans.  &lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
Java has excellent support on Linux - there is an established implementation of the Java compiler and interpreter, and several Integrated Development Environments (IDEs) including NetBeans and Eclipse. &lt;br /&gt;
&lt;br /&gt;
The first step in using Java on Linux is to install the base Phidget libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different basic Phidget library files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
You will also need the [http://www.phidgets.com/downloads/libraries/phidget21jar.zip Phidget Java Libraries (phidget21.jar)].&lt;br /&gt;
&lt;br /&gt;
Once downloaded, the {{Code|phidget21.jar}} library file does not get &#039;installed&#039; (i.e. do not run {{Code| java -jar phidget21.jar}}).  Rather, the library file gets put into the path of whatever program you write, and you will link it via both the java compiler and the java interpreter.  We walk you through this below.&lt;br /&gt;
&lt;br /&gt;
We have two different types of Phidget examples in Java: &lt;br /&gt;
*Simple examples, to be run on the command line, and&lt;br /&gt;
*Full examples, to be run in NetBeans&lt;br /&gt;
&lt;br /&gt;
Both are contained within the [http://www.phidgets.com/downloads/examples/JavaJNI.zip Phidget Java example download package].&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
&lt;br /&gt;
The Phidget Java libraries depend on the C libraries being installed as explained on the main [[OS - Linux | Linux page]].  If you browse around within the phidget21.jar archive, you will find Java class files (too many to reasonably list here) that have names related to the devices they provide an API for.&lt;br /&gt;
&lt;br /&gt;
These Java class files use the functions available in the &#039;&#039;dynamic&#039;&#039; Phidget21 C-language library on Linux.  Dynamic libraries end with {{Code|.so}}, and so the C library that the Phidget Java class files use is {{Code|/usr/lib/libphidget21.so}}.&lt;br /&gt;
&lt;br /&gt;
===Javac (Command Line)===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Linux gets somewhat complicated in that two Java compilers exist: {{Code|openjdk}} and {{Code|gcj}}.  Furthermore, a given IDE can &#039;&#039;usually&#039;&#039; use either compiler. That being said, we only offer support here for openJDK and IDEs running openJDK.&lt;br /&gt;
&lt;br /&gt;
To find out which type of compiler your computer has, use the {{Code|-version}} option on the command line.  You can use the same option for your runtime environment (interpreter):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
$&amp;gt; java -version&lt;br /&gt;
java version &amp;quot;1.6.0_23&amp;quot;&lt;br /&gt;
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.1)&lt;br /&gt;
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)&lt;br /&gt;
&lt;br /&gt;
$&amp;gt; javac -version&lt;br /&gt;
javac 1.6.0_23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The good news is that you can have both {{Code|openjdk}} and {{Code|gcj}} on your machine, co-habitating happily.  There can be only one linked java and javac in {{Code|/usr/bin/}} however, and so this will correspond to whichever java compiler and interpreter you installed last.&lt;br /&gt;
&lt;br /&gt;
If you do not have {{Code|openjdk}} installed already (this is the default Java installation for most Linux machines, so you will probably know), and you choose to install it for Phidget purposes, it is important is that the {{Code|java}} version be greater than the {{Code|javac}} version.  Otherwise, your runtime environment will consider the stuff your compiler produces to be newfangled nonsense.  So when installing Java from a repository, you should install both the jdk and the jre.  These are, unfortunately, usually separate packages in a repository (e.g. {{Code|openjdk-7-jre}} and {{Code|openjdk-7-jdk}}).&lt;br /&gt;
&lt;br /&gt;
The simple examples in Java are meant to be compiled and run on the command line.  The example package includes a {{Code|Makefile}} so you can either make all of the examples at once, with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
make all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...Or you can make them individually.  You can either use:&lt;br /&gt;
* The HelloWorld example, which will work with any Phidget, or&lt;br /&gt;
* The example with the name that corresponds to the family (software object) of your Phidget hardware.  &lt;br /&gt;
{{FindYourDevice}}  Once you&#039;ve identified the right example - say, {{Code|HelloWorld.java}} - compile it on the command line with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar HelloWorld.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run the example on a Linux machine [[OS - Linux#Setting udev Rules| without your udev USB rules set]], you will need to run the Java example as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo java -classpath .:phidget21.jar HelloWorld&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
You&#039;ll note that the Phidget Java library file {{Code|phidget21.jar}} needs to be explicitly linked at both points in the compile and run process.  Alternatively, you can make a jar file which includes the Phidget Java library.  This process takes two steps, the first of which is creating a text file called {{Code|MyProgram.mf}}, where {{Code|MyProgram}} is replaced by the name of your main class in both the filename and the text below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: MyProgram&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; The manifest file should end with a carriage return. So, there should be an extra line at the bottom of the file.&lt;br /&gt;
&lt;br /&gt;
After creating the manifest file, you can use the {{Code|jar}} function to create one self-contained file with your classes and the correct classpath.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar –cfm MyProgram.jar MyProgram.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If porting this for an external system, such as one that your customer would be running, the Phidget library would need to be compiled and distributed along with the {{Code|.jar}}.  Although we do not directly support this, if you are interested in how to construct this, we provide both a distribution example and information on cross-compiling:&lt;br /&gt;
* The [[Language - Android Java | Android Java]] libraries have an ARM-compiled {{Code|libphidget21.so}} file included, as an example of distributing a compiled libphidget21.so with the jar file&lt;br /&gt;
* The [[OS - Linux#Cross-Compiling with a Custom Toolchain|Linux page]] has more detail for compiling the Phidget C Libraries for an external target.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
We offer in-depth tutorials on using our examples in NetBeans and Eclipse in the [[#NetBeans|Windows NetBeans]] and [[#Eclipse|Windows Eclipse]] sections.&lt;br /&gt;
&lt;br /&gt;
As our full examples are written with NetBeans, but NetBeans is not part of the standard Linux package repository, we offer installation instructions here before referring to the Windows sections.&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
&lt;br /&gt;
Although Eclipse is standard in the Debian/Ubuntu package repository, NetBeans is no longer standard.  What is more, Netbeans does not install by default into a folder within your path.  As our Phidget full Java examples are written using NetBeans, we provide basic installation instructions here so you can actually run them.&lt;br /&gt;
&lt;br /&gt;
To install NetBeans:&lt;br /&gt;
&lt;br /&gt;
1. Download the install script from website: [http://netbeans.org/downloads/ http://netbeans.org/downloads/]&amp;lt;br&amp;gt;&lt;br /&gt;
2. Change the permissions of the downloaded file to be executable.  Usually, this is something like:&lt;br /&gt;
:{{Code|chmod +x netbeans-7.1-ml-javase-linux.sh}}&amp;lt;br&amp;gt;&lt;br /&gt;
3. Run the downloaded file as a script. (This will result in a GUI interaction that walks you through installation.)&amp;lt;br&amp;gt;&lt;br /&gt;
4. To find the location where the NetBeans installation occurred, run:&amp;lt;br&amp;gt;&lt;br /&gt;
:{{Code|updatedb}}&lt;br /&gt;
:{{Code|locate netbeans | grep bin}}&amp;lt;br&amp;gt;&lt;br /&gt;
5. Usually, the location of the binary is {{Code|/usr/local/netbeans-7.1/bin/netbeans}}, where 7.1 is the installed version.&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Once you have NetBeans installed, running our examples will be very similar to the process described in the [[#NetBeans|Windows NetBeans]] section.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#NetBeans| Windows NetBeans]] section for instructions if you are unfamiliar with NetBeans.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The [[#Follow the Examples|teaching]] section - which describes the examples - also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  This teaching section has resources for you to learn from the examples and write your own.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing Java code will be our Java API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in Java|[http://www.phidgets.com/documentation/JavaDoc.zip Java API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In Java, it is easiest if you name these &#039;&#039;&#039;event&#039;&#039;&#039; functions the same as in our examples.  You can change the main function pointer variable name, but none of the other names.  Our examples show how to immediately hook these functions into the events that will call them &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
In the example code, the event functions common to all Phidgets are called things like &#039;&#039;&#039;AttachHandler()&#039;&#039;&#039; and &#039;&#039;&#039;DetachHandler()&#039;&#039;&#039;, etc.&amp;lt;br&amp;gt;&lt;br /&gt;
But some event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.  Some &#039;get data&#039; functions are also specific to each device.&lt;br /&gt;
|Creating a Phidget software object in Java - when you are not using the Manager - is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating a {{Code|SpatialPhidget}} object.  The device-specific examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The software object provides device specific methods which are available from the API for your specific Phidget.|&lt;br /&gt;
[http://www.phidgets.com/documentation/JavaDoc.zip Java API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
When programming in Java, you&#039;re in luck.  All of our code snippet examples on our [[General Phidget Programming]] page are in both C++ and Java.  Therefore, we do not include any here, because that page is much more in-depth, and you won&#039;t have to have two pages open at once.  So head over there, and start writing code!&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
None yet.&lt;/div&gt;</summary>
		<author><name>192.168.3.183</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=19796</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=19796"/>
		<updated>2012-05-17T15:59:23Z</updated>

		<summary type="html">&lt;p&gt;192.168.3.183: /* OS X */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-Java.png|64x64px|link=|alt=Java]]|Java is a modern, object-oriented programming language maintained by Oracle.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|Java|the complete Phidget API, including events|all Phidget devices.|the {{Code|javac}} command line compiler as well as in integrated development environments(IDEs) such as [[#NetBeans | NetBeans]] and [[#Eclipse | Eclipse]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
&lt;br /&gt;
{{QuickDownloads|Java|&lt;br /&gt;
{{APIQuickDownloads|http://www.phidgets.com/documentation/JavaDoc.zip}}|&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/JavaJNI.zip|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|http://www.phidgets.com/downloads/libraries/phidget21jar.zip|Java|(phidget21.jar)}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with Java==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
Java programs on Windows depend on two files, which the installers in the [[#Libraries and Drivers | Quick Downloads]] section put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.  &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.jar}}&amp;lt;/b&amp;gt; is the Phidget Java library for JDK &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.4.2&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. So, you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. For more information, please see the section for your specific compiler/environment. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the [http://www.phidgets.com/downloads/libraries/phidget21-x86.zip {{Code|phidget21.dll}}] as well as the [http://www.phidgets.com/downloads/libraries/phidget21jar_2.1.8.20120131.zip {{Code|phidget21.jar}}] and manually install them where you want; refer to our [[OS_-_Windows#Manual_File_Installation|Manual Installation Instructions]].&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each compiler below.&lt;br /&gt;
&lt;br /&gt;
You can program Phidgets with Java in command line with the {{Code|javac}} compiler as well as in IDEs such as NetBeans and Eclipse. &lt;br /&gt;
&lt;br /&gt;
===Javac (Command Line)===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip example] and unpack them into a folder. Here, you can find an example program called HelloWorld which will work with any Phidget.  You can also find example programs for all the devices. {{FindYourDevice}} Please only use the simple examples. The full examples are intended for the [[#NetBeans | NetBeans IDE]].&lt;br /&gt;
&lt;br /&gt;
Ensure that the {{Code|phidget21.jar}} is in the same directory as the source code.&lt;br /&gt;
&lt;br /&gt;
To compile in Windows command prompt:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .;phidget21.jar example.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create Java bytecode in the form of {{Code|.class}} files. Type the following to run the program:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .;phidget21.jar example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you wish, you can compile the project as a {{Code|.jar}} so there are fewer files to maintain. The [http://www.oracle.com/java Java SDK] provides the {{Code|jar}} utility which packages all the {{Code|.class}} files into a single {{Code|.jar}} file. &lt;br /&gt;
To begin, you will have to provide a Manifest file to indicate the program entry point. With your favourite text editor, create a new file with the following content:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;  &lt;br /&gt;
Ensure that the file ends in a single new line or a carriage return character. &lt;br /&gt;
Save the file as {{Code|example.mf}} and place it in the same directory as the other {{Code|.class}} files.&lt;br /&gt;
Next, create the .{{Code|jar}} with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar -cfm example.jar example.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Afterwards, you can run the {{Code|.jar}} with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -jar example.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#Use Our Examples| previous]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
You first download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip examples], unpack them into a folder, and then find the source code for your device. {{FindYourDevice}} The full examples were written in NetBeans, so the rest of this section will use these examples. To use the simple examples, you will have to import the source code into a new NetBeans project. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Open Project.PNG|link=|alt=Open Project]]&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Click on Run &amp;amp;rarr; Run Project. The project, by default tries to find the {{Code|phidget21.jar}} in {{Code|..\..\lib}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Create a new Java application project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget Java library. In the projects pane, right click {{Code|Libraries}} and add the {{Code|jar}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Add Jar.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
3. Find and select {{Code|phidget21.jar}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Add Jar 2.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip examples] and unpack them into a folder. Here, you can find an example program called HelloWorld which will work with any Phidget.  You will also find example programs for all the devices. {{FindYourDevice}} &lt;br /&gt;
&lt;br /&gt;
Please use the simple examples. The full examples were written in NetBeans, and are not compatible with Eclipse. The rest of this guide will assume that the simple examples are used. The example source code will be copied into your Eclipse project later on. Keep note of the file name of the example as a Java class will be created with the same name.&lt;br /&gt;
&lt;br /&gt;
2. Generate a new Java project with a descriptive name such as PhidgetTest. Click next.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. On the next screen, go to the libraries panel and add an external {{Code|jar}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Add Jar 1.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
4. Find and select {{Code|phidget21.jar}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Add Jar 2.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
5. Add a new Java class to the project.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Class.PNG|link=|alt=New Class]]&lt;br /&gt;
&lt;br /&gt;
6. Name this class with the same name as the simple example&#039;s name. &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Class 2.PNG|link=|alt=New Class]]&lt;br /&gt;
&lt;br /&gt;
7. Copy and paste the example source code over to the class you created.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
8. The only thing left to do is to run the examples! &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#Use Our Examples 3| Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
The first step in using Java on Mac is to install the Phidget libraries.  Compile and install them as explained on the [[OS - OS X|main Mac OS page]].  That page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
The commands to compile in a OS X and Windows terminal are slightly different. Rather than prefixing {{Code|phidget21.jar}} with a semi-colon( {{Code|;}} ), a colon( {{Code|:}} ) is used.  Make sure that the {{Code|phidget21.jar}} file is in the same directory as the code you are trying to compile.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar example.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, to run the program:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .:phidget21.jar example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can be used on any of the simple examples.  If you are interested in using an IDE then refer to the [[Language - Java#Windows|Windows]] section for information about setting up Phidgets projects in Eclipse or NetBeans.  &lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
Java has excellent support on Linux - there is an established implementation of the Java compiler and interpreter, and several Integrated Development Environments (IDEs) including NetBeans and Eclipse. &lt;br /&gt;
&lt;br /&gt;
The first step in using Java on Linux is to install the base Phidget libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different basic Phidget library files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
You will also need the [http://www.phidgets.com/downloads/libraries/phidget21jar.zip Phidget Java Libraries (phidget21.jar)].&lt;br /&gt;
&lt;br /&gt;
Once downloaded, the {{Code|phidget21.jar}} library file does not get &#039;installed&#039; (i.e. do not run {{Code| java -jar phidget21.jar}}).  Rather, the library file gets put into the path of whatever program you write, and you will link it via both the java compiler and the java interpreter.  We walk you through this below.&lt;br /&gt;
&lt;br /&gt;
We have two different types of Phidget examples in Java: &lt;br /&gt;
*Simple examples, to be run on the command line, and&lt;br /&gt;
*Full examples, to be run in NetBeans&lt;br /&gt;
&lt;br /&gt;
Both are contained within the [http://www.phidgets.com/downloads/examples/JavaJNI.zip Phidget Java example download package].&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
&lt;br /&gt;
The Phidget Java libraries depend on the C libraries being installed as explained on the main [[OS - Linux | Linux page]].  If you browse around within the phidget21.jar archive, you will find Java class files (too many to reasonably list here) that have names related to the devices they provide an API for.&lt;br /&gt;
&lt;br /&gt;
These Java class files use the functions available in the &#039;&#039;dynamic&#039;&#039; Phidget21 C-language library on Linux.  Dynamic libraries end with {{Code|.so}}, and so the C library that the Phidget Java class files use is {{Code|/usr/lib/libphidget21.so}}.&lt;br /&gt;
&lt;br /&gt;
===Javac (Command Line)===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Linux gets somewhat complicated in that two Java compilers exist: {{Code|openjdk}} and {{Code|gcj}}.  Furthermore, a given IDE can &#039;&#039;usually&#039;&#039; use either compiler. That being said, we only offer support here for openJDK and IDEs running openJDK.&lt;br /&gt;
&lt;br /&gt;
To find out which type of compiler your computer has, use the {{Code|-version}} option on the command line.  You can use the same option for your runtime environment (interpreter):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
$&amp;gt; java -version&lt;br /&gt;
java version &amp;quot;1.6.0_23&amp;quot;&lt;br /&gt;
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.1)&lt;br /&gt;
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)&lt;br /&gt;
&lt;br /&gt;
$&amp;gt; javac -version&lt;br /&gt;
javac 1.6.0_23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The good news is that you can have both {{Code|openjdk}} and {{Code|gcj}} on your machine, co-habitating happily.  There can be only one linked java and javac in {{Code|/usr/bin/}} however, and so this will correspond to whichever java compiler and interpreter you installed last.&lt;br /&gt;
&lt;br /&gt;
If you do not have {{Code|openjdk}} installed already (this is the default Java installation for most Linux machines, so you will probably know), and you choose to install it for Phidget purposes, it is important is that the {{Code|java}} version be greater than the {{Code|javac}} version.  Otherwise, your runtime environment will consider the stuff your compiler produces to be newfangled nonsense.  So when installing Java from a repository, you should install both the jdk and the jre.  These are, unfortunately, usually separate packages in a repository (e.g. {{Code|openjdk-7-jre}} and {{Code|openjdk-7-jdk}}).&lt;br /&gt;
&lt;br /&gt;
The simple examples in Java are meant to be compiled and run on the command line.  The example package includes a {{Code|Makefile}} so you can either make all of the examples at once, with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
make all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...Or you can make them individually.  You can either use:&lt;br /&gt;
* The HelloWorld example, which will work with any Phidget, or&lt;br /&gt;
* The example with the name that corresponds to the family (software object) of your Phidget hardware.  &lt;br /&gt;
{{FindYourDevice}}  Once you&#039;ve identified the right example - say, {{Code|HelloWorld.java}} - compile it on the command line with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar HelloWorld.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run the example on a Linux machine [[OS - Linux#Setting udev Rules| without your udev USB rules set]], you will need to run the Java example as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo java -classpath .:phidget21.jar HelloWorld&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
You&#039;ll note that the Phidget Java library file {{Code|phidget21.jar}} needs to be explicitly linked at both points in the compile and run process.  Alternatively, you can make a jar file which includes the Phidget Java library.  This process takes two steps, the first of which is creating a text file called {{Code|MyProgram.mf}}, where {{Code|MyProgram}} is replaced by the name of your main class in both the filename and the text below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: MyProgram&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; The manifest file should end with a carriage return. So, there should be an extra line at the bottom of the file.&lt;br /&gt;
&lt;br /&gt;
After creating the manifest file, you can use the {{Code|jar}} function to create one self-contained file with your classes and the correct classpath.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar –cfm MyProgram.jar MyProgram.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If porting this for an external system, such as one that your customer would be running, the Phidget library would need to be compiled and distributed along with the {{Code|.jar}}.  Although we do not directly support this, if you are interested in how to construct this, we provide both a distribution example and information on cross-compiling:&lt;br /&gt;
* The [[Language - Android Java | Android Java]] libraries have an ARM-compiled {{Code|libphidget21.so}} file included, as an example of distributing a compiled libphidget21.so with the jar file&lt;br /&gt;
* The [[OS - Linux#Cross-Compiling with a Custom Toolchain|Linux page]] has more detail for compiling the Phidget C Libraries for an external target.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
We offer in-depth tutorials on using our examples in NetBeans and Eclipse in the [[#NetBeans|Windows NetBeans]] and [[#Eclipse|Windows Eclipse]] sections.&lt;br /&gt;
&lt;br /&gt;
As our full examples are written with NetBeans, but NetBeans is not part of the standard Linux package repository, we offer installation instructions here before referring to the Windows sections.&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
&lt;br /&gt;
Although Eclipse is standard in the Debian/Ubuntu package repository, NetBeans is no longer standard.  What is more, Netbeans does not install by default into a folder within your path.  As our Phidget full Java examples are written using NetBeans, we provide basic installation instructions here so you can actually run them.&lt;br /&gt;
&lt;br /&gt;
To install NetBeans:&lt;br /&gt;
&lt;br /&gt;
1. Download the install script from website: [http://netbeans.org/downloads/ http://netbeans.org/downloads/]&amp;lt;br&amp;gt;&lt;br /&gt;
2. Change the permissions of the downloaded file to be executable.  Usually, this is something like:&lt;br /&gt;
:{{Code|chmod +x netbeans-7.1-ml-javase-linux.sh}}&amp;lt;br&amp;gt;&lt;br /&gt;
3. Run the downloaded file as a script. (This will result in a GUI interaction that walks you through installation.)&amp;lt;br&amp;gt;&lt;br /&gt;
4. To find the location where the NetBeans installation occurred, run:&amp;lt;br&amp;gt;&lt;br /&gt;
:{{Code|updatedb}}&lt;br /&gt;
:{{Code|locate netbeans | grep bin}}&amp;lt;br&amp;gt;&lt;br /&gt;
5. Usually, the location of the binary is {{Code|/usr/local/netbeans-7.1/bin/netbeans}}, where 7.1 is the installed version.&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Once you have NetBeans installed, running our examples will be very similar to the process described in the [[#NetBeans|Windows NetBeans]] section.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#NetBeans| Windows NetBeans]] section for instructions if you are unfamiliar with NetBeans.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The [[#Follow the Examples|teaching]] section - which describes the examples - also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  This teaching section has resources for you to learn from the examples and write your own.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing Java code will be our Java API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in Java|[http://www.phidgets.com/documentation/JavaDoc.zip Java API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In Java, it is easiest if you name these &#039;&#039;&#039;event&#039;&#039;&#039; functions the same as in our examples.  You can change the main function pointer variable name, but none of the other names.  Our examples show how to immediately hook these functions into the events that will call them &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
In the example code, the event functions common to all Phidgets are called things like &#039;&#039;&#039;AttachHandler()&#039;&#039;&#039; and &#039;&#039;&#039;DetachHandler()&#039;&#039;&#039;, etc.&amp;lt;br&amp;gt;&lt;br /&gt;
But some event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.  Some &#039;get data&#039; functions are also specific to each device.&lt;br /&gt;
|Creating a Phidget software object in Java - when you are not using the Manager - is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating a {{Code|SpatialPhidget}} object.  The device-specific examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The software object provides device specific methods which are available from the API for your specific Phidget.|&lt;br /&gt;
[http://www.phidgets.com/documentation/JavaDoc.zip Java API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
When programming in Java, you&#039;re in luck.  All of our code snippet examples on our [[General Phidget Programming]] page are in both C++ and Java.  Therefore, we do not include any here, because that page is much more in-depth, and you won&#039;t have to have two pages open at once.  So head over there, and start writing code!&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
None yet.&lt;/div&gt;</summary>
		<author><name>192.168.3.183</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=19795</id>
		<title>Language - Java</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_Java&amp;diff=19795"/>
		<updated>2012-05-17T15:57:47Z</updated>

		<summary type="html">&lt;p&gt;192.168.3.183: /* Mac OS */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-Java.png|64x64px|link=|alt=Java]]|Java is a modern, object-oriented programming language maintained by Oracle.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|Java|the complete Phidget API, including events|all Phidget devices.|the {{Code|javac}} command line compiler as well as in integrated development environments(IDEs) such as [[#NetBeans | NetBeans]] and [[#Eclipse | Eclipse]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
&lt;br /&gt;
{{QuickDownloads|Java|&lt;br /&gt;
{{APIQuickDownloads|http://www.phidgets.com/documentation/JavaDoc.zip}}|&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/JavaJNI.zip|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|http://www.phidgets.com/downloads/libraries/phidget21jar.zip|Java|(phidget21.jar)}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with Java==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
Java programs on Windows depend on two files, which the installers in the [[#Libraries and Drivers | Quick Downloads]] section put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.  &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.jar}}&amp;lt;/b&amp;gt; is the Phidget Java library for JDK &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.4.2&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. So, you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. For more information, please see the section for your specific compiler/environment. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the [http://www.phidgets.com/downloads/libraries/phidget21-x86.zip {{Code|phidget21.dll}}] as well as the [http://www.phidgets.com/downloads/libraries/phidget21jar_2.1.8.20120131.zip {{Code|phidget21.jar}}] and manually install them where you want; refer to our [[OS_-_Windows#Manual_File_Installation|Manual Installation Instructions]].&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each compiler below.&lt;br /&gt;
&lt;br /&gt;
You can program Phidgets with Java in command line with the {{Code|javac}} compiler as well as in IDEs such as NetBeans and Eclipse. &lt;br /&gt;
&lt;br /&gt;
===Javac (Command Line)===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip example] and unpack them into a folder. Here, you can find an example program called HelloWorld which will work with any Phidget.  You can also find example programs for all the devices. {{FindYourDevice}} Please only use the simple examples. The full examples are intended for the [[#NetBeans | NetBeans IDE]].&lt;br /&gt;
&lt;br /&gt;
Ensure that the {{Code|phidget21.jar}} is in the same directory as the source code.&lt;br /&gt;
&lt;br /&gt;
To compile in Windows command prompt:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .;phidget21.jar example.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create Java bytecode in the form of {{Code|.class}} files. Type the following to run the program:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .;phidget21.jar example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you wish, you can compile the project as a {{Code|.jar}} so there are fewer files to maintain. The [http://www.oracle.com/java Java SDK] provides the {{Code|jar}} utility which packages all the {{Code|.class}} files into a single {{Code|.jar}} file. &lt;br /&gt;
To begin, you will have to provide a Manifest file to indicate the program entry point. With your favourite text editor, create a new file with the following content:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;  &lt;br /&gt;
Ensure that the file ends in a single new line or a carriage return character. &lt;br /&gt;
Save the file as {{Code|example.mf}} and place it in the same directory as the other {{Code|.class}} files.&lt;br /&gt;
Next, create the .{{Code|jar}} with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar -cfm example.jar example.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Afterwards, you can run the {{Code|.jar}} with:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -jar example.jar&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#Use Our Examples| previous]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
You first download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip examples], unpack them into a folder, and then find the source code for your device. {{FindYourDevice}} The full examples were written in NetBeans, so the rest of this section will use these examples. To use the simple examples, you will have to import the source code into a new NetBeans project. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Open Project.PNG|link=|alt=Open Project]]&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Click on Run &amp;amp;rarr; Run Project. The project, by default tries to find the {{Code|phidget21.jar}} in {{Code|..\..\lib}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Create a new Java application project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget Java library. In the projects pane, right click {{Code|Libraries}} and add the {{Code|jar}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Add Jar.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
3. Find and select {{Code|phidget21.jar}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Java NetBeans Add Jar 2.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [http://www.phidgets.com/downloads/examples/JavaJNI.zip examples] and unpack them into a folder. Here, you can find an example program called HelloWorld which will work with any Phidget.  You will also find example programs for all the devices. {{FindYourDevice}} &lt;br /&gt;
&lt;br /&gt;
Please use the simple examples. The full examples were written in NetBeans, and are not compatible with Eclipse. The rest of this guide will assume that the simple examples are used. The example source code will be copied into your Eclipse project later on. Keep note of the file name of the example as a Java class will be created with the same name.&lt;br /&gt;
&lt;br /&gt;
2. Generate a new Java project with a descriptive name such as PhidgetTest. Click next.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. On the next screen, go to the libraries panel and add an external {{Code|jar}}.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Add Jar 1.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
4. Find and select {{Code|phidget21.jar}}. &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Add Jar 2.PNG|link=|alt=Add Jar]]&lt;br /&gt;
&lt;br /&gt;
5. Add a new Java class to the project.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Class.PNG|link=|alt=New Class]]&lt;br /&gt;
&lt;br /&gt;
6. Name this class with the same name as the simple example&#039;s name. &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse New Class 2.PNG|link=|alt=New Class]]&lt;br /&gt;
&lt;br /&gt;
7. Copy and paste the example source code over to the class you created.&lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
8. The only thing left to do is to run the examples! &lt;br /&gt;
&lt;br /&gt;
[[File:Java Eclipse Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you have the Java examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#Use Our Examples 3| Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
The first step in using Java on Mac is to install the Phidget libraries.  Compile and install them as explained on the [[OS - OS X|main Mac OS page]].  That page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
The commands to compile in a OS X and Linux terminal are slightly different. Rather than prefixing {{Code|phidget21.jar}} with a semi-colon( {{Code|;}} ), a colon( {{Code|:}} ) is used.  Make sure that the {{Code|phidget21.jar}} file is in the same directory as the code you are trying to compile.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar example.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, to run the program:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
java -classpath .:phidget21.jar example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method can be used on any of the simple examples.  If you are interested in using an IDE then refer to the Windows section for information about setting up Phidgets projects in Eclipse or NetBeans.  &lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
Java has excellent support on Linux - there is an established implementation of the Java compiler and interpreter, and several Integrated Development Environments (IDEs) including NetBeans and Eclipse. &lt;br /&gt;
&lt;br /&gt;
The first step in using Java on Linux is to install the base Phidget libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different basic Phidget library files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
You will also need the [http://www.phidgets.com/downloads/libraries/phidget21jar.zip Phidget Java Libraries (phidget21.jar)].&lt;br /&gt;
&lt;br /&gt;
Once downloaded, the {{Code|phidget21.jar}} library file does not get &#039;installed&#039; (i.e. do not run {{Code| java -jar phidget21.jar}}).  Rather, the library file gets put into the path of whatever program you write, and you will link it via both the java compiler and the java interpreter.  We walk you through this below.&lt;br /&gt;
&lt;br /&gt;
We have two different types of Phidget examples in Java: &lt;br /&gt;
*Simple examples, to be run on the command line, and&lt;br /&gt;
*Full examples, to be run in NetBeans&lt;br /&gt;
&lt;br /&gt;
Both are contained within the [http://www.phidgets.com/downloads/examples/JavaJNI.zip Phidget Java example download package].&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
&lt;br /&gt;
The Phidget Java libraries depend on the C libraries being installed as explained on the main [[OS - Linux | Linux page]].  If you browse around within the phidget21.jar archive, you will find Java class files (too many to reasonably list here) that have names related to the devices they provide an API for.&lt;br /&gt;
&lt;br /&gt;
These Java class files use the functions available in the &#039;&#039;dynamic&#039;&#039; Phidget21 C-language library on Linux.  Dynamic libraries end with {{Code|.so}}, and so the C library that the Phidget Java class files use is {{Code|/usr/lib/libphidget21.so}}.&lt;br /&gt;
&lt;br /&gt;
===Javac (Command Line)===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Linux gets somewhat complicated in that two Java compilers exist: {{Code|openjdk}} and {{Code|gcj}}.  Furthermore, a given IDE can &#039;&#039;usually&#039;&#039; use either compiler. That being said, we only offer support here for openJDK and IDEs running openJDK.&lt;br /&gt;
&lt;br /&gt;
To find out which type of compiler your computer has, use the {{Code|-version}} option on the command line.  You can use the same option for your runtime environment (interpreter):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
$&amp;gt; java -version&lt;br /&gt;
java version &amp;quot;1.6.0_23&amp;quot;&lt;br /&gt;
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.1)&lt;br /&gt;
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)&lt;br /&gt;
&lt;br /&gt;
$&amp;gt; javac -version&lt;br /&gt;
javac 1.6.0_23&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The good news is that you can have both {{Code|openjdk}} and {{Code|gcj}} on your machine, co-habitating happily.  There can be only one linked java and javac in {{Code|/usr/bin/}} however, and so this will correspond to whichever java compiler and interpreter you installed last.&lt;br /&gt;
&lt;br /&gt;
If you do not have {{Code|openjdk}} installed already (this is the default Java installation for most Linux machines, so you will probably know), and you choose to install it for Phidget purposes, it is important is that the {{Code|java}} version be greater than the {{Code|javac}} version.  Otherwise, your runtime environment will consider the stuff your compiler produces to be newfangled nonsense.  So when installing Java from a repository, you should install both the jdk and the jre.  These are, unfortunately, usually separate packages in a repository (e.g. {{Code|openjdk-7-jre}} and {{Code|openjdk-7-jdk}}).&lt;br /&gt;
&lt;br /&gt;
The simple examples in Java are meant to be compiled and run on the command line.  The example package includes a {{Code|Makefile}} so you can either make all of the examples at once, with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
make all&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...Or you can make them individually.  You can either use:&lt;br /&gt;
* The HelloWorld example, which will work with any Phidget, or&lt;br /&gt;
* The example with the name that corresponds to the family (software object) of your Phidget hardware.  &lt;br /&gt;
{{FindYourDevice}}  Once you&#039;ve identified the right example - say, {{Code|HelloWorld.java}} - compile it on the command line with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
javac -classpath .:phidget21.jar HelloWorld.java&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run the example on a Linux machine [[OS - Linux#Setting udev Rules| without your udev USB rules set]], you will need to run the Java example as root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo java -classpath .:phidget21.jar HelloWorld&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
You&#039;ll note that the Phidget Java library file {{Code|phidget21.jar}} needs to be explicitly linked at both points in the compile and run process.  Alternatively, you can make a jar file which includes the Phidget Java library.  This process takes two steps, the first of which is creating a text file called {{Code|MyProgram.mf}}, where {{Code|MyProgram}} is replaced by the name of your main class in both the filename and the text below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=text&amp;gt;&lt;br /&gt;
Manifest-Version: 1.0&lt;br /&gt;
Class-Path: phidget21.jar&lt;br /&gt;
Main-Class: MyProgram&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; The manifest file should end with a carriage return. So, there should be an extra line at the bottom of the file.&lt;br /&gt;
&lt;br /&gt;
After creating the manifest file, you can use the {{Code|jar}} function to create one self-contained file with your classes and the correct classpath.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
jar –cfm MyProgram.jar MyProgram.mf *.class&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If porting this for an external system, such as one that your customer would be running, the Phidget library would need to be compiled and distributed along with the {{Code|.jar}}.  Although we do not directly support this, if you are interested in how to construct this, we provide both a distribution example and information on cross-compiling:&lt;br /&gt;
* The [[Language - Android Java | Android Java]] libraries have an ARM-compiled {{Code|libphidget21.so}} file included, as an example of distributing a compiled libphidget21.so with the jar file&lt;br /&gt;
* The [[OS - Linux#Cross-Compiling with a Custom Toolchain|Linux page]] has more detail for compiling the Phidget C Libraries for an external target.&lt;br /&gt;
&lt;br /&gt;
===NetBeans===&lt;br /&gt;
&lt;br /&gt;
We offer in-depth tutorials on using our examples in NetBeans and Eclipse in the [[#NetBeans|Windows NetBeans]] and [[#Eclipse|Windows Eclipse]] sections.&lt;br /&gt;
&lt;br /&gt;
As our full examples are written with NetBeans, but NetBeans is not part of the standard Linux package repository, we offer installation instructions here before referring to the Windows sections.&lt;br /&gt;
&lt;br /&gt;
====Installation====&lt;br /&gt;
&lt;br /&gt;
Although Eclipse is standard in the Debian/Ubuntu package repository, NetBeans is no longer standard.  What is more, Netbeans does not install by default into a folder within your path.  As our Phidget full Java examples are written using NetBeans, we provide basic installation instructions here so you can actually run them.&lt;br /&gt;
&lt;br /&gt;
To install NetBeans:&lt;br /&gt;
&lt;br /&gt;
1. Download the install script from website: [http://netbeans.org/downloads/ http://netbeans.org/downloads/]&amp;lt;br&amp;gt;&lt;br /&gt;
2. Change the permissions of the downloaded file to be executable.  Usually, this is something like:&lt;br /&gt;
:{{Code|chmod +x netbeans-7.1-ml-javase-linux.sh}}&amp;lt;br&amp;gt;&lt;br /&gt;
3. Run the downloaded file as a script. (This will result in a GUI interaction that walks you through installation.)&amp;lt;br&amp;gt;&lt;br /&gt;
4. To find the location where the NetBeans installation occurred, run:&amp;lt;br&amp;gt;&lt;br /&gt;
:{{Code|updatedb}}&lt;br /&gt;
:{{Code|locate netbeans | grep bin}}&amp;lt;br&amp;gt;&lt;br /&gt;
5. Usually, the location of the binary is {{Code|/usr/local/netbeans-7.1/bin/netbeans}}, where 7.1 is the installed version.&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
Once you have NetBeans installed, running our examples will be very similar to the process described in the [[#NetBeans|Windows NetBeans]] section.&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget Java library. Please see the [[#NetBeans| Windows NetBeans]] section for instructions if you are unfamiliar with NetBeans.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget Java library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=java&amp;gt;&lt;br /&gt;
import com.phidgets.*;&lt;br /&gt;
import com.phidgets.event.*;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The [[#Follow the Examples|teaching]] section - which describes the examples - also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  This teaching section has resources for you to learn from the examples and write your own.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing Java code will be our Java API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in Java|[http://www.phidgets.com/documentation/JavaDoc.zip Java API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In Java, it is easiest if you name these &#039;&#039;&#039;event&#039;&#039;&#039; functions the same as in our examples.  You can change the main function pointer variable name, but none of the other names.  Our examples show how to immediately hook these functions into the events that will call them &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
In the example code, the event functions common to all Phidgets are called things like &#039;&#039;&#039;AttachHandler()&#039;&#039;&#039; and &#039;&#039;&#039;DetachHandler()&#039;&#039;&#039;, etc.&amp;lt;br&amp;gt;&lt;br /&gt;
But some event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.  Some &#039;get data&#039; functions are also specific to each device.&lt;br /&gt;
|Creating a Phidget software object in Java - when you are not using the Manager - is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating a {{Code|SpatialPhidget}} object.  The device-specific examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The software object provides device specific methods which are available from the API for your specific Phidget.|&lt;br /&gt;
[http://www.phidgets.com/documentation/JavaDoc.zip Java API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
When programming in Java, you&#039;re in luck.  All of our code snippet examples on our [[General Phidget Programming]] page are in both C++ and Java.  Therefore, we do not include any here, because that page is much more in-depth, and you won&#039;t have to have two pages open at once.  So head over there, and start writing code!&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
None yet.&lt;/div&gt;</summary>
		<author><name>192.168.3.183</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Main_Page&amp;diff=19794</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Main_Page&amp;diff=19794"/>
		<updated>2012-05-17T14:58:04Z</updated>

		<summary type="html">&lt;p&gt;192.168.3.183: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;table&amp;gt;&lt;br /&gt;
 &amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;&lt;br /&gt;
__TOC__&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td valign=top align=center width=40%&amp;gt;&lt;br /&gt;
&amp;lt;!--{{#widget:Google Gadget|url=http://www.calebegg.com/countdown.xml&amp;amp;amp;up_eve=Diablo%20III%20is%20Released&amp;amp;amp;up_mon=5&amp;amp;amp;up_dat=14&amp;amp;amp;up_yer=2012&amp;amp;amp;synd=open&amp;amp;amp;w=200&amp;amp;amp;h=75&amp;amp;amp;title=&amp;amp;amp;lang=all&amp;amp;amp;country=ALL&amp;amp;amp;border=%23ffffff%7C3px%2C1px+solid+%23999999&amp;amp;amp;output=js|height=50}}--&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
==Phwiki==&lt;br /&gt;
&lt;br /&gt;
* [[Phidget Development Process]]&lt;br /&gt;
: [[Processes]]&lt;br /&gt;
: [[Standards]]&lt;br /&gt;
* [[Getting Started with Phidgets]]&lt;br /&gt;
* [[Style_Guide|Documentation Style Guide]]&lt;br /&gt;
* [[Projects Status]]&lt;br /&gt;
*[[PhidgetTesting Overhaul]]&lt;br /&gt;
*[[Website Redesign Ideas]]&lt;br /&gt;
*[[Products]] - Repository for product artifacts&lt;br /&gt;
*[[Logbook Details]]&lt;br /&gt;
*[[R&amp;amp;D Specializations]]&lt;br /&gt;
*[[Phidgets Bored Room Awesomification]]&lt;br /&gt;
&lt;br /&gt;
==Internal Systems Documentation==&lt;br /&gt;
&lt;br /&gt;
[[File:trac.png|link=|alt=]] Bug Tracker for [http://sl/trac# Brian] or [http://trac/# everyone else]&lt;br /&gt;
&lt;br /&gt;
[[File:trac.png|link=|alt=]] [[How to use Trac]]&lt;br /&gt;
*[[InternalTools]] documentation.&lt;br /&gt;
*Phidgets Inc. Internal [[Network]] information.&lt;br /&gt;
*[[Phone system]]&lt;br /&gt;
*[[Product Photography]]&lt;br /&gt;
*[[OpenVPN new user HOWTO]]&lt;br /&gt;
*[[Product Keys &amp;amp; Site Logins]]&lt;br /&gt;
&lt;br /&gt;
==People&#039;s Lists of Pages==&lt;br /&gt;
&lt;br /&gt;
===Patrick===&lt;br /&gt;
&lt;br /&gt;
* [[Patrick&#039;s List]]&lt;br /&gt;
:[[Phidget21]]&lt;br /&gt;
:[[SBC]]&lt;br /&gt;
:[[SBC2]]&lt;br /&gt;
:[[Programming@Phidgets - serials and MAC addresses]]&lt;br /&gt;
:[[iPhone Developer Program]]&lt;br /&gt;
:[[Release Build Documentation]]&lt;br /&gt;
:[[Delphi]]&lt;br /&gt;
:[[LTIB]]&lt;br /&gt;
&lt;br /&gt;
===Erik===&lt;br /&gt;
*[[Erik&#039;s Logbook]]&lt;br /&gt;
*[[Erik&#039;s List]]&lt;br /&gt;
:[[Erik&#039;s HW TODO]]&lt;br /&gt;
&lt;br /&gt;
===Fraser===&lt;br /&gt;
&lt;br /&gt;
*[[Fraser - General]]&lt;br /&gt;
*[[Fraser - NXP]]&lt;br /&gt;
*[[Fraser - Spatial]]&lt;br /&gt;
*[[NXP Getting Started]]&lt;br /&gt;
*[[Fraser - Zigbee/Bluetooth]]&lt;br /&gt;
&lt;br /&gt;
===Mike Paradis===&lt;br /&gt;
*[[Mike&#039;s List]]&lt;br /&gt;
&lt;br /&gt;
===Brian===&lt;br /&gt;
&lt;br /&gt;
===Cora===&lt;br /&gt;
&lt;br /&gt;
[[User:Cora|Cora&#039;s List]]&lt;br /&gt;
&lt;br /&gt;
===Dan J. Rudiak===&lt;br /&gt;
#&#039;&#039;&#039;Real Pages&#039;&#039;&#039;&lt;br /&gt;
#* [[Documentation_Log|Documentation Log]]&lt;br /&gt;
#&#039;&#039;&#039;Wiki Information&#039;&#039;&#039;&lt;br /&gt;
#* [[Icon Gallery]]&lt;br /&gt;
#* [[Progress Bars]]&lt;br /&gt;
#[[User:Djrudiak|Dan&#039;s List]]&lt;br /&gt;
&lt;br /&gt;
===Old Pages===&lt;br /&gt;
* [[User:Djrudiak|Dan&#039;s List]]&lt;br /&gt;
* [[Michael Shan&#039;s List]]&lt;br /&gt;
* [[Evan&#039;s List]]&lt;br /&gt;
*[[Adam&#039;s List]]&lt;br /&gt;
&lt;br /&gt;
===Leo===&lt;br /&gt;
*[[Leo&#039;s Documentation]]&lt;br /&gt;
*[[Test Lab information]]&lt;br /&gt;
*[[Internal EMC Testing Status]]&lt;br /&gt;
*[[Travel Notes]]&lt;br /&gt;
*[[Leo&#039;s Logbook]]&lt;br /&gt;
&lt;br /&gt;
== Getting started ==&lt;br /&gt;
&lt;br /&gt;
Consult the [http://meta.wikipedia.org/wiki/MediaWiki_User%27s_Guide User&#039;s Guide] for information on using the wiki software.&lt;br /&gt;
&lt;br /&gt;
* [http://www.mediawiki.org/wiki/Help:Configuration_settings Configuration settings list]&lt;br /&gt;
* [http://www.mediawiki.org/wiki/Help:FAQ MediaWiki FAQ]&lt;br /&gt;
* [http://mail.wikipedia.org/mailman/listinfo/mediawiki-announce MediaWiki release mailing list]&lt;/div&gt;</summary>
		<author><name>192.168.3.183</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_C&amp;diff=19779</id>
		<title>Language - C</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_C&amp;diff=19779"/>
		<updated>2012-05-16T19:10:25Z</updated>

		<summary type="html">&lt;p&gt;192.168.3.183: /* OS X */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-C++.png|link=|alt=C/C++|64x64px]]|C++ is a general purpose, cross-platform programming language with a vast user base.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|C/C++|the complete Phidget API, including events|all Phidget devices.|Windows 2000/XP/Vista/7(environments include [[#Visual Studio | Visual Studio]], [[#Borland | Borland]], [[#Cygwin/MinGW | Cygwin, and MinGW]]), [[#Windows CE | Windows CE]], [[#OS X | OS X]], and [[#Linux | Linux]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
{{QuickDownloads|C/C++|&lt;br /&gt;
{{APIQuickDownloads|http://www.phidgets.com/documentation/Phidget21_C_Doc.zip}}|&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/VCpp.zip Visual Studio 2005/2008/2010|}}&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz Generic|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|http://www.phidgets.com/downloads/libraries/phidget21bcc.zip|Borland(Windows)|}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with C/C++==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C/C++ programs on Windows depend on three files, which the installers in [[#Libraries and Drivers|Quick Downloads]] put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.lib}}&amp;lt;/b&amp;gt; is used by your compiler to link to the dll.  Your compiler has to know where this file is, by default our installer puts {{Code|phidget21.lib}} into {{Code|C:\Program Files\Phidgets}}, so you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. {{Code|phidget21.lib}} is written to be compatible with most compilers - but your specific compiler may need a different format. Check our documentation for your specific compiler for details. Please note that we provide versions of the {{Code|phidget21.lib}} that are specifically optimized for 32-bit or 64-bit systems. If you are using a 64 bit versions of Windows, the {{Code|phidget21.lib}} is placed in {{Code|C:\Program Files\Phidgets}}; The 32 bit version of {{Code|phidget21.lib}} is placed in {{Code|C:\Program Files\Phidgets\x86}}. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.h}}&amp;lt;/b&amp;gt; lists all the Phidget API function calls available to your code.  Your compiler also has to know where this file is.  By default, our installer puts {{Code|phidget21.h}} into {{Code|C:\Program Files\Phidgets}} so you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download all three [http://www.phidgets.com/downloads/libraries/phidget21-x86.zip files] and manually install them where you want; refer to our [[OS_-_Windows#Manual_File_Installation | Manual Installation Instructions]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for [[#Visual Studio 2005/2008/2010 | Visual Studio 2005/2008/2010]], [[#Visual Studio 2003 | Visual Studio 2003]], [[#Visual Studio C++ 6.0 | Visual Studio 6]], [[#Borland| Borland]], [[#Cygwin/MinGW | Cygwin/MinGW]], and [[#Dev C++ | Dev C++]].&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
&lt;br /&gt;
C++/CLI (which used to be called Managed C++) is very different from mainstream C/C++.  If you must use C++/CLI, consider calling the Phidget .NET library, instead of the C API normally used from C/C++.  We have no documentation for using C++/CLI.&lt;br /&gt;
&lt;br /&gt;
Microsoft makes free versions of Visual Studio available known as Express Editions.  The Express editions are suitable for most applications, but are limited in features for more complex applications. Please see [http://www.microsoft.com/visualstudio Microsoft Visual Studio] for more information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Visual Studio 2005/2008/2010====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
To run the examples, you first download the [http://www.phidgets.com/downloads/examples/VCpp.zip examples] and unpack them into a folder.  To load all projects in Visual Studio, go to File &amp;amp;rarr; Open &amp;amp;rarr; Project &amp;amp;rarr; Solution, and open {{Code|Visual Studio Phidgets Examples.sln}} in the {{Code|VCpp}} folder of the examples.&lt;br /&gt;
&lt;br /&gt;
Since the examples were written in Visual Studio 2005, if you are opening the examples in Visual Studio 2008/2010, you will need to go through the Visual Studio Conversion Wizard to open and convert the 2005 project. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Conversion Wizard.PNG|link=|alt=Conversion Wizard]]&lt;br /&gt;
&lt;br /&gt;
This will load all of the examples available for C/C++. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
Start by setting the {{Code|HelloWorld}} project as your start up project.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 StartUp Project.PNG|link=|alt=Start Up Project]]&lt;br /&gt;
&lt;br /&gt;
To run the example, click on Debug &amp;amp;rarr; Start Debugging. Please note that the projects, by default try to find the {{Code|phidget21.h}} and {{Code|phidget21.lib}} in the {{Code|$(SystemDrive)\Program Files\Phidgets}}. If you have these files installed in another location, please change the path to the file&#039;s location accordingly. Please see the [[#Write Your Own Code | Write Your Own Code]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C++: Win32 Console Application project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Next, select Console Application.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 New Project 2.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Open the project properties window.&lt;br /&gt;
&lt;br /&gt;
4. Navigate to Configuration Properties &amp;amp;rarr; C/C++.&lt;br /&gt;
&lt;br /&gt;
5. Add {{Code|&amp;quot;C:\Program Files\Phidgets&amp;quot;}} to the additional directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Configuration Properties &amp;amp;rarr; Linker &amp;amp;rarr; Input.&lt;br /&gt;
&lt;br /&gt;
7. Edit the additional dependencies and add {{Code|&amp;quot;C:\Program  Files\Phidgets\phidget21.lib&amp;quot;}}. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
8. The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
====Visual Studio 2003====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Start by downloading the [http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz examples]. You can import these examples into a Visual Studio 2003 C++ project. Afterwards, unpack them into a folder. Here, you can find example programs for all the devices. You will need this example source code to be copied into your C++ project later on. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example. &lt;br /&gt;
&lt;br /&gt;
2. A new project will need to be created. Generate a new Visual C++ empty project(.NET) with a descriptive name such as HelloWorld.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Create a new C++ file by adding a new item to the source files folder. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 New File.PNG|link=|alt=New File]]&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 New File 2.PNG|link=|alt=New File]]&lt;br /&gt;
&lt;br /&gt;
4. An empty C++ file will pop up. Please copy and paste the contents of the {{Code|HelloWorld.c}} program into here. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
5. Next, the project setting needs to be set up. Open the project properties window.&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Configuration Properties &amp;amp;rarr; C/C++.&lt;br /&gt;
&lt;br /&gt;
7. Add {{Code|&amp;quot;C:\Program Files\Phidgets&amp;quot;}} to the additional include directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
8. Navigate to Configuration Properties &amp;amp;rarr; Linker &amp;amp;rarr; Input.&lt;br /&gt;
&lt;br /&gt;
9. Add {{Code|&amp;quot;C:\Program  Files\Phidgets\phidget21.lib&amp;quot;}} to the additional dependencies field. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
10. Now, you can run the example. Click on Debug &amp;amp;rarr; Start Without Debugging.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
11. This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your  development environment to properly link the Phidget C/C++ library. Please see the [[#Use Our Examples 2 | Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Visual Studio C++ 6.0====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz examples] and unpack them into a folder. Here, you can find example programs for all the devices. You will need this example source code to be copied into your C++ project later on. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
2. Next, a new project will need to be created. Generate a new Win32 Console Application project with a descriptive name such as HelloWorld.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Create an empty project.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 New Project 2.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
4. Next, the project settings needs to be set up. Navigate to Project &amp;amp;rarr; Settings &amp;amp;rarr; C/C++ &amp;amp;rarr; Preprocessor.&lt;br /&gt;
&lt;br /&gt;
5. Add {{Code|C:\Program Files\Phidgets}} to the additional include directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Project &amp;amp;rarr; Settings &amp;amp;rarr; Link &amp;amp;rarr; Input &amp;amp;rarr; Additional library Path.&lt;br /&gt;
&lt;br /&gt;
7. Add {{Code|phidget21.lib}} to the object/library modules field.&lt;br /&gt;
&lt;br /&gt;
8. Add {{Code|C:\Program  Files\Phidgets}} to the additional library path. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
To import the example program into your project, please:&lt;br /&gt;
&lt;br /&gt;
9. Create a new C++ file by navigating to File &amp;amp;rarr; New &amp;amp;rarr; Files &amp;amp;rarr; C++ Source File and enter a descriptive name such as HelloWorld.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 New File.PNG|link=|alt=New File]]&lt;br /&gt;
&lt;br /&gt;
10. An empty C++ file will pop up. Please copy and paste the contents of the {{Code|HelloWorld.c}} program here.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
11. Now, you can run the example. Click on Build &amp;amp;rarr; Execute.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
12. This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. Please see the [[#Use Our Examples 3 | Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as shown in the [[#Use Our Examples 3 | Use Our Examples]] section. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
===Borland===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
In addition to running one of the two [[#Libraries and Drivers:| Windows Installers]] above (which you probably already have if you worked through the &#039;&#039;Getting Started&#039;&#039; page for your device), you will need the [http://www.phidgets.com/downloads/libraries/phidget21bcc.zip Borland C++ Libraries]. {{Code|phidget21bcc.lib}} is typically placed in {{Code|C:\Program Files\Phidgets}}, but you are free to place it in any directory you wish.&lt;br /&gt;
&lt;br /&gt;
After installing the Phidget C/C++ library, you&#039;re ready to download the [http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz examples] and run the examples.&lt;br /&gt;
&lt;br /&gt;
Afterwards, unpack the examples. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example. Locate the {{Code|HelloWorld.c}} file and type the following to compile the file and link the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
To compile, link the Phidget C/C++ library and build a binary executable, enter the following in a command line prompt in the directory with {{Code|HelloWorld.c}}:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  bcc32 -eHelloWorld -I&amp;quot;C:\Program Files\Phidgets&amp;quot; -L&amp;quot;C:\Program Files\Phidgets&amp;quot; phidget21bcc.lib HelloWorld.c&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is assumed that {{Code|phidget21bcc.lib}} and {{Code|phidget21.h}} are placed in {{Code|C:\Program Files\Phidgets}}. If the files are placed in another location, please adjust the paths to both of the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
In this case, {{Code|HelloWorld.c}} would be the &#039;&#039;&#039;.c&#039;&#039;&#039; file specific to your device.  After using {{Code|bcc32}}, you will have an executable named {{Code|HelloWorld}} that you can run.  &lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:Borland HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C/C++ code with Borland. In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as the examples [[#Use Our Examples 4 |above]]. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
===GCC on Windows===&lt;br /&gt;
&lt;br /&gt;
====Cygwin/MinGW====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Download the [http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz examples] and unpack them into a folder. Afterwards, unpack the examples. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example. Locate the {{Code|HelloWorld.c}} file and type the following to compile the file and link the Phidget C/C++ library in a command line prompt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Cygwin&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  gcc example.c -o HelloWorld -I&amp;quot;/cygdrive/c/Program Files/Phidgets&amp;quot; -L&amp;quot;/cygdrive/c/Program Files/Phidgets&amp;quot; -lphidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;MinGW&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  gcc example.c -o HelloWorld -I&amp;quot;C:\Program Files\Phidgets&amp;quot; -L&amp;quot;C:\Program Files\Phidgets&amp;quot; -lphidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After using gcc, you will have an executable named {{Code|HelloWorld}} that you can run.  &lt;br /&gt;
It is assumed that {{Code|phidget21.h}} and {{Code|phidget21.lib}} are placed in {{Code|C:\Program Files\Phidgets}}. If the files are placed in another location, please adjust the paths to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
After using {{Code|gcc}}, you will have an executable named {{Code|HelloWorld}} that you can run.  &lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:C MinGW HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C/C++ code with Cygwin/MinGW in your favourite text editor. In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as shown in the [[#Use Our Examples 5| Use Our Examples]] section above. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
===Dev C++===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz examples] and unpack them into a folder. Here, you can find example programs for all the devices. {{FindYourDevice}}  You will need this example source code to be copied into your Dev C++ project later on. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
2. In order to control Phidgets with Dev C++, we will use the {{Code|reimp}} tool to convert the {{Code|phidget21.lib}} to a format that Dev C++ accepts. Download the [http://www.phidgets.com reimp tool].&lt;br /&gt;
&lt;br /&gt;
3. Open up command line and traverse to the directory containing the reimp tool. Type the following command to create {{Code|libphidget21.a}}.&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  reimp.exe &amp;quot;C:\Program Files\Phidgets\phidget21.lib&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
The command above assumes that the {{Code|phidget21.lib}} is in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly. Please note that the 64 bit version of {{Code|phidget21.lib}} is not supported on Dev C/C++. Please use the 32 bit version of {{Code|phidget21.lib}}.&lt;br /&gt;
&lt;br /&gt;
4. Place {{Code|libphidget21.a}} in {{Code|&amp;lt;Dev-Cpp Install Directory&amp;gt;/lib}}.&lt;br /&gt;
&lt;br /&gt;
5. Next, a new project will need to be created. Generate a new console application with a descriptive name such as PhidgetTest. Please select C as the project type.&lt;br /&gt;
&lt;br /&gt;
[[File:DevC New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
6. Next, the project settings needs to be set up. Navigate to Project Options &amp;amp;rarr; Directories &amp;amp;rarr; Include Directories.&lt;br /&gt;
&lt;br /&gt;
7. Add a new path to {{Code|C:\Program Files\Phidgets}}. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:DevC Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
8. Navigate to Project Options &amp;amp;rarr; Parameters &amp;amp;rarr; Linker.&lt;br /&gt;
&lt;br /&gt;
9. Add {{Code|-lphidget21}} to the field. This step will find the {{Code|libphidget21.a}} file in {{Code|&amp;lt;Dev-Cpp Install Directory&amp;gt;/lib}}. &lt;br /&gt;
&lt;br /&gt;
[[File:DevC Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
10. To import the {{Code|HelloWorld}} program into your project, please open up {{Code|main.c}} in the editor.&lt;br /&gt;
&lt;br /&gt;
11. An empty C file will pop up. Please copy and paste the contents of the example program. &lt;br /&gt;
&lt;br /&gt;
[[File:DevC Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
12. Now, you can run the example. Click on Execute &amp;amp;rarr; Compile &amp;amp; Run.&lt;br /&gt;
&lt;br /&gt;
[[File:DevC Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
13. This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:DevC HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. Please see the [[#Use Our Examples 6 | Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as the [[#Use Our Examples 6 | examples]] above. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
C/C++ has excellent support on OS X through the gcc compiler.  &lt;br /&gt;
&lt;br /&gt;
The first step in using C/C++ on Mac is to install the Phidget C/C++ library.  Compile and install them as explained on the Getting Started guide for your device, which you can find on its product page on [http://www.phidgets.com our main website].  Then, the [[OS - OS X#Description of Library files|OS - OS X]] page also describes the different Phidget files, their installed locations, and their roles. &lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
After installing the main Phidget library for OS X as above, you&#039;re ready to download the [http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz examples]. Afterwards, unzip the file. To run the example code, you&#039;ll need to find the source code &#039;&#039;for your specific device&#039;&#039;.  Then, compile the code under your platform and run it.&lt;br /&gt;
&lt;br /&gt;
To compile, link the Phidget C/C++ library, and build an executable binary on OS X, do (for example, depending on the Headers location):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  gcc example.c -o example -framework Phidget21 -I/Library/Frameworks/Phidget21.framework/Headers&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After using gcc, you will have an executable named {{Code|example}} that you can run.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as shown in the [[#Use Our Examples 7|Use Our Example]] section above.&lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples.  Even more help and references are provided from there.&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
C/C++ has support on Linux through the gcc compiler.  &lt;br /&gt;
&lt;br /&gt;
The first step in using C/C++ on Linux is to install the Phidget libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
After installing the Phidget libraries for Linux as above, you&#039;re ready to download and run the examples:&lt;br /&gt;
*[http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz Generic C/C++ Examples]&lt;br /&gt;
&lt;br /&gt;
To run the example code, you&#039;ll need to download and unpack the examples, and then find the source code for your device.  {{FindYourDevice}}  You can also use the HelloWorld program, which a basic program that can run with any Phidget.  Then, compile the code under your platform and run it.  When compiling, you need to link to the Phidget library.&lt;br /&gt;
&lt;br /&gt;
To compile, link the Phidget libraries and build a binary executable on Linux, do the following in a terminal in the directory with {{Code|example.c}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  gcc example.c -o example -lphidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, {{Code|example.c}} would be the &#039;&#039;&#039;.c&#039;&#039;&#039; file specific to your device.  After using gcc, you will have an executable named {{Code|example}} that you can run.  &lt;br /&gt;
&lt;br /&gt;
On Linux, if you have not set up [[OS_-_Linux#Setting_udev_Rules | your udev rules for USB access]], you will need to run the program &#039;&#039;&#039;as root&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  sudo ./example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C/C++ code on Linux, such as within a text editor like Emacs, Vi, Gedit, or Kate.  In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as the examples above. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==Windows CE==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C/C++ programs on Windows CE depend on the following files, which the Windows CE installer puts onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  It is placed in {{Code|\Windows}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|PhidgetWebService21.exe}}&amp;lt;/b&amp;gt; is used to control Phidgets remotely across a network using the [[#WebService | PhidgetWebService]]. It can be placed anywhere on the system.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.lib}}&amp;lt;/b&amp;gt; is used by your compiler to link to the dll.  Your compiler has to know where this file is.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.h}}&amp;lt;/b&amp;gt; lists all the Phidget API function calls available to your code.  Your compiler also has to know where this file is. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget.dll}}&amp;lt;/b&amp;gt; is the Phidgets kernel driver. It is placed in {{Code|\Windows}}.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2005/2008/2010===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Currently, we have no example code for C/C++ on Windows CE. However, set up is very much the same as what it would be with [[#Visual Studio 2005/2008/2010 |Visual Studio 2005/2008/2010]] in Windows. The {{Code|phidget21.h}} and {{Code|phidget21.lib}} can be downloaded [http://www.phidgets.com/downloads/libraries/Phidget21-wincedevel.zip here].&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C++: Win32 Smart Device project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 1.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Select {{Code|Next}}.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 2.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Select the SDK(s) that you want to code against and elect {{Code|Next}}.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 3.PNG|link=|alt=SDKs]]&lt;br /&gt;
&lt;br /&gt;
4. Create a console application and select {{Code|Next}}.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 4.PNG|link=|alt=Create Console Application]]&lt;br /&gt;
&lt;br /&gt;
3. Open the project properties window.&lt;br /&gt;
&lt;br /&gt;
4. Navigate to Configuration Properties &amp;amp;rarr; C/C++.&lt;br /&gt;
&lt;br /&gt;
5. Add {{Code|&amp;quot;C:\Program Files\Phidgets&amp;quot;}} to the additional directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Configuration Properties &amp;amp;rarr; Linker &amp;amp;rarr; Input.&lt;br /&gt;
&lt;br /&gt;
7. Edit the additional dependencies and add {{Code|&amp;quot;C:\Program  Files\Phidgets\phidget21.lib&amp;quot;}}. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
8. The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  &lt;br /&gt;
&lt;br /&gt;
Your main reference for writing C code will be our C/C++ API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in C/C++|[http://www.phidgets.com/documentation/Phidget21_C_Doc.zip C/C++ API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In C/C++, you can name these &#039;&#039;&#039;event&#039;&#039;&#039; functions whatever you like.  You will then pass them as function pointers to the Phidget library below in the Main Code section.  This hooks them into the actual events when they occur. &amp;lt;br&amp;gt; &lt;br /&gt;
In the example code, the event functions common to all Phidgets are called things like &#039;&#039;&#039;AttachHandler()&#039;&#039;&#039; and &#039;&#039;&#039;DetachHandler()&#039;&#039;&#039;, etc.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Some event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.&lt;br /&gt;
Other functions are given in the examples to show you more detail on using your Phidget.  For example, &#039;&#039;&#039;DeviceInitialize()&#039;&#039;&#039; will show what needs to be set up for your Phidget before using it.&lt;br /&gt;
|Creating a Phidget software object in C is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating an object with the {{Code|CPhidgetSpatialHandle}} type, and then initializing it using the {{Code|CPhidgetSpatial_create function}}.  The examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Other C calls follow a similar syntax - {{Code|CPhidgetXXX_function}}, where XXX is the name of your device, and function is an action available from the API for your specific Phidget.|&lt;br /&gt;
[http://www.phidgets.com/documentation/Phidget21_C_Doc.zip C/C++ API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
When programming in C/C++, you&#039;re in luck.  All of our code snippet examples on our [[General Phidget Programming]] page are in both C++ and Java.  Therefore, we do not include any here, because that page is much more in-depth, and you won&#039;t have to have two pages open at once.  So head over there, and start writing code!&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
===Issue: I am using a non US-English version of Windows, and the Visual C/C++ examples run into a linker error===&lt;br /&gt;
Affected Operating Systems: &#039;&#039;&#039;Windows&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The example projects, by default finds the {{Code|phidget21.h}} and {{Code|phidget21.lib}} in ${SystemDrive}\Program Files\Phidgets. If you are using a non US-English version of Windows, the Phidget drivers may be installed into a different location. To resolve, you will have to modify the paths to these two files. For instructions, please see your environment/compiler section.&lt;/div&gt;</summary>
		<author><name>192.168.3.183</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_C&amp;diff=19778</id>
		<title>Language - C</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_C&amp;diff=19778"/>
		<updated>2012-05-16T19:10:07Z</updated>

		<summary type="html">&lt;p&gt;192.168.3.183: /* OS X */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-C++.png|link=|alt=C/C++|64x64px]]|C++ is a general purpose, cross-platform programming language with a vast user base.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|C/C++|the complete Phidget API, including events|all Phidget devices.|Windows 2000/XP/Vista/7(environments include [[#Visual Studio | Visual Studio]], [[#Borland | Borland]], [[#Cygwin/MinGW | Cygwin, and MinGW]]), [[#Windows CE | Windows CE]], [[#OS X | OS X]], and [[#Linux | Linux]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
{{QuickDownloads|C/C++|&lt;br /&gt;
{{APIQuickDownloads|http://www.phidgets.com/documentation/Phidget21_C_Doc.zip}}|&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/VCpp.zip Visual Studio 2005/2008/2010|}}&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz Generic|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|http://www.phidgets.com/downloads/libraries/phidget21bcc.zip|Borland(Windows)|}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with C/C++==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C/C++ programs on Windows depend on three files, which the installers in [[#Libraries and Drivers|Quick Downloads]] put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.lib}}&amp;lt;/b&amp;gt; is used by your compiler to link to the dll.  Your compiler has to know where this file is, by default our installer puts {{Code|phidget21.lib}} into {{Code|C:\Program Files\Phidgets}}, so you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. {{Code|phidget21.lib}} is written to be compatible with most compilers - but your specific compiler may need a different format. Check our documentation for your specific compiler for details. Please note that we provide versions of the {{Code|phidget21.lib}} that are specifically optimized for 32-bit or 64-bit systems. If you are using a 64 bit versions of Windows, the {{Code|phidget21.lib}} is placed in {{Code|C:\Program Files\Phidgets}}; The 32 bit version of {{Code|phidget21.lib}} is placed in {{Code|C:\Program Files\Phidgets\x86}}. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.h}}&amp;lt;/b&amp;gt; lists all the Phidget API function calls available to your code.  Your compiler also has to know where this file is.  By default, our installer puts {{Code|phidget21.h}} into {{Code|C:\Program Files\Phidgets}} so you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download all three [http://www.phidgets.com/downloads/libraries/phidget21-x86.zip files] and manually install them where you want; refer to our [[OS_-_Windows#Manual_File_Installation | Manual Installation Instructions]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for [[#Visual Studio 2005/2008/2010 | Visual Studio 2005/2008/2010]], [[#Visual Studio 2003 | Visual Studio 2003]], [[#Visual Studio C++ 6.0 | Visual Studio 6]], [[#Borland| Borland]], [[#Cygwin/MinGW | Cygwin/MinGW]], and [[#Dev C++ | Dev C++]].&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
&lt;br /&gt;
C++/CLI (which used to be called Managed C++) is very different from mainstream C/C++.  If you must use C++/CLI, consider calling the Phidget .NET library, instead of the C API normally used from C/C++.  We have no documentation for using C++/CLI.&lt;br /&gt;
&lt;br /&gt;
Microsoft makes free versions of Visual Studio available known as Express Editions.  The Express editions are suitable for most applications, but are limited in features for more complex applications. Please see [http://www.microsoft.com/visualstudio Microsoft Visual Studio] for more information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Visual Studio 2005/2008/2010====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
To run the examples, you first download the [http://www.phidgets.com/downloads/examples/VCpp.zip examples] and unpack them into a folder.  To load all projects in Visual Studio, go to File &amp;amp;rarr; Open &amp;amp;rarr; Project &amp;amp;rarr; Solution, and open {{Code|Visual Studio Phidgets Examples.sln}} in the {{Code|VCpp}} folder of the examples.&lt;br /&gt;
&lt;br /&gt;
Since the examples were written in Visual Studio 2005, if you are opening the examples in Visual Studio 2008/2010, you will need to go through the Visual Studio Conversion Wizard to open and convert the 2005 project. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Conversion Wizard.PNG|link=|alt=Conversion Wizard]]&lt;br /&gt;
&lt;br /&gt;
This will load all of the examples available for C/C++. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
Start by setting the {{Code|HelloWorld}} project as your start up project.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 StartUp Project.PNG|link=|alt=Start Up Project]]&lt;br /&gt;
&lt;br /&gt;
To run the example, click on Debug &amp;amp;rarr; Start Debugging. Please note that the projects, by default try to find the {{Code|phidget21.h}} and {{Code|phidget21.lib}} in the {{Code|$(SystemDrive)\Program Files\Phidgets}}. If you have these files installed in another location, please change the path to the file&#039;s location accordingly. Please see the [[#Write Your Own Code | Write Your Own Code]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C++: Win32 Console Application project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Next, select Console Application.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 New Project 2.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Open the project properties window.&lt;br /&gt;
&lt;br /&gt;
4. Navigate to Configuration Properties &amp;amp;rarr; C/C++.&lt;br /&gt;
&lt;br /&gt;
5. Add {{Code|&amp;quot;C:\Program Files\Phidgets&amp;quot;}} to the additional directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Configuration Properties &amp;amp;rarr; Linker &amp;amp;rarr; Input.&lt;br /&gt;
&lt;br /&gt;
7. Edit the additional dependencies and add {{Code|&amp;quot;C:\Program  Files\Phidgets\phidget21.lib&amp;quot;}}. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
8. The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
====Visual Studio 2003====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Start by downloading the [http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz examples]. You can import these examples into a Visual Studio 2003 C++ project. Afterwards, unpack them into a folder. Here, you can find example programs for all the devices. You will need this example source code to be copied into your C++ project later on. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example. &lt;br /&gt;
&lt;br /&gt;
2. A new project will need to be created. Generate a new Visual C++ empty project(.NET) with a descriptive name such as HelloWorld.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Create a new C++ file by adding a new item to the source files folder. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 New File.PNG|link=|alt=New File]]&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 New File 2.PNG|link=|alt=New File]]&lt;br /&gt;
&lt;br /&gt;
4. An empty C++ file will pop up. Please copy and paste the contents of the {{Code|HelloWorld.c}} program into here. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
5. Next, the project setting needs to be set up. Open the project properties window.&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Configuration Properties &amp;amp;rarr; C/C++.&lt;br /&gt;
&lt;br /&gt;
7. Add {{Code|&amp;quot;C:\Program Files\Phidgets&amp;quot;}} to the additional include directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
8. Navigate to Configuration Properties &amp;amp;rarr; Linker &amp;amp;rarr; Input.&lt;br /&gt;
&lt;br /&gt;
9. Add {{Code|&amp;quot;C:\Program  Files\Phidgets\phidget21.lib&amp;quot;}} to the additional dependencies field. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
10. Now, you can run the example. Click on Debug &amp;amp;rarr; Start Without Debugging.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
11. This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your  development environment to properly link the Phidget C/C++ library. Please see the [[#Use Our Examples 2 | Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Visual Studio C++ 6.0====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz examples] and unpack them into a folder. Here, you can find example programs for all the devices. You will need this example source code to be copied into your C++ project later on. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
2. Next, a new project will need to be created. Generate a new Win32 Console Application project with a descriptive name such as HelloWorld.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Create an empty project.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 New Project 2.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
4. Next, the project settings needs to be set up. Navigate to Project &amp;amp;rarr; Settings &amp;amp;rarr; C/C++ &amp;amp;rarr; Preprocessor.&lt;br /&gt;
&lt;br /&gt;
5. Add {{Code|C:\Program Files\Phidgets}} to the additional include directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Project &amp;amp;rarr; Settings &amp;amp;rarr; Link &amp;amp;rarr; Input &amp;amp;rarr; Additional library Path.&lt;br /&gt;
&lt;br /&gt;
7. Add {{Code|phidget21.lib}} to the object/library modules field.&lt;br /&gt;
&lt;br /&gt;
8. Add {{Code|C:\Program  Files\Phidgets}} to the additional library path. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
To import the example program into your project, please:&lt;br /&gt;
&lt;br /&gt;
9. Create a new C++ file by navigating to File &amp;amp;rarr; New &amp;amp;rarr; Files &amp;amp;rarr; C++ Source File and enter a descriptive name such as HelloWorld.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 New File.PNG|link=|alt=New File]]&lt;br /&gt;
&lt;br /&gt;
10. An empty C++ file will pop up. Please copy and paste the contents of the {{Code|HelloWorld.c}} program here.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
11. Now, you can run the example. Click on Build &amp;amp;rarr; Execute.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
12. This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. Please see the [[#Use Our Examples 3 | Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as shown in the [[#Use Our Examples 3 | Use Our Examples]] section. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
===Borland===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
In addition to running one of the two [[#Libraries and Drivers:| Windows Installers]] above (which you probably already have if you worked through the &#039;&#039;Getting Started&#039;&#039; page for your device), you will need the [http://www.phidgets.com/downloads/libraries/phidget21bcc.zip Borland C++ Libraries]. {{Code|phidget21bcc.lib}} is typically placed in {{Code|C:\Program Files\Phidgets}}, but you are free to place it in any directory you wish.&lt;br /&gt;
&lt;br /&gt;
After installing the Phidget C/C++ library, you&#039;re ready to download the [http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz examples] and run the examples.&lt;br /&gt;
&lt;br /&gt;
Afterwards, unpack the examples. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example. Locate the {{Code|HelloWorld.c}} file and type the following to compile the file and link the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
To compile, link the Phidget C/C++ library and build a binary executable, enter the following in a command line prompt in the directory with {{Code|HelloWorld.c}}:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  bcc32 -eHelloWorld -I&amp;quot;C:\Program Files\Phidgets&amp;quot; -L&amp;quot;C:\Program Files\Phidgets&amp;quot; phidget21bcc.lib HelloWorld.c&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is assumed that {{Code|phidget21bcc.lib}} and {{Code|phidget21.h}} are placed in {{Code|C:\Program Files\Phidgets}}. If the files are placed in another location, please adjust the paths to both of the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
In this case, {{Code|HelloWorld.c}} would be the &#039;&#039;&#039;.c&#039;&#039;&#039; file specific to your device.  After using {{Code|bcc32}}, you will have an executable named {{Code|HelloWorld}} that you can run.  &lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:Borland HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C/C++ code with Borland. In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as the examples [[#Use Our Examples 4 |above]]. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
===GCC on Windows===&lt;br /&gt;
&lt;br /&gt;
====Cygwin/MinGW====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Download the [http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz examples] and unpack them into a folder. Afterwards, unpack the examples. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example. Locate the {{Code|HelloWorld.c}} file and type the following to compile the file and link the Phidget C/C++ library in a command line prompt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Cygwin&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  gcc example.c -o HelloWorld -I&amp;quot;/cygdrive/c/Program Files/Phidgets&amp;quot; -L&amp;quot;/cygdrive/c/Program Files/Phidgets&amp;quot; -lphidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;MinGW&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  gcc example.c -o HelloWorld -I&amp;quot;C:\Program Files\Phidgets&amp;quot; -L&amp;quot;C:\Program Files\Phidgets&amp;quot; -lphidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After using gcc, you will have an executable named {{Code|HelloWorld}} that you can run.  &lt;br /&gt;
It is assumed that {{Code|phidget21.h}} and {{Code|phidget21.lib}} are placed in {{Code|C:\Program Files\Phidgets}}. If the files are placed in another location, please adjust the paths to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
After using {{Code|gcc}}, you will have an executable named {{Code|HelloWorld}} that you can run.  &lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:C MinGW HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C/C++ code with Cygwin/MinGW in your favourite text editor. In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as shown in the [[#Use Our Examples 5| Use Our Examples]] section above. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
===Dev C++===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz examples] and unpack them into a folder. Here, you can find example programs for all the devices. {{FindYourDevice}}  You will need this example source code to be copied into your Dev C++ project later on. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
2. In order to control Phidgets with Dev C++, we will use the {{Code|reimp}} tool to convert the {{Code|phidget21.lib}} to a format that Dev C++ accepts. Download the [http://www.phidgets.com reimp tool].&lt;br /&gt;
&lt;br /&gt;
3. Open up command line and traverse to the directory containing the reimp tool. Type the following command to create {{Code|libphidget21.a}}.&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  reimp.exe &amp;quot;C:\Program Files\Phidgets\phidget21.lib&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
The command above assumes that the {{Code|phidget21.lib}} is in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly. Please note that the 64 bit version of {{Code|phidget21.lib}} is not supported on Dev C/C++. Please use the 32 bit version of {{Code|phidget21.lib}}.&lt;br /&gt;
&lt;br /&gt;
4. Place {{Code|libphidget21.a}} in {{Code|&amp;lt;Dev-Cpp Install Directory&amp;gt;/lib}}.&lt;br /&gt;
&lt;br /&gt;
5. Next, a new project will need to be created. Generate a new console application with a descriptive name such as PhidgetTest. Please select C as the project type.&lt;br /&gt;
&lt;br /&gt;
[[File:DevC New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
6. Next, the project settings needs to be set up. Navigate to Project Options &amp;amp;rarr; Directories &amp;amp;rarr; Include Directories.&lt;br /&gt;
&lt;br /&gt;
7. Add a new path to {{Code|C:\Program Files\Phidgets}}. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:DevC Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
8. Navigate to Project Options &amp;amp;rarr; Parameters &amp;amp;rarr; Linker.&lt;br /&gt;
&lt;br /&gt;
9. Add {{Code|-lphidget21}} to the field. This step will find the {{Code|libphidget21.a}} file in {{Code|&amp;lt;Dev-Cpp Install Directory&amp;gt;/lib}}. &lt;br /&gt;
&lt;br /&gt;
[[File:DevC Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
10. To import the {{Code|HelloWorld}} program into your project, please open up {{Code|main.c}} in the editor.&lt;br /&gt;
&lt;br /&gt;
11. An empty C file will pop up. Please copy and paste the contents of the example program. &lt;br /&gt;
&lt;br /&gt;
[[File:DevC Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
12. Now, you can run the example. Click on Execute &amp;amp;rarr; Compile &amp;amp; Run.&lt;br /&gt;
&lt;br /&gt;
[[File:DevC Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
13. This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:DevC HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. Please see the [[#Use Our Examples 6 | Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as the [[#Use Our Examples 6 | examples]] above. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
C/C++ has excellent support on OS X through the gcc compiler.  &lt;br /&gt;
&lt;br /&gt;
The first step in using C/C++ on Mac is to install the Phidget C/C++ library.  Compile and install them as explained on the Getting Started guide for your device, which you can find on its product page on [http://www.phidgets.com our main website].  Then, the [[OS - OS X#Description of files|OS - OS X]] page also describes the different Phidget files, their installed locations, and their roles. &lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
After installing the main Phidget library for OS X as above, you&#039;re ready to download the [http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz examples]. Afterwards, unzip the file. To run the example code, you&#039;ll need to find the source code &#039;&#039;for your specific device&#039;&#039;.  Then, compile the code under your platform and run it.&lt;br /&gt;
&lt;br /&gt;
To compile, link the Phidget C/C++ library, and build an executable binary on OS X, do (for example, depending on the Headers location):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  gcc example.c -o example -framework Phidget21 -I/Library/Frameworks/Phidget21.framework/Headers&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After using gcc, you will have an executable named {{Code|example}} that you can run.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as shown in the [[#Use Our Examples 7|Use Our Example]] section above.&lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples.  Even more help and references are provided from there.&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
C/C++ has support on Linux through the gcc compiler.  &lt;br /&gt;
&lt;br /&gt;
The first step in using C/C++ on Linux is to install the Phidget libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
After installing the Phidget libraries for Linux as above, you&#039;re ready to download and run the examples:&lt;br /&gt;
*[http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz Generic C/C++ Examples]&lt;br /&gt;
&lt;br /&gt;
To run the example code, you&#039;ll need to download and unpack the examples, and then find the source code for your device.  {{FindYourDevice}}  You can also use the HelloWorld program, which a basic program that can run with any Phidget.  Then, compile the code under your platform and run it.  When compiling, you need to link to the Phidget library.&lt;br /&gt;
&lt;br /&gt;
To compile, link the Phidget libraries and build a binary executable on Linux, do the following in a terminal in the directory with {{Code|example.c}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  gcc example.c -o example -lphidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, {{Code|example.c}} would be the &#039;&#039;&#039;.c&#039;&#039;&#039; file specific to your device.  After using gcc, you will have an executable named {{Code|example}} that you can run.  &lt;br /&gt;
&lt;br /&gt;
On Linux, if you have not set up [[OS_-_Linux#Setting_udev_Rules | your udev rules for USB access]], you will need to run the program &#039;&#039;&#039;as root&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  sudo ./example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C/C++ code on Linux, such as within a text editor like Emacs, Vi, Gedit, or Kate.  In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as the examples above. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==Windows CE==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C/C++ programs on Windows CE depend on the following files, which the Windows CE installer puts onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  It is placed in {{Code|\Windows}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|PhidgetWebService21.exe}}&amp;lt;/b&amp;gt; is used to control Phidgets remotely across a network using the [[#WebService | PhidgetWebService]]. It can be placed anywhere on the system.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.lib}}&amp;lt;/b&amp;gt; is used by your compiler to link to the dll.  Your compiler has to know where this file is.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.h}}&amp;lt;/b&amp;gt; lists all the Phidget API function calls available to your code.  Your compiler also has to know where this file is. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget.dll}}&amp;lt;/b&amp;gt; is the Phidgets kernel driver. It is placed in {{Code|\Windows}}.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2005/2008/2010===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Currently, we have no example code for C/C++ on Windows CE. However, set up is very much the same as what it would be with [[#Visual Studio 2005/2008/2010 |Visual Studio 2005/2008/2010]] in Windows. The {{Code|phidget21.h}} and {{Code|phidget21.lib}} can be downloaded [http://www.phidgets.com/downloads/libraries/Phidget21-wincedevel.zip here].&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C++: Win32 Smart Device project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 1.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Select {{Code|Next}}.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 2.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Select the SDK(s) that you want to code against and elect {{Code|Next}}.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 3.PNG|link=|alt=SDKs]]&lt;br /&gt;
&lt;br /&gt;
4. Create a console application and select {{Code|Next}}.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 4.PNG|link=|alt=Create Console Application]]&lt;br /&gt;
&lt;br /&gt;
3. Open the project properties window.&lt;br /&gt;
&lt;br /&gt;
4. Navigate to Configuration Properties &amp;amp;rarr; C/C++.&lt;br /&gt;
&lt;br /&gt;
5. Add {{Code|&amp;quot;C:\Program Files\Phidgets&amp;quot;}} to the additional directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Configuration Properties &amp;amp;rarr; Linker &amp;amp;rarr; Input.&lt;br /&gt;
&lt;br /&gt;
7. Edit the additional dependencies and add {{Code|&amp;quot;C:\Program  Files\Phidgets\phidget21.lib&amp;quot;}}. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
8. The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  &lt;br /&gt;
&lt;br /&gt;
Your main reference for writing C code will be our C/C++ API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in C/C++|[http://www.phidgets.com/documentation/Phidget21_C_Doc.zip C/C++ API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In C/C++, you can name these &#039;&#039;&#039;event&#039;&#039;&#039; functions whatever you like.  You will then pass them as function pointers to the Phidget library below in the Main Code section.  This hooks them into the actual events when they occur. &amp;lt;br&amp;gt; &lt;br /&gt;
In the example code, the event functions common to all Phidgets are called things like &#039;&#039;&#039;AttachHandler()&#039;&#039;&#039; and &#039;&#039;&#039;DetachHandler()&#039;&#039;&#039;, etc.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Some event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.&lt;br /&gt;
Other functions are given in the examples to show you more detail on using your Phidget.  For example, &#039;&#039;&#039;DeviceInitialize()&#039;&#039;&#039; will show what needs to be set up for your Phidget before using it.&lt;br /&gt;
|Creating a Phidget software object in C is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating an object with the {{Code|CPhidgetSpatialHandle}} type, and then initializing it using the {{Code|CPhidgetSpatial_create function}}.  The examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Other C calls follow a similar syntax - {{Code|CPhidgetXXX_function}}, where XXX is the name of your device, and function is an action available from the API for your specific Phidget.|&lt;br /&gt;
[http://www.phidgets.com/documentation/Phidget21_C_Doc.zip C/C++ API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
When programming in C/C++, you&#039;re in luck.  All of our code snippet examples on our [[General Phidget Programming]] page are in both C++ and Java.  Therefore, we do not include any here, because that page is much more in-depth, and you won&#039;t have to have two pages open at once.  So head over there, and start writing code!&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
===Issue: I am using a non US-English version of Windows, and the Visual C/C++ examples run into a linker error===&lt;br /&gt;
Affected Operating Systems: &#039;&#039;&#039;Windows&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The example projects, by default finds the {{Code|phidget21.h}} and {{Code|phidget21.lib}} in ${SystemDrive}\Program Files\Phidgets. If you are using a non US-English version of Windows, the Phidget drivers may be installed into a different location. To resolve, you will have to modify the paths to these two files. For instructions, please see your environment/compiler section.&lt;/div&gt;</summary>
		<author><name>192.168.3.183</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_C&amp;diff=19777</id>
		<title>Language - C</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_C&amp;diff=19777"/>
		<updated>2012-05-16T19:09:45Z</updated>

		<summary type="html">&lt;p&gt;192.168.3.183: /* OS X */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-C++.png|link=|alt=C/C++|64x64px]]|C++ is a general purpose, cross-platform programming language with a vast user base.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|C/C++|the complete Phidget API, including events|all Phidget devices.|Windows 2000/XP/Vista/7(environments include [[#Visual Studio | Visual Studio]], [[#Borland | Borland]], [[#Cygwin/MinGW | Cygwin, and MinGW]]), [[#Windows CE | Windows CE]], [[#OS X | OS X]], and [[#Linux | Linux]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
{{QuickDownloads|C/C++|&lt;br /&gt;
{{APIQuickDownloads|http://www.phidgets.com/documentation/Phidget21_C_Doc.zip}}|&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/VCpp.zip Visual Studio 2005/2008/2010|}}&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz Generic|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|http://www.phidgets.com/downloads/libraries/phidget21bcc.zip|Borland(Windows)|}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with C/C++==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C/C++ programs on Windows depend on three files, which the installers in [[#Libraries and Drivers|Quick Downloads]] put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.lib}}&amp;lt;/b&amp;gt; is used by your compiler to link to the dll.  Your compiler has to know where this file is, by default our installer puts {{Code|phidget21.lib}} into {{Code|C:\Program Files\Phidgets}}, so you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. {{Code|phidget21.lib}} is written to be compatible with most compilers - but your specific compiler may need a different format. Check our documentation for your specific compiler for details. Please note that we provide versions of the {{Code|phidget21.lib}} that are specifically optimized for 32-bit or 64-bit systems. If you are using a 64 bit versions of Windows, the {{Code|phidget21.lib}} is placed in {{Code|C:\Program Files\Phidgets}}; The 32 bit version of {{Code|phidget21.lib}} is placed in {{Code|C:\Program Files\Phidgets\x86}}. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.h}}&amp;lt;/b&amp;gt; lists all the Phidget API function calls available to your code.  Your compiler also has to know where this file is.  By default, our installer puts {{Code|phidget21.h}} into {{Code|C:\Program Files\Phidgets}} so you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download all three [http://www.phidgets.com/downloads/libraries/phidget21-x86.zip files] and manually install them where you want; refer to our [[OS_-_Windows#Manual_File_Installation | Manual Installation Instructions]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for [[#Visual Studio 2005/2008/2010 | Visual Studio 2005/2008/2010]], [[#Visual Studio 2003 | Visual Studio 2003]], [[#Visual Studio C++ 6.0 | Visual Studio 6]], [[#Borland| Borland]], [[#Cygwin/MinGW | Cygwin/MinGW]], and [[#Dev C++ | Dev C++]].&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
&lt;br /&gt;
C++/CLI (which used to be called Managed C++) is very different from mainstream C/C++.  If you must use C++/CLI, consider calling the Phidget .NET library, instead of the C API normally used from C/C++.  We have no documentation for using C++/CLI.&lt;br /&gt;
&lt;br /&gt;
Microsoft makes free versions of Visual Studio available known as Express Editions.  The Express editions are suitable for most applications, but are limited in features for more complex applications. Please see [http://www.microsoft.com/visualstudio Microsoft Visual Studio] for more information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Visual Studio 2005/2008/2010====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
To run the examples, you first download the [http://www.phidgets.com/downloads/examples/VCpp.zip examples] and unpack them into a folder.  To load all projects in Visual Studio, go to File &amp;amp;rarr; Open &amp;amp;rarr; Project &amp;amp;rarr; Solution, and open {{Code|Visual Studio Phidgets Examples.sln}} in the {{Code|VCpp}} folder of the examples.&lt;br /&gt;
&lt;br /&gt;
Since the examples were written in Visual Studio 2005, if you are opening the examples in Visual Studio 2008/2010, you will need to go through the Visual Studio Conversion Wizard to open and convert the 2005 project. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Conversion Wizard.PNG|link=|alt=Conversion Wizard]]&lt;br /&gt;
&lt;br /&gt;
This will load all of the examples available for C/C++. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
Start by setting the {{Code|HelloWorld}} project as your start up project.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 StartUp Project.PNG|link=|alt=Start Up Project]]&lt;br /&gt;
&lt;br /&gt;
To run the example, click on Debug &amp;amp;rarr; Start Debugging. Please note that the projects, by default try to find the {{Code|phidget21.h}} and {{Code|phidget21.lib}} in the {{Code|$(SystemDrive)\Program Files\Phidgets}}. If you have these files installed in another location, please change the path to the file&#039;s location accordingly. Please see the [[#Write Your Own Code | Write Your Own Code]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C++: Win32 Console Application project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Next, select Console Application.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 New Project 2.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Open the project properties window.&lt;br /&gt;
&lt;br /&gt;
4. Navigate to Configuration Properties &amp;amp;rarr; C/C++.&lt;br /&gt;
&lt;br /&gt;
5. Add {{Code|&amp;quot;C:\Program Files\Phidgets&amp;quot;}} to the additional directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Configuration Properties &amp;amp;rarr; Linker &amp;amp;rarr; Input.&lt;br /&gt;
&lt;br /&gt;
7. Edit the additional dependencies and add {{Code|&amp;quot;C:\Program  Files\Phidgets\phidget21.lib&amp;quot;}}. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
8. The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
====Visual Studio 2003====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Start by downloading the [http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz examples]. You can import these examples into a Visual Studio 2003 C++ project. Afterwards, unpack them into a folder. Here, you can find example programs for all the devices. You will need this example source code to be copied into your C++ project later on. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example. &lt;br /&gt;
&lt;br /&gt;
2. A new project will need to be created. Generate a new Visual C++ empty project(.NET) with a descriptive name such as HelloWorld.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Create a new C++ file by adding a new item to the source files folder. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 New File.PNG|link=|alt=New File]]&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 New File 2.PNG|link=|alt=New File]]&lt;br /&gt;
&lt;br /&gt;
4. An empty C++ file will pop up. Please copy and paste the contents of the {{Code|HelloWorld.c}} program into here. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
5. Next, the project setting needs to be set up. Open the project properties window.&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Configuration Properties &amp;amp;rarr; C/C++.&lt;br /&gt;
&lt;br /&gt;
7. Add {{Code|&amp;quot;C:\Program Files\Phidgets&amp;quot;}} to the additional include directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
8. Navigate to Configuration Properties &amp;amp;rarr; Linker &amp;amp;rarr; Input.&lt;br /&gt;
&lt;br /&gt;
9. Add {{Code|&amp;quot;C:\Program  Files\Phidgets\phidget21.lib&amp;quot;}} to the additional dependencies field. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
10. Now, you can run the example. Click on Debug &amp;amp;rarr; Start Without Debugging.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
11. This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your  development environment to properly link the Phidget C/C++ library. Please see the [[#Use Our Examples 2 | Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Visual Studio C++ 6.0====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz examples] and unpack them into a folder. Here, you can find example programs for all the devices. You will need this example source code to be copied into your C++ project later on. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
2. Next, a new project will need to be created. Generate a new Win32 Console Application project with a descriptive name such as HelloWorld.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Create an empty project.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 New Project 2.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
4. Next, the project settings needs to be set up. Navigate to Project &amp;amp;rarr; Settings &amp;amp;rarr; C/C++ &amp;amp;rarr; Preprocessor.&lt;br /&gt;
&lt;br /&gt;
5. Add {{Code|C:\Program Files\Phidgets}} to the additional include directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Project &amp;amp;rarr; Settings &amp;amp;rarr; Link &amp;amp;rarr; Input &amp;amp;rarr; Additional library Path.&lt;br /&gt;
&lt;br /&gt;
7. Add {{Code|phidget21.lib}} to the object/library modules field.&lt;br /&gt;
&lt;br /&gt;
8. Add {{Code|C:\Program  Files\Phidgets}} to the additional library path. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
To import the example program into your project, please:&lt;br /&gt;
&lt;br /&gt;
9. Create a new C++ file by navigating to File &amp;amp;rarr; New &amp;amp;rarr; Files &amp;amp;rarr; C++ Source File and enter a descriptive name such as HelloWorld.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 New File.PNG|link=|alt=New File]]&lt;br /&gt;
&lt;br /&gt;
10. An empty C++ file will pop up. Please copy and paste the contents of the {{Code|HelloWorld.c}} program here.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
11. Now, you can run the example. Click on Build &amp;amp;rarr; Execute.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
12. This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. Please see the [[#Use Our Examples 3 | Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as shown in the [[#Use Our Examples 3 | Use Our Examples]] section. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
===Borland===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
In addition to running one of the two [[#Libraries and Drivers:| Windows Installers]] above (which you probably already have if you worked through the &#039;&#039;Getting Started&#039;&#039; page for your device), you will need the [http://www.phidgets.com/downloads/libraries/phidget21bcc.zip Borland C++ Libraries]. {{Code|phidget21bcc.lib}} is typically placed in {{Code|C:\Program Files\Phidgets}}, but you are free to place it in any directory you wish.&lt;br /&gt;
&lt;br /&gt;
After installing the Phidget C/C++ library, you&#039;re ready to download the [http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz examples] and run the examples.&lt;br /&gt;
&lt;br /&gt;
Afterwards, unpack the examples. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example. Locate the {{Code|HelloWorld.c}} file and type the following to compile the file and link the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
To compile, link the Phidget C/C++ library and build a binary executable, enter the following in a command line prompt in the directory with {{Code|HelloWorld.c}}:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  bcc32 -eHelloWorld -I&amp;quot;C:\Program Files\Phidgets&amp;quot; -L&amp;quot;C:\Program Files\Phidgets&amp;quot; phidget21bcc.lib HelloWorld.c&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is assumed that {{Code|phidget21bcc.lib}} and {{Code|phidget21.h}} are placed in {{Code|C:\Program Files\Phidgets}}. If the files are placed in another location, please adjust the paths to both of the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
In this case, {{Code|HelloWorld.c}} would be the &#039;&#039;&#039;.c&#039;&#039;&#039; file specific to your device.  After using {{Code|bcc32}}, you will have an executable named {{Code|HelloWorld}} that you can run.  &lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:Borland HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C/C++ code with Borland. In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as the examples [[#Use Our Examples 4 |above]]. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
===GCC on Windows===&lt;br /&gt;
&lt;br /&gt;
====Cygwin/MinGW====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Download the [http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz examples] and unpack them into a folder. Afterwards, unpack the examples. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example. Locate the {{Code|HelloWorld.c}} file and type the following to compile the file and link the Phidget C/C++ library in a command line prompt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Cygwin&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  gcc example.c -o HelloWorld -I&amp;quot;/cygdrive/c/Program Files/Phidgets&amp;quot; -L&amp;quot;/cygdrive/c/Program Files/Phidgets&amp;quot; -lphidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;MinGW&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  gcc example.c -o HelloWorld -I&amp;quot;C:\Program Files\Phidgets&amp;quot; -L&amp;quot;C:\Program Files\Phidgets&amp;quot; -lphidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After using gcc, you will have an executable named {{Code|HelloWorld}} that you can run.  &lt;br /&gt;
It is assumed that {{Code|phidget21.h}} and {{Code|phidget21.lib}} are placed in {{Code|C:\Program Files\Phidgets}}. If the files are placed in another location, please adjust the paths to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
After using {{Code|gcc}}, you will have an executable named {{Code|HelloWorld}} that you can run.  &lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:C MinGW HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C/C++ code with Cygwin/MinGW in your favourite text editor. In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as shown in the [[#Use Our Examples 5| Use Our Examples]] section above. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
===Dev C++===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz examples] and unpack them into a folder. Here, you can find example programs for all the devices. {{FindYourDevice}}  You will need this example source code to be copied into your Dev C++ project later on. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
2. In order to control Phidgets with Dev C++, we will use the {{Code|reimp}} tool to convert the {{Code|phidget21.lib}} to a format that Dev C++ accepts. Download the [http://www.phidgets.com reimp tool].&lt;br /&gt;
&lt;br /&gt;
3. Open up command line and traverse to the directory containing the reimp tool. Type the following command to create {{Code|libphidget21.a}}.&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  reimp.exe &amp;quot;C:\Program Files\Phidgets\phidget21.lib&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
The command above assumes that the {{Code|phidget21.lib}} is in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly. Please note that the 64 bit version of {{Code|phidget21.lib}} is not supported on Dev C/C++. Please use the 32 bit version of {{Code|phidget21.lib}}.&lt;br /&gt;
&lt;br /&gt;
4. Place {{Code|libphidget21.a}} in {{Code|&amp;lt;Dev-Cpp Install Directory&amp;gt;/lib}}.&lt;br /&gt;
&lt;br /&gt;
5. Next, a new project will need to be created. Generate a new console application with a descriptive name such as PhidgetTest. Please select C as the project type.&lt;br /&gt;
&lt;br /&gt;
[[File:DevC New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
6. Next, the project settings needs to be set up. Navigate to Project Options &amp;amp;rarr; Directories &amp;amp;rarr; Include Directories.&lt;br /&gt;
&lt;br /&gt;
7. Add a new path to {{Code|C:\Program Files\Phidgets}}. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:DevC Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
8. Navigate to Project Options &amp;amp;rarr; Parameters &amp;amp;rarr; Linker.&lt;br /&gt;
&lt;br /&gt;
9. Add {{Code|-lphidget21}} to the field. This step will find the {{Code|libphidget21.a}} file in {{Code|&amp;lt;Dev-Cpp Install Directory&amp;gt;/lib}}. &lt;br /&gt;
&lt;br /&gt;
[[File:DevC Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
10. To import the {{Code|HelloWorld}} program into your project, please open up {{Code|main.c}} in the editor.&lt;br /&gt;
&lt;br /&gt;
11. An empty C file will pop up. Please copy and paste the contents of the example program. &lt;br /&gt;
&lt;br /&gt;
[[File:DevC Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
12. Now, you can run the example. Click on Execute &amp;amp;rarr; Compile &amp;amp; Run.&lt;br /&gt;
&lt;br /&gt;
[[File:DevC Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
13. This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:DevC HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. Please see the [[#Use Our Examples 6 | Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as the [[#Use Our Examples 6 | examples]] above. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
C/C++ has excellent support on OS X through the gcc compiler.  &lt;br /&gt;
&lt;br /&gt;
The first step in using C/C++ on Mac is to install the Phidget C/C++ library.  Compile and install them as explained on the Getting Started guide for your device, which you can find on its product page on [http://www.phidgets.com our main website].  Then, the [[OS - OS X#Description of files]] page also describes the different Phidget files, their installed locations, and their roles. &lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
After installing the main Phidget library for OS X as above, you&#039;re ready to download the [http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz examples]. Afterwards, unzip the file. To run the example code, you&#039;ll need to find the source code &#039;&#039;for your specific device&#039;&#039;.  Then, compile the code under your platform and run it.&lt;br /&gt;
&lt;br /&gt;
To compile, link the Phidget C/C++ library, and build an executable binary on OS X, do (for example, depending on the Headers location):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  gcc example.c -o example -framework Phidget21 -I/Library/Frameworks/Phidget21.framework/Headers&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After using gcc, you will have an executable named {{Code|example}} that you can run.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as shown in the [[#Use Our Examples 7|Use Our Example]] section above.&lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples.  Even more help and references are provided from there.&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
C/C++ has support on Linux through the gcc compiler.  &lt;br /&gt;
&lt;br /&gt;
The first step in using C/C++ on Linux is to install the Phidget libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
After installing the Phidget libraries for Linux as above, you&#039;re ready to download and run the examples:&lt;br /&gt;
*[http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz Generic C/C++ Examples]&lt;br /&gt;
&lt;br /&gt;
To run the example code, you&#039;ll need to download and unpack the examples, and then find the source code for your device.  {{FindYourDevice}}  You can also use the HelloWorld program, which a basic program that can run with any Phidget.  Then, compile the code under your platform and run it.  When compiling, you need to link to the Phidget library.&lt;br /&gt;
&lt;br /&gt;
To compile, link the Phidget libraries and build a binary executable on Linux, do the following in a terminal in the directory with {{Code|example.c}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  gcc example.c -o example -lphidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, {{Code|example.c}} would be the &#039;&#039;&#039;.c&#039;&#039;&#039; file specific to your device.  After using gcc, you will have an executable named {{Code|example}} that you can run.  &lt;br /&gt;
&lt;br /&gt;
On Linux, if you have not set up [[OS_-_Linux#Setting_udev_Rules | your udev rules for USB access]], you will need to run the program &#039;&#039;&#039;as root&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  sudo ./example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C/C++ code on Linux, such as within a text editor like Emacs, Vi, Gedit, or Kate.  In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as the examples above. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==Windows CE==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C/C++ programs on Windows CE depend on the following files, which the Windows CE installer puts onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  It is placed in {{Code|\Windows}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|PhidgetWebService21.exe}}&amp;lt;/b&amp;gt; is used to control Phidgets remotely across a network using the [[#WebService | PhidgetWebService]]. It can be placed anywhere on the system.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.lib}}&amp;lt;/b&amp;gt; is used by your compiler to link to the dll.  Your compiler has to know where this file is.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.h}}&amp;lt;/b&amp;gt; lists all the Phidget API function calls available to your code.  Your compiler also has to know where this file is. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget.dll}}&amp;lt;/b&amp;gt; is the Phidgets kernel driver. It is placed in {{Code|\Windows}}.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2005/2008/2010===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Currently, we have no example code for C/C++ on Windows CE. However, set up is very much the same as what it would be with [[#Visual Studio 2005/2008/2010 |Visual Studio 2005/2008/2010]] in Windows. The {{Code|phidget21.h}} and {{Code|phidget21.lib}} can be downloaded [http://www.phidgets.com/downloads/libraries/Phidget21-wincedevel.zip here].&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C++: Win32 Smart Device project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 1.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Select {{Code|Next}}.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 2.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Select the SDK(s) that you want to code against and elect {{Code|Next}}.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 3.PNG|link=|alt=SDKs]]&lt;br /&gt;
&lt;br /&gt;
4. Create a console application and select {{Code|Next}}.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 4.PNG|link=|alt=Create Console Application]]&lt;br /&gt;
&lt;br /&gt;
3. Open the project properties window.&lt;br /&gt;
&lt;br /&gt;
4. Navigate to Configuration Properties &amp;amp;rarr; C/C++.&lt;br /&gt;
&lt;br /&gt;
5. Add {{Code|&amp;quot;C:\Program Files\Phidgets&amp;quot;}} to the additional directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Configuration Properties &amp;amp;rarr; Linker &amp;amp;rarr; Input.&lt;br /&gt;
&lt;br /&gt;
7. Edit the additional dependencies and add {{Code|&amp;quot;C:\Program  Files\Phidgets\phidget21.lib&amp;quot;}}. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
8. The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  &lt;br /&gt;
&lt;br /&gt;
Your main reference for writing C code will be our C/C++ API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in C/C++|[http://www.phidgets.com/documentation/Phidget21_C_Doc.zip C/C++ API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In C/C++, you can name these &#039;&#039;&#039;event&#039;&#039;&#039; functions whatever you like.  You will then pass them as function pointers to the Phidget library below in the Main Code section.  This hooks them into the actual events when they occur. &amp;lt;br&amp;gt; &lt;br /&gt;
In the example code, the event functions common to all Phidgets are called things like &#039;&#039;&#039;AttachHandler()&#039;&#039;&#039; and &#039;&#039;&#039;DetachHandler()&#039;&#039;&#039;, etc.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Some event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.&lt;br /&gt;
Other functions are given in the examples to show you more detail on using your Phidget.  For example, &#039;&#039;&#039;DeviceInitialize()&#039;&#039;&#039; will show what needs to be set up for your Phidget before using it.&lt;br /&gt;
|Creating a Phidget software object in C is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating an object with the {{Code|CPhidgetSpatialHandle}} type, and then initializing it using the {{Code|CPhidgetSpatial_create function}}.  The examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Other C calls follow a similar syntax - {{Code|CPhidgetXXX_function}}, where XXX is the name of your device, and function is an action available from the API for your specific Phidget.|&lt;br /&gt;
[http://www.phidgets.com/documentation/Phidget21_C_Doc.zip C/C++ API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
When programming in C/C++, you&#039;re in luck.  All of our code snippet examples on our [[General Phidget Programming]] page are in both C++ and Java.  Therefore, we do not include any here, because that page is much more in-depth, and you won&#039;t have to have two pages open at once.  So head over there, and start writing code!&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
===Issue: I am using a non US-English version of Windows, and the Visual C/C++ examples run into a linker error===&lt;br /&gt;
Affected Operating Systems: &#039;&#039;&#039;Windows&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The example projects, by default finds the {{Code|phidget21.h}} and {{Code|phidget21.lib}} in ${SystemDrive}\Program Files\Phidgets. If you are using a non US-English version of Windows, the Phidget drivers may be installed into a different location. To resolve, you will have to modify the paths to these two files. For instructions, please see your environment/compiler section.&lt;/div&gt;</summary>
		<author><name>192.168.3.183</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_C&amp;diff=19776</id>
		<title>Language - C</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_C&amp;diff=19776"/>
		<updated>2012-05-16T19:06:02Z</updated>

		<summary type="html">&lt;p&gt;192.168.3.183: /* OS X */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-C++.png|link=|alt=C/C++|64x64px]]|C++ is a general purpose, cross-platform programming language with a vast user base.}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|C/C++|the complete Phidget API, including events|all Phidget devices.|Windows 2000/XP/Vista/7(environments include [[#Visual Studio | Visual Studio]], [[#Borland | Borland]], [[#Cygwin/MinGW | Cygwin, and MinGW]]), [[#Windows CE | Windows CE]], [[#OS X | OS X]], and [[#Linux | Linux]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
{{QuickDownloads|C/C++|&lt;br /&gt;
{{APIQuickDownloads|http://www.phidgets.com/documentation/Phidget21_C_Doc.zip}}|&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/VCpp.zip Visual Studio 2005/2008/2010|}}&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz Generic|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|http://www.phidgets.com/downloads/libraries/phidget21bcc.zip|Borland(Windows)|}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with C/C++==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C/C++ programs on Windows depend on three files, which the installers in [[#Libraries and Drivers|Quick Downloads]] put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.lib}}&amp;lt;/b&amp;gt; is used by your compiler to link to the dll.  Your compiler has to know where this file is, by default our installer puts {{Code|phidget21.lib}} into {{Code|C:\Program Files\Phidgets}}, so you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. {{Code|phidget21.lib}} is written to be compatible with most compilers - but your specific compiler may need a different format. Check our documentation for your specific compiler for details. Please note that we provide versions of the {{Code|phidget21.lib}} that are specifically optimized for 32-bit or 64-bit systems. If you are using a 64 bit versions of Windows, the {{Code|phidget21.lib}} is placed in {{Code|C:\Program Files\Phidgets}}; The 32 bit version of {{Code|phidget21.lib}} is placed in {{Code|C:\Program Files\Phidgets\x86}}. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.h}}&amp;lt;/b&amp;gt; lists all the Phidget API function calls available to your code.  Your compiler also has to know where this file is.  By default, our installer puts {{Code|phidget21.h}} into {{Code|C:\Program Files\Phidgets}} so you can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download all three [http://www.phidgets.com/downloads/libraries/phidget21-x86.zip files] and manually install them where you want; refer to our [[OS_-_Windows#Manual_File_Installation | Manual Installation Instructions]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for [[#Visual Studio 2005/2008/2010 | Visual Studio 2005/2008/2010]], [[#Visual Studio 2003 | Visual Studio 2003]], [[#Visual Studio C++ 6.0 | Visual Studio 6]], [[#Borland| Borland]], [[#Cygwin/MinGW | Cygwin/MinGW]], and [[#Dev C++ | Dev C++]].&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
&lt;br /&gt;
C++/CLI (which used to be called Managed C++) is very different from mainstream C/C++.  If you must use C++/CLI, consider calling the Phidget .NET library, instead of the C API normally used from C/C++.  We have no documentation for using C++/CLI.&lt;br /&gt;
&lt;br /&gt;
Microsoft makes free versions of Visual Studio available known as Express Editions.  The Express editions are suitable for most applications, but are limited in features for more complex applications. Please see [http://www.microsoft.com/visualstudio Microsoft Visual Studio] for more information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Visual Studio 2005/2008/2010====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
To run the examples, you first download the [http://www.phidgets.com/downloads/examples/VCpp.zip examples] and unpack them into a folder.  To load all projects in Visual Studio, go to File &amp;amp;rarr; Open &amp;amp;rarr; Project &amp;amp;rarr; Solution, and open {{Code|Visual Studio Phidgets Examples.sln}} in the {{Code|VCpp}} folder of the examples.&lt;br /&gt;
&lt;br /&gt;
Since the examples were written in Visual Studio 2005, if you are opening the examples in Visual Studio 2008/2010, you will need to go through the Visual Studio Conversion Wizard to open and convert the 2005 project. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Conversion Wizard.PNG|link=|alt=Conversion Wizard]]&lt;br /&gt;
&lt;br /&gt;
This will load all of the examples available for C/C++. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
Start by setting the {{Code|HelloWorld}} project as your start up project.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 StartUp Project.PNG|link=|alt=Start Up Project]]&lt;br /&gt;
&lt;br /&gt;
To run the example, click on Debug &amp;amp;rarr; Start Debugging. Please note that the projects, by default try to find the {{Code|phidget21.h}} and {{Code|phidget21.lib}} in the {{Code|$(SystemDrive)\Program Files\Phidgets}}. If you have these files installed in another location, please change the path to the file&#039;s location accordingly. Please see the [[#Write Your Own Code | Write Your Own Code]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C++: Win32 Console Application project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Next, select Console Application.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 New Project 2.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Open the project properties window.&lt;br /&gt;
&lt;br /&gt;
4. Navigate to Configuration Properties &amp;amp;rarr; C/C++.&lt;br /&gt;
&lt;br /&gt;
5. Add {{Code|&amp;quot;C:\Program Files\Phidgets&amp;quot;}} to the additional directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Configuration Properties &amp;amp;rarr; Linker &amp;amp;rarr; Input.&lt;br /&gt;
&lt;br /&gt;
7. Edit the additional dependencies and add {{Code|&amp;quot;C:\Program  Files\Phidgets\phidget21.lib&amp;quot;}}. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
8. The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
====Visual Studio 2003====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Start by downloading the [http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz examples]. You can import these examples into a Visual Studio 2003 C++ project. Afterwards, unpack them into a folder. Here, you can find example programs for all the devices. You will need this example source code to be copied into your C++ project later on. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example. &lt;br /&gt;
&lt;br /&gt;
2. A new project will need to be created. Generate a new Visual C++ empty project(.NET) with a descriptive name such as HelloWorld.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Create a new C++ file by adding a new item to the source files folder. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 New File.PNG|link=|alt=New File]]&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 New File 2.PNG|link=|alt=New File]]&lt;br /&gt;
&lt;br /&gt;
4. An empty C++ file will pop up. Please copy and paste the contents of the {{Code|HelloWorld.c}} program into here. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
5. Next, the project setting needs to be set up. Open the project properties window.&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Configuration Properties &amp;amp;rarr; C/C++.&lt;br /&gt;
&lt;br /&gt;
7. Add {{Code|&amp;quot;C:\Program Files\Phidgets&amp;quot;}} to the additional include directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
8. Navigate to Configuration Properties &amp;amp;rarr; Linker &amp;amp;rarr; Input.&lt;br /&gt;
&lt;br /&gt;
9. Add {{Code|&amp;quot;C:\Program  Files\Phidgets\phidget21.lib&amp;quot;}} to the additional dependencies field. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
10. Now, you can run the example. Click on Debug &amp;amp;rarr; Start Without Debugging.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
11. This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:VS2003 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your  development environment to properly link the Phidget C/C++ library. Please see the [[#Use Our Examples 2 | Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Visual Studio C++ 6.0====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz examples] and unpack them into a folder. Here, you can find example programs for all the devices. You will need this example source code to be copied into your C++ project later on. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
2. Next, a new project will need to be created. Generate a new Win32 Console Application project with a descriptive name such as HelloWorld.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Create an empty project.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 New Project 2.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
4. Next, the project settings needs to be set up. Navigate to Project &amp;amp;rarr; Settings &amp;amp;rarr; C/C++ &amp;amp;rarr; Preprocessor.&lt;br /&gt;
&lt;br /&gt;
5. Add {{Code|C:\Program Files\Phidgets}} to the additional include directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Project &amp;amp;rarr; Settings &amp;amp;rarr; Link &amp;amp;rarr; Input &amp;amp;rarr; Additional library Path.&lt;br /&gt;
&lt;br /&gt;
7. Add {{Code|phidget21.lib}} to the object/library modules field.&lt;br /&gt;
&lt;br /&gt;
8. Add {{Code|C:\Program  Files\Phidgets}} to the additional library path. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
To import the example program into your project, please:&lt;br /&gt;
&lt;br /&gt;
9. Create a new C++ file by navigating to File &amp;amp;rarr; New &amp;amp;rarr; Files &amp;amp;rarr; C++ Source File and enter a descriptive name such as HelloWorld.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 New File.PNG|link=|alt=New File]]&lt;br /&gt;
&lt;br /&gt;
10. An empty C++ file will pop up. Please copy and paste the contents of the {{Code|HelloWorld.c}} program here.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
11. Now, you can run the example. Click on Build &amp;amp;rarr; Execute.&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
12. This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:VS6 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. Please see the [[#Use Our Examples 3 | Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as shown in the [[#Use Our Examples 3 | Use Our Examples]] section. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
===Borland===&lt;br /&gt;
&lt;br /&gt;
====Use Our Examples====&lt;br /&gt;
&lt;br /&gt;
In addition to running one of the two [[#Libraries and Drivers:| Windows Installers]] above (which you probably already have if you worked through the &#039;&#039;Getting Started&#039;&#039; page for your device), you will need the [http://www.phidgets.com/downloads/libraries/phidget21bcc.zip Borland C++ Libraries]. {{Code|phidget21bcc.lib}} is typically placed in {{Code|C:\Program Files\Phidgets}}, but you are free to place it in any directory you wish.&lt;br /&gt;
&lt;br /&gt;
After installing the Phidget C/C++ library, you&#039;re ready to download the [http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz examples] and run the examples.&lt;br /&gt;
&lt;br /&gt;
Afterwards, unpack the examples. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example. Locate the {{Code|HelloWorld.c}} file and type the following to compile the file and link the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
To compile, link the Phidget C/C++ library and build a binary executable, enter the following in a command line prompt in the directory with {{Code|HelloWorld.c}}:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  bcc32 -eHelloWorld -I&amp;quot;C:\Program Files\Phidgets&amp;quot; -L&amp;quot;C:\Program Files\Phidgets&amp;quot; phidget21bcc.lib HelloWorld.c&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is assumed that {{Code|phidget21bcc.lib}} and {{Code|phidget21.h}} are placed in {{Code|C:\Program Files\Phidgets}}. If the files are placed in another location, please adjust the paths to both of the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
In this case, {{Code|HelloWorld.c}} would be the &#039;&#039;&#039;.c&#039;&#039;&#039; file specific to your device.  After using {{Code|bcc32}}, you will have an executable named {{Code|HelloWorld}} that you can run.  &lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:Borland HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
====Write Your Own Code====&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C/C++ code with Borland. In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as the examples [[#Use Our Examples 4 |above]]. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
===GCC on Windows===&lt;br /&gt;
&lt;br /&gt;
====Cygwin/MinGW====&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Download the [http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz examples] and unpack them into a folder. Afterwards, unpack the examples. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example. Locate the {{Code|HelloWorld.c}} file and type the following to compile the file and link the Phidget C/C++ library in a command line prompt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Cygwin&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  gcc example.c -o HelloWorld -I&amp;quot;/cygdrive/c/Program Files/Phidgets&amp;quot; -L&amp;quot;/cygdrive/c/Program Files/Phidgets&amp;quot; -lphidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;MinGW&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  gcc example.c -o HelloWorld -I&amp;quot;C:\Program Files\Phidgets&amp;quot; -L&amp;quot;C:\Program Files\Phidgets&amp;quot; -lphidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After using gcc, you will have an executable named {{Code|HelloWorld}} that you can run.  &lt;br /&gt;
It is assumed that {{Code|phidget21.h}} and {{Code|phidget21.lib}} are placed in {{Code|C:\Program Files\Phidgets}}. If the files are placed in another location, please adjust the paths to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
After using {{Code|gcc}}, you will have an executable named {{Code|HelloWorld}} that you can run.  &lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:C MinGW HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C/C++ code with Cygwin/MinGW in your favourite text editor. In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as shown in the [[#Use Our Examples 5| Use Our Examples]] section above. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
===Dev C++===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz examples] and unpack them into a folder. Here, you can find example programs for all the devices. {{FindYourDevice}}  You will need this example source code to be copied into your Dev C++ project later on. The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
2. In order to control Phidgets with Dev C++, we will use the {{Code|reimp}} tool to convert the {{Code|phidget21.lib}} to a format that Dev C++ accepts. Download the [http://www.phidgets.com reimp tool].&lt;br /&gt;
&lt;br /&gt;
3. Open up command line and traverse to the directory containing the reimp tool. Type the following command to create {{Code|libphidget21.a}}.&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  reimp.exe &amp;quot;C:\Program Files\Phidgets\phidget21.lib&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
The command above assumes that the {{Code|phidget21.lib}} is in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly. Please note that the 64 bit version of {{Code|phidget21.lib}} is not supported on Dev C/C++. Please use the 32 bit version of {{Code|phidget21.lib}}.&lt;br /&gt;
&lt;br /&gt;
4. Place {{Code|libphidget21.a}} in {{Code|&amp;lt;Dev-Cpp Install Directory&amp;gt;/lib}}.&lt;br /&gt;
&lt;br /&gt;
5. Next, a new project will need to be created. Generate a new console application with a descriptive name such as PhidgetTest. Please select C as the project type.&lt;br /&gt;
&lt;br /&gt;
[[File:DevC New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
6. Next, the project settings needs to be set up. Navigate to Project Options &amp;amp;rarr; Directories &amp;amp;rarr; Include Directories.&lt;br /&gt;
&lt;br /&gt;
7. Add a new path to {{Code|C:\Program Files\Phidgets}}. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:DevC Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
8. Navigate to Project Options &amp;amp;rarr; Parameters &amp;amp;rarr; Linker.&lt;br /&gt;
&lt;br /&gt;
9. Add {{Code|-lphidget21}} to the field. This step will find the {{Code|libphidget21.a}} file in {{Code|&amp;lt;Dev-Cpp Install Directory&amp;gt;/lib}}. &lt;br /&gt;
&lt;br /&gt;
[[File:DevC Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
10. To import the {{Code|HelloWorld}} program into your project, please open up {{Code|main.c}} in the editor.&lt;br /&gt;
&lt;br /&gt;
11. An empty C file will pop up. Please copy and paste the contents of the example program. &lt;br /&gt;
&lt;br /&gt;
[[File:DevC Source.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
12. Now, you can run the example. Click on Execute &amp;amp;rarr; Compile &amp;amp; Run.&lt;br /&gt;
&lt;br /&gt;
[[File:DevC Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
13. This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:DevC HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Once you have the C/C++ examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. Please see the [[#Use Our Examples 6 | Use Our Examples]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as the [[#Use Our Examples 6 | examples]] above. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
C/C++ has excellent support on OS X through the gcc compiler.  &lt;br /&gt;
&lt;br /&gt;
The first step in using C/C++ on Mac is to install the Phidget C/C++ library.  Compile and install them as explained on the Getting Started guide for your device, which you can find on its product page on [http://www.phidgets.com our main website].  Then, the [[OS - OS X]] page also describes the different Phidget files, their installed locations, and their roles. &lt;br /&gt;
&lt;br /&gt;
{{ContentNeeded|The information we say that we say on the OS - OS X page (i.e. the different files, locations, and roles) should actually be added there}}&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
After installing the main Phidget library for OS X as above, you&#039;re ready to download the [http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz examples]. Afterwards, unzip the file. To run the example code, you&#039;ll need to find the source code &#039;&#039;for your specific device&#039;&#039;.  Then, compile the code under your platform and run it.&lt;br /&gt;
&lt;br /&gt;
To compile, link the Phidget C/C++ library, and build an executable binary on OS X, do (for example, depending on the Headers location):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  gcc example.c -o example -framework Phidget21 -I/Library/Frameworks/Phidget21.framework/Headers&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After using gcc, you will have an executable named {{Code|example}} that you can run.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as shown in the [[#Use Our Examples 7|Use Our Example]] section above.&lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples.  Even more help and references are provided from there.&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
C/C++ has support on Linux through the gcc compiler.  &lt;br /&gt;
&lt;br /&gt;
The first step in using C/C++ on Linux is to install the Phidget libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
&lt;br /&gt;
After installing the Phidget libraries for Linux as above, you&#039;re ready to download and run the examples:&lt;br /&gt;
*[http://www.phidgets.com/downloads/examples/phidget21-c-examples.tar.gz Generic C/C++ Examples]&lt;br /&gt;
&lt;br /&gt;
To run the example code, you&#039;ll need to download and unpack the examples, and then find the source code for your device.  {{FindYourDevice}}  You can also use the HelloWorld program, which a basic program that can run with any Phidget.  Then, compile the code under your platform and run it.  When compiling, you need to link to the Phidget library.&lt;br /&gt;
&lt;br /&gt;
To compile, link the Phidget libraries and build a binary executable on Linux, do the following in a terminal in the directory with {{Code|example.c}}:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  gcc example.c -o example -lphidget21&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case, {{Code|example.c}} would be the &#039;&#039;&#039;.c&#039;&#039;&#039; file specific to your device.  After using gcc, you will have an executable named {{Code|example}} that you can run.  &lt;br /&gt;
&lt;br /&gt;
On Linux, if you have not set up [[OS_-_Linux#Setting_udev_Rules | your udev rules for USB access]], you will need to run the program &#039;&#039;&#039;as root&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
  sudo ./example&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C/C++ code on Linux, such as within a text editor like Emacs, Vi, Gedit, or Kate.  In your &#039;&#039;&#039;{{Code|.c}}&#039;&#039;&#039; source code file, you must include a reference to the library header:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C/C++ code the same way as the examples above. &lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching]] section to help you follow the provided C/C++ examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==Windows CE==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C/C++ programs on Windows CE depend on the following files, which the Windows CE installer puts onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  It is placed in {{Code|\Windows}}.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|PhidgetWebService21.exe}}&amp;lt;/b&amp;gt; is used to control Phidgets remotely across a network using the [[#WebService | PhidgetWebService]]. It can be placed anywhere on the system.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.lib}}&amp;lt;/b&amp;gt; is used by your compiler to link to the dll.  Your compiler has to know where this file is.&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.h}}&amp;lt;/b&amp;gt; lists all the Phidget API function calls available to your code.  Your compiler also has to know where this file is. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget.dll}}&amp;lt;/b&amp;gt; is the Phidgets kernel driver. It is placed in {{Code|\Windows}}.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2005/2008/2010===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Currently, we have no example code for C/C++ on Windows CE. However, set up is very much the same as what it would be with [[#Visual Studio 2005/2008/2010 |Visual Studio 2005/2008/2010]] in Windows. The {{Code|phidget21.h}} and {{Code|phidget21.lib}} can be downloaded [http://www.phidgets.com/downloads/libraries/Phidget21-wincedevel.zip here].&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget C/C++ library. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C++: Win32 Smart Device project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 1.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Select {{Code|Next}}.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 2.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Select the SDK(s) that you want to code against and elect {{Code|Next}}.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 3.PNG|link=|alt=SDKs]]&lt;br /&gt;
&lt;br /&gt;
4. Create a console application and select {{Code|Next}}.&lt;br /&gt;
&lt;br /&gt;
[[File:WinCE VS C NewProject 4.PNG|link=|alt=Create Console Application]]&lt;br /&gt;
&lt;br /&gt;
3. Open the project properties window.&lt;br /&gt;
&lt;br /&gt;
4. Navigate to Configuration Properties &amp;amp;rarr; C/C++.&lt;br /&gt;
&lt;br /&gt;
5. Add {{Code|&amp;quot;C:\Program Files\Phidgets&amp;quot;}} to the additional directories field. This step will find the {{Code|phidget21.h}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Header.PNG|link=|alt=Header File]]&lt;br /&gt;
&lt;br /&gt;
6. Navigate to Configuration Properties &amp;amp;rarr; Linker &amp;amp;rarr; Input.&lt;br /&gt;
&lt;br /&gt;
7. Edit the additional dependencies and add {{Code|&amp;quot;C:\Program  Files\Phidgets\phidget21.lib&amp;quot;}}. This step will find the {{Code|phidget21.lib}} file in the corresponding directory. If the file is placed in another location, please adjust the path  to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Library.PNG|link=|alt=Library File]]&lt;br /&gt;
&lt;br /&gt;
8. The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget C/C++ library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;phidget21.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  &lt;br /&gt;
&lt;br /&gt;
Your main reference for writing C code will be our C/C++ API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in C/C++|[http://www.phidgets.com/documentation/Phidget21_C_Doc.zip C/C++ API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In C/C++, you can name these &#039;&#039;&#039;event&#039;&#039;&#039; functions whatever you like.  You will then pass them as function pointers to the Phidget library below in the Main Code section.  This hooks them into the actual events when they occur. &amp;lt;br&amp;gt; &lt;br /&gt;
In the example code, the event functions common to all Phidgets are called things like &#039;&#039;&#039;AttachHandler()&#039;&#039;&#039; and &#039;&#039;&#039;DetachHandler()&#039;&#039;&#039;, etc.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Some event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.&lt;br /&gt;
Other functions are given in the examples to show you more detail on using your Phidget.  For example, &#039;&#039;&#039;DeviceInitialize()&#039;&#039;&#039; will show what needs to be set up for your Phidget before using it.&lt;br /&gt;
|Creating a Phidget software object in C is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating an object with the {{Code|CPhidgetSpatialHandle}} type, and then initializing it using the {{Code|CPhidgetSpatial_create function}}.  The examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Other C calls follow a similar syntax - {{Code|CPhidgetXXX_function}}, where XXX is the name of your device, and function is an action available from the API for your specific Phidget.|&lt;br /&gt;
[http://www.phidgets.com/documentation/Phidget21_C_Doc.zip C/C++ API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
When programming in C/C++, you&#039;re in luck.  All of our code snippet examples on our [[General Phidget Programming]] page are in both C++ and Java.  Therefore, we do not include any here, because that page is much more in-depth, and you won&#039;t have to have two pages open at once.  So head over there, and start writing code!&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
===Issue: I am using a non US-English version of Windows, and the Visual C/C++ examples run into a linker error===&lt;br /&gt;
Affected Operating Systems: &#039;&#039;&#039;Windows&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The example projects, by default finds the {{Code|phidget21.h}} and {{Code|phidget21.lib}} in ${SystemDrive}\Program Files\Phidgets. If you are using a non US-English version of Windows, the Phidget drivers may be installed into a different location. To resolve, you will have to modify the paths to these two files. For instructions, please see your environment/compiler section.&lt;/div&gt;</summary>
		<author><name>192.168.3.183</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_C_Sharp&amp;diff=19773</id>
		<title>Language - C Sharp</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_C_Sharp&amp;diff=19773"/>
		<updated>2012-05-16T18:50:37Z</updated>

		<summary type="html">&lt;p&gt;192.168.3.183: /* OS X */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-CSharp.png|64x64px|link=|alt=]]|C# is a modern, object-oriented programming language developed by [http://www.microsoft.com Microsoft].}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|C#|the complete Phidget API, including events|all Phidget devices.|the .NET or Mono framework. Both of the frameworks are supported on Windows. For Linux and OS X, only the Mono framework can be used. We provide instructions on how to set up your environment/compilers for [[#Visual Studio 2005/2008/2010 | Visual Studio 2005/2008/2010]], [[#Visual Studio 2003 | Visual Studio 2003]], [[#MonoDevelop | MonoDevelop]] and the [[#Mono | Mono command line compilers]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
{{QuickDownloads|C#|&lt;br /&gt;
{{APIQuickDownloads|http://www.phidgets.com/documentation/Phidget21.NET.zip .NET}}|&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/CSharp.zip|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|http://www.phidgets.com/downloads/libraries/phidget21-x86.zip|.NET Framework Files|}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with C#==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C# programs on Windows depend on the following files, which the installers above put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
You will also need one of the following two files, depending on the .NET framework version you are targeting:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;2.0&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET1.1.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.1&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt;. Your compiler has to know where this file is. By default, is is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
You can optionally install the following files:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.XML}}&amp;lt;/b&amp;gt; provides the IntelliSense in-line documentation for the .NET library in Visual Studio/MonoDevelop. This documentation is also visible in the Object Browser in Visual Studio. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Policy.2.1.Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the policy assembly for {{Code|Phidget21.NET.dll}}. Our installer places this file in the Global Assembly Cache(GAC) directory. It directs any programs compiled against version 2.1.0 or higher of {{Code|Phidget21.NET.dll}} to use the most recent installed version. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the five [http://www.phidgets.com/downloads/libraries/Phidget21-windevel.zip files].&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each compiler below.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2005/2008/2010===&lt;br /&gt;
&lt;br /&gt;
Microsoft makes free versions of Visual Studio available known as Express Editions.  The Express editions are suitable for most applications, but are limited in features for more complex applications. Please see [http://www.microsoft.com/visualstudio Microsoft Visual Studio] for more information.&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Please start by downloading the [http://www.phidgets.com/downloads/examples/CSharp.zip examples] and unpack them into a folder.  While these examples were written in Visual Studio 2005 and 2008, Visual Studio 2010 will easily open and upgrade them. To load all projects in Visual Studio, go to File &amp;amp;rarr; Open &amp;amp;rarr; Project, and open {{Code|AllExamples/AllExamples.sln}} or {{Code|AllExamples/AllExamples_vs2008.sln}} for Visual Studio 2005 and 2008, respectively.&lt;br /&gt;
&lt;br /&gt;
If you are opening the Phidget examples in Visual Studio 2010, you will need to go through the Visual Studio Conversion Wizard to convert the 2005 or 2008 project. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Conversion Wizard.PNG|link=|alt=Conversion Wizard]]&lt;br /&gt;
&lt;br /&gt;
The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
Start by setting the {{Code|HelloWorld}} project as your start up project.&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the example! Click on Debug &amp;amp;rarr; Start Debugging. Please note that the projects, by default try to find the {{Code|Phidget21.NET.dll}} in the {{Code|C:\Program Files\Phidgets}}. If you have it installed in another location, please change the path to the file&#039;s location accordingly. If you are receiving an error message regarding that the namespace Phidgets cannot be found, please re-add the reference to {{Code|Phidget21.NET.dll}}. Please see the [[#Write Your Own Code | Write Your Own Code ]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}} &lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your environment to properly link the Phidget C# libraries. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C# Windows Applications project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Add Reference.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Under the .NET tab, select {{Code|Phidget21.NET.dll}}.&lt;br /&gt;
If you used our installer, these files are installed in {{Code|C:\Program Files\Phidgets}}, by default. If it does not appear in this list, then you can browse to the Phidget Framework installation directory and add the file.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching ]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2003===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [http://www.phidgets.com/downloads/examples/CSharp.zip examples] and unpack them into a folder. Here, you can find the HelloWorld example which works with any Phidget.  You can also find example programs for all the devices. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
As the examples were written in newer versions of Visual Studio, Visual Studio 2003 is not able to open the examples. Fortunately, you can import the &#039;&#039;&#039;simple examples&#039;&#039;&#039; to a Visual Studio 2003 project. It will be difficult to import the full examples as you will need to recreate the GUI components. &lt;br /&gt;
&lt;br /&gt;
2. Next, a new project will need to be created. Generate a new Visual C# console application project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp_VS2003 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Add a reference to the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp_VS2003 Add Reference 1.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
4. Under the .NET tab, select {{Code|Phidget21.NET1.1.dll}}. If you used our installer, by default, this file is placed in {{Code|C:\Program Files\Phidgets}}. If it is in another location, please change the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp_VS2003 Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
5. To import the simple example program into your project, please: open up {{Code|Class1.cs}}.&lt;br /&gt;
&lt;br /&gt;
6. Traverse to the example in Windows Explorer and locate the {{Code|Program.cs}} file.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2003 Source Code.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
7. Copy and paste the contents from that file into {{Code|Class1.cs}}.&lt;br /&gt;
&lt;br /&gt;
8. Comment out the following line as it is not supported in .NET 1.1:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using System.Collections.Generic;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2003 Source Code 2.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
9. Now, you can run the example. Click on Debug &amp;amp;rarr; Start.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2003 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching ]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget .NET library. Please see the [[#Use Our Examples 2 | Use Our Examples ]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Mono===&lt;br /&gt;
&lt;br /&gt;
This section will provide instructions on how to compile using the {{Code|mcs}} compiler. Other compilers such as {{Code|gmcs}}, {{Code|smcs}}, and {{Code|dmcs}} all work in the same way.&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Download the [http://www.phidgets.com/downloads/examples/CSharp.zip examples] and unpack them into a folder. Here, you can find the HelloWorld program that will work with any Phidget.  You will also find example programs for all the devices. {{FindYourDevice}}. &lt;br /&gt;
&lt;br /&gt;
Please only use the simple examples. The full examples uses Windows Forms, which Mono and the Gtk# toolkit are not completely compatible with. Locate the {{Code|Program.cs}} file as this contains the example source code. Copy the file into your working directory, and rename it to {{Code|example.cs}}.&lt;br /&gt;
&lt;br /&gt;
Place the {{Code|Phidget21.NET.dll}} in the same directory as your source code.&lt;br /&gt;
&lt;br /&gt;
To compile and build an executable, run:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
mcs /out:example.exe /r:phidget21.NET.dll example.cs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have the {{Code|Phidget21.NET.dll}} installed in another location, please change the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
Afterwards, you will have an executable named {{Code|example.exe}} that you can run. Type the following to run the program:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
mono example.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget .NET library. Please see the [[#Use Our Examples 3 | Use Our Example ]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===MonoDevelop===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Download the [http://www.phidgets.com/downloads/examples/CSharp.zip examples] and unpack them into a folder. Here, you can find example programs for all the devices, as well as a HelloWorld program that will work with any Phidget. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
These examples were written in Visual Studio 2005 and 2008, but are also compatible with MonoDevelop.&lt;br /&gt;
&lt;br /&gt;
To load all projects in MonoDevelop, go to File &amp;amp;rarr; Open, and open {{Code|AllExamples/AllExamples.sln}}&lt;br /&gt;
&lt;br /&gt;
This will load all of the examples available for C#, and then you can set your main project to be the one that matches your device.   If you are running under the .NET framework, you can use either the full or simple examples. Otherwise, if you are running under the Mono framework, please only use the simple examples. The full examples uses Windows Forms, which is not completely compatible with Mono&#039;s Gtk#.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win Start Up.PNG|link=|alt=Start Up Project]]&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Right click the project, and click on {{Code|Run With}} and select the target framework. Please note that the projects, by default try to find the {{Code|Phidget21.NET.dll}} in the {{Code|C\Program Files\Phidgets}}. If you have it installed in another location, please change the path to the file&#039;s location accordingly. If you are receiving an error message regarding that the namespace Phidgets cannot be found, please re-add the reference to {{Code|Phidget21.NET.dll}}. Please see the [[#Write Your Own Code 4 | Write Your Own Code]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win Run As.PNG|link=|alt=Run As]]&lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your  development environment to properly link the Phidget .NET library. To begin:&lt;br /&gt;
&lt;br /&gt;
1. Create a new C# empty project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win Reference.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Select {{Code|Phidget21.NET.dll}}. If you used our installer, by default, this file is placed in {{Code|C:\Program Files\Phidgets}}. If it is in another location, please change the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
The first thing you are going to need to do is install [http://www.mono-project.com/Main_Page Mono] (Note that Mono is only available for Intel Macs and not PowerPC).  You will need both the SDK and the runtime.  &lt;br /&gt;
&lt;br /&gt;
Then, you will need the Phidget .NET libraries.  These are part of the Windows library zip file download:&lt;br /&gt;
&lt;br /&gt;
* [http://www.phidgets.com/downloads/libraries/Phidget21-windevel.zip Phidget Windows Library Zip File]&lt;br /&gt;
&lt;br /&gt;
Extract the library zip file.  Descriptions for the files are available on the [[OS - Windows]] page, but for now we only need the {{Code|Phidget21.NET.dll}} file to run the Phidget C# examples in Mono.  So remember where you unzipped these Windows libraries - you will need to copy the {{Code|Phidget21.NET.dll}} file into your example directory shortly.&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to download and extract the Phidget C# Examples (For Windows, not for .NET Compact):&lt;br /&gt;
&lt;br /&gt;
* [http://www.phidgets.com/downloads/examples/CSharp.zip C Sharp Examples for Windows]&lt;br /&gt;
&lt;br /&gt;
One more thing needs to be done before you can compile and run the examples.  You need to set up a special configuration file so that Mono knows where to find the phidget21.dll.  Since Mac does not use dll&#039;s you need to redirect it to the appropriate file.  Create a new file in the same directory as the example you wish to compile and name it &amp;lt;code&amp;gt;Phidget21.NET.dll.config&amp;lt;/code&amp;gt;.  Put the following into the file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=xml&amp;gt;&lt;br /&gt;
&amp;lt;configuration&amp;gt;&lt;br /&gt;
	&amp;lt;dllmap dll=&amp;quot;phidget21.dll&amp;quot; target=&amp;quot;/Library/Frameworks/Phidget21.framework/Versions/Current/Phidget21&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/configuration&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All that is left is to compile and run the code.  When compiling, you need to link to the Phidget library. As the Phidget21.NET file is an &amp;quot;additional assembly&amp;quot; in C#/Mono, you can link to the assembly using the {{Code|-r}} &amp;quot;reference&amp;quot; switch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
gmcs Program.cs -r:Phidget21.NET.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will compile a {{Code|*.exe}} file - in this case, {{Code|Program.exe}}.  This you can then run under Mono:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
mono Program.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you will be compiling with an IDE such as GTK# or MonoDevelop, we don&#039;t have explicit instructions by IDE for OS X.  However, you will probably find the [[#MonoDevelop | MonoDevelop]] section in the Windows portion above useful.&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
C# has support on Linux through the Mono framework.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
 &lt;br /&gt;
The first step in using C# with Phidgets on Linux is to make sure that you have all of Mono installed.  Although you probably have already done this if you&#039;re a C# programmer, you want to make sure you have all of the packages you&#039;ll need.  Try:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo apt-get mono-complete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to install the main Phidget Libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
Then, you will need the Phidget .NET libraries.  These are part of the Windows library zip file download:&lt;br /&gt;
&lt;br /&gt;
* [http://www.phidgets.com/downloads/libraries/Phidget21-windevel.zip Phidget Windows Library Zip File]&lt;br /&gt;
&lt;br /&gt;
Extract the library zip file.  Descriptions for the files are available on the [[OS - Windows]] page, but for now we only need the {{Code|Phidget21.NET.dll}} file to run the Phidget C# examples in Mono.  So remember where you unzipped these Windows libraries - you will need to copy the {{Code|Phidget21.NET.dll}} file into your example directory shortly.&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to download and extract the Phidget C# Examples (For Windows, not for .NET Compact):&lt;br /&gt;
&lt;br /&gt;
* [http://www.phidgets.com/downloads/examples/CSharp.zip C Sharp Examples for Windows]&lt;br /&gt;
&lt;br /&gt;
To check that your Linux, Phidget, and Mono setup is all working together, you&#039;ll want to run the C# examples.  Specifically, you&#039;ll want to run the &#039;&#039;simple&#039;&#039; C# examples. You can either use the HelloWorld program that will work with any Phidget, or you can find the source code for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Let&#039;s say you&#039;re running the Temperature Sensor example (for the 1048 or 1051).  The source code for the example is in the directory: &lt;br /&gt;
&lt;br /&gt;
:{{Code|TemperatureSensorExamples}} &amp;amp;rarr; {{Code|TemperatureSensor-simple}} &amp;amp;rarr; {{Code|TemperatureSensor-simple}} &amp;amp;rarr; {{Code|Program.cs}}&lt;br /&gt;
&lt;br /&gt;
Other examples will be in directories named appropriately for their software object name.  Once you have found the example you want to run, copy the {{Code|Phidget21.NET.dll}} file that you unzipped earlier into that example directory where the {{Code|Program.cs}} file is.  &lt;br /&gt;
&lt;br /&gt;
Then, compile the code.  When compiling, you need to link to the Phidget library. As the Phidget21.NET file is an &amp;quot;additional assembly&amp;quot; in C#/Mono, you can link to the assembly using the {{Code|-r}} &amp;quot;reference&amp;quot; switch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
gmcs Program.cs -r:Phidget21.NET.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will compile a {{Code|*.exe}} file - in this case, {{Code|Program.exe}}.  This you can then run under Mono:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo mono Program.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember that the {{Code|sudo}} is needed unless you have your [[OS - Linux#Setting udev Rules|udev rules set on your Linux system]].&lt;br /&gt;
&lt;br /&gt;
If you will be compiling with an IDE such as GTK# or MonoDevelop, we don&#039;t have explicit instructions by IDE for Linux.  However, you will probably find the [[#MonoDevelop | MonoDevelop]] section in the Windows portion above useful.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C# code on Linux, such as within a text editor like Emacs, Vi, Gedit, or Kate. In your .cs source code file, you must include a reference to the Phidget Library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using Phidgets; &lt;br /&gt;
using Phidgets.Events; &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C# code the same way as the examples above.&lt;br /&gt;
&lt;br /&gt;
Mono also has a few different IDEs which you can use to develop code, and these are especially useful if you are doing GUI development.  We provide instructions for MonoDevelop - one such IDE - being used [[#MonoDevelop|under Windows]].&lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching section]] to help you follow the provided C# examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==Windows CE==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C# programs on Windows depend on the following files, which the installers above put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
You will also need one of the following two files, depending on the .NET framework version you are targeting:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;2.0&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET1.1.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.1&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt;. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
You can optionally install the following files:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.XML}}&amp;lt;/b&amp;gt; provides the IntelliSense in-line documentation for the .NET library in Visual Studio/MonoDevelop. This documentation is also visible in the Object Browser in Visual Studio. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Policy.2.1.Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the policy assembly for {{Code|Phidget21.NET.dll}}. Our installer places this file in the Global Assembly Cache(GAC) directory. It directs any programs compiled against version 2.1.0 or higher of {{Code|Phidget21.NET.dll}} to use the most recent installed version. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the five [http://www.phidgets.com/downloads/libraries/Phidget21-windevel.zip files].&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each compiler below.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2005/2008/2010===&lt;br /&gt;
&lt;br /&gt;
Microsoft makes free versions of Visual Studio available known as Express Editions.  The Express editions are suitable for most applications, but are limited in features for more complex applications. Please see [http://www.microsoft.com/visualstudio Microsoft Visual Studio] for more information.&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Please start by downloading the [http://www.phidgets.com/downloads/examples/CSharp.zip examples] and unpack them into a folder.  While these examples were written in Visual Studio 2005 and 2008, Visual Studio 2010 will easily open and upgrade them. To load all projects in Visual Studio, go to File &amp;amp;rarr; Open &amp;amp;rarr; Project, and open {{Code|AllExamples/AllExamples.sln}} or {{Code|AllExamples/AllExamples_vs2008.sln}} for Visual Studio 2005 and 2008, respectively.&lt;br /&gt;
&lt;br /&gt;
If you are opening the Phidget examples in Visual Studio 2010, you will need to go through the Visual Studio Conversion Wizard to convert the 2005 or 2008 project. &lt;br /&gt;
[[File:VS2005 Conversion Wizard.PNG|link=|alt=Conversion Wizard]]&lt;br /&gt;
&lt;br /&gt;
The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
Start by setting the {{Code|HelloWorld}} project as your start up project.&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the example! Click on Debug &amp;amp;rarr; Start Debugging. Please note that the projects, by default try to find the {{Code|Phidget21.NET.dll}} in the {{Code|C:\Program Files\Phidgets}}. If you have it installed in another location, please change the path to the file&#039;s location accordingly. If you are receiving an error message regarding that the namespace Phidgets cannot be found, please re-add the reference to {{Code|Phidget21.NET.dll}}. Please see the [[#Write Your Own Code | Write Your Own Code ]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}  Please ensure that you have set your start up project to be the one that matches your device before compiling. &lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your environment to properly link the Phidget C# libraries. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C# Windows Applications project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Add Reference.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Under the .NET tab, select {{Code|Phidget21.NET.dll}}.&lt;br /&gt;
If you used our installer, these files are installed in {{Code|C:\Program Files\Phidgets}}, by default. If it does not appear in this list, then you can browse to the Phidget Framework installation directory and add the file.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching ]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  This teaching section has resources for you to learn from the examples and write your own.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing C# code will be our C# API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in C#|[http://www.phidgets.com/documentation/Phidget21.NET.zip .NET API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In C#, you can name these &#039;&#039;&#039;event&#039;&#039;&#039; functions whatever you like.  You will add them to the Phidget .NET library in the Main Code section.  This hooks them into the actual events when they occur. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
In the example code, the event functions common to all Phidgets are things like attach, detach, and error handling.&amp;lt;br&amp;gt;&lt;br /&gt;
Other event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.&lt;br /&gt;
|Creating a Phidget software object in C# is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating a {{Code|Spatial}} object.  The examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The object provides device specific methods and properties which are available from the API for your specific Phidget.|&lt;br /&gt;
[http://www.phidgets.com/documentation/Phidget21.NET.zip .NET API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
Specific calls in MATLAB will differ in syntax from those on the [[General Phidget Programming]] page, but the concepts stay the same.  &lt;br /&gt;
&lt;br /&gt;
It may help to have the [[General Phidget Programming]] page and this section open at the same time, because they parallel each other and you can refer to the C# syntax.  However, &#039;&#039;many&#039;&#039; additional concepts are covered on the General Phidget Programming page on a high level, such as using multiple Phidgets, handling errors, and different styles of programming.&lt;br /&gt;
&lt;br /&gt;
====Step One: Initialize and Open====&lt;br /&gt;
&lt;br /&gt;
The open() function opens the software object, but not hardware.  So, it is not a guarantee you can use the Phidget immediately.&lt;br /&gt;
&lt;br /&gt;
The different types of open can be used with parameters to try and get the first device it can find, open based on its serial number, or even open across the network. The API manual lists and [[General Phidget Programming]] discusses all of the available modes that open provides.&lt;br /&gt;
&lt;br /&gt;
For example, if we were using a Temperature Sensor board as our device, the general calls would look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using Phidgets;&lt;br /&gt;
using Phidgets.Events;&lt;br /&gt;
// using.....&lt;br /&gt;
&lt;br /&gt;
namespace Program {&lt;br /&gt;
    class Code {&lt;br /&gt;
        static void Main(string[] args) {&lt;br /&gt;
            try {&lt;br /&gt;
&lt;br /&gt;
                // Declare a TemperatureSensor object&lt;br /&gt;
                TemperatureSensor device = new TemperatureSensor(); &lt;br /&gt;
                &lt;br /&gt;
                // Hook in any event handlers&lt;br /&gt;
                // ...&lt;br /&gt;
&lt;br /&gt;
                // Open the device&lt;br /&gt;
                device.open();&lt;br /&gt;
&lt;br /&gt;
            } catch (PhidgetException ex) { Console.WriteLine(ex.Description); }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Two: Wait for Attachment (plugging in) of the Phidget====&lt;br /&gt;
&lt;br /&gt;
To use the Phidget, it must be plugged in (attached). We can handle this by using event driven programming and tracking the AttachEvents and DetachEvents, or we can handle this by calling waitForAttachment. This function works for any Phidget. WaitForAttachment will block indefinitely until a connection is made to the Phidget, or an optional timeout is exceeded:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  device.open();&lt;br /&gt;
  Console.WriteLine(&amp;quot;Waiting for TemperatureSensor to be attached....&amp;quot;);&lt;br /&gt;
  device.waitForAttachment();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One important thing to remember is that when working with Phidgets, a local connection will reserve the device until closed. This means only one program can access the Phidget locally. Many computers can access one Phidget over the [[Phidget WebService]].&lt;br /&gt;
&lt;br /&gt;
====Step Three: Do Things with the Phidget====&lt;br /&gt;
&lt;br /&gt;
We recommend the use of event driven programming when working with Phidgets. This allows the program to execute other tasks until the Phidget generates a new event.  You can hook a custom function into an event trigger like this, using the Interface Kit Phidget as an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
ifKit.SensorChange += new SensorChangeEventHandler(ifKit_SensorChange);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ifKit_SensorChange method is defined as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
void ifKit_SensorChange(object sender, SensorChangeEventArgs e) {&lt;br /&gt;
   textBox1.Text = &amp;quot;Index &amp;quot; + e.Index + &amp;quot; Value: &amp;quot; + e.Value;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some values can be directly read and set on the Phidget, and inside polling loops used as an alternative to event driven programming.  These functions can be used inside a polling loop as an alternative to event driven programming.  The line inside the loop would be something like this, after which you could do something with the value:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
int val = device.sensors[0].Value;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Four: Close and Delete====&lt;br /&gt;
&lt;br /&gt;
At the end of your program, unhook any events and call Application.DoEvents(). This will make sure there are no outstanding events being processed before calling close.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
private void Form1_FormClosing(object sender, FormClosingEventArgs e)  {&lt;br /&gt;
    ifKit.SensorChange -= new SensorChangeEventHandler(ifKit_SensorChange);&lt;br /&gt;
    //run any events in the message queue&lt;br /&gt;
    Application.DoEvents();&lt;br /&gt;
    ifKit.close();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{MoreHowTos}}&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;complete&#039;&#039; set of functions you have available for all Phidgets can be found in the [http://www.phidgets.com/documentation/Phidget21.NET.zip .NET API].  You can also find more description on any device-specific function in the Device API page for your specific Phidget, which can be found on its product page on our [http://www.phidgets.com main website].&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
==={{ProblemSolution|All Operating Systems|The Phidgets.Events.ErrorEventHandler conflicts with System.IO.ErrorEventHandler.}}===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using Phidgets;&lt;br /&gt;
using Phidgets.Events;&lt;br /&gt;
...&lt;br /&gt;
spatial.Error += new ErrorEventHandler(spatial_Error);&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
void spatial_Error(object sender, ErrorEventArgs e){&lt;br /&gt;
   ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code produces the following errors:&lt;br /&gt;
&lt;br /&gt;
{{Code|&#039;ErrorEventHandler&#039; is an ambiguous reference between &#039;System.IO.ErrorEventHandler&#039; and &#039;Phidgets.Events.ErrorEventHandler&#039;}}.&lt;br /&gt;
&lt;br /&gt;
and&lt;br /&gt;
&lt;br /&gt;
{{Code|&#039;ErrorEventArgs&#039; is an ambiguous reference between &#039;System.IO.ErrorEventArgs&#039; and &#039;Phidgets.Events.ErrorEventArgs&#039;}}.&lt;br /&gt;
&lt;br /&gt;
The error is due to the {{Code|System.IO}} and {{Code|Phidgets.Events}} namespaces both having a class called {{Code|ErrorEventHandler}}.&lt;br /&gt;
&lt;br /&gt;
To get around this issue, use the fully qualified namespace when referring to the {{Code|ErrorEventHandler}} and {{Code|ErrorEventArgs}} classes:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using Phidgets;&lt;br /&gt;
using Phidgets.Events;&lt;br /&gt;
...&lt;br /&gt;
spatial.Error += new Phidgets.Events.ErrorEventHandler(spatial_Error);&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
void spatial_Error(object sender, Phidgets.Events.ErrorEventArgs e){&lt;br /&gt;
   ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>192.168.3.183</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_C_Sharp&amp;diff=19772</id>
		<title>Language - C Sharp</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_C_Sharp&amp;diff=19772"/>
		<updated>2012-05-16T18:50:22Z</updated>

		<summary type="html">&lt;p&gt;192.168.3.183: /* OS X */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-CSharp.png|64x64px|link=|alt=]]|C# is a modern, object-oriented programming language developed by [http://www.microsoft.com Microsoft].}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|C#|the complete Phidget API, including events|all Phidget devices.|the .NET or Mono framework. Both of the frameworks are supported on Windows. For Linux and OS X, only the Mono framework can be used. We provide instructions on how to set up your environment/compilers for [[#Visual Studio 2005/2008/2010 | Visual Studio 2005/2008/2010]], [[#Visual Studio 2003 | Visual Studio 2003]], [[#MonoDevelop | MonoDevelop]] and the [[#Mono | Mono command line compilers]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
{{QuickDownloads|C#|&lt;br /&gt;
{{APIQuickDownloads|http://www.phidgets.com/documentation/Phidget21.NET.zip .NET}}|&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/CSharp.zip|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|http://www.phidgets.com/downloads/libraries/phidget21-x86.zip|.NET Framework Files|}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with C#==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C# programs on Windows depend on the following files, which the installers above put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
You will also need one of the following two files, depending on the .NET framework version you are targeting:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;2.0&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET1.1.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.1&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt;. Your compiler has to know where this file is. By default, is is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
You can optionally install the following files:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.XML}}&amp;lt;/b&amp;gt; provides the IntelliSense in-line documentation for the .NET library in Visual Studio/MonoDevelop. This documentation is also visible in the Object Browser in Visual Studio. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Policy.2.1.Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the policy assembly for {{Code|Phidget21.NET.dll}}. Our installer places this file in the Global Assembly Cache(GAC) directory. It directs any programs compiled against version 2.1.0 or higher of {{Code|Phidget21.NET.dll}} to use the most recent installed version. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the five [http://www.phidgets.com/downloads/libraries/Phidget21-windevel.zip files].&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each compiler below.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2005/2008/2010===&lt;br /&gt;
&lt;br /&gt;
Microsoft makes free versions of Visual Studio available known as Express Editions.  The Express editions are suitable for most applications, but are limited in features for more complex applications. Please see [http://www.microsoft.com/visualstudio Microsoft Visual Studio] for more information.&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Please start by downloading the [http://www.phidgets.com/downloads/examples/CSharp.zip examples] and unpack them into a folder.  While these examples were written in Visual Studio 2005 and 2008, Visual Studio 2010 will easily open and upgrade them. To load all projects in Visual Studio, go to File &amp;amp;rarr; Open &amp;amp;rarr; Project, and open {{Code|AllExamples/AllExamples.sln}} or {{Code|AllExamples/AllExamples_vs2008.sln}} for Visual Studio 2005 and 2008, respectively.&lt;br /&gt;
&lt;br /&gt;
If you are opening the Phidget examples in Visual Studio 2010, you will need to go through the Visual Studio Conversion Wizard to convert the 2005 or 2008 project. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Conversion Wizard.PNG|link=|alt=Conversion Wizard]]&lt;br /&gt;
&lt;br /&gt;
The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
Start by setting the {{Code|HelloWorld}} project as your start up project.&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the example! Click on Debug &amp;amp;rarr; Start Debugging. Please note that the projects, by default try to find the {{Code|Phidget21.NET.dll}} in the {{Code|C:\Program Files\Phidgets}}. If you have it installed in another location, please change the path to the file&#039;s location accordingly. If you are receiving an error message regarding that the namespace Phidgets cannot be found, please re-add the reference to {{Code|Phidget21.NET.dll}}. Please see the [[#Write Your Own Code | Write Your Own Code ]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}} &lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your environment to properly link the Phidget C# libraries. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C# Windows Applications project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Add Reference.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Under the .NET tab, select {{Code|Phidget21.NET.dll}}.&lt;br /&gt;
If you used our installer, these files are installed in {{Code|C:\Program Files\Phidgets}}, by default. If it does not appear in this list, then you can browse to the Phidget Framework installation directory and add the file.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching ]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2003===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [http://www.phidgets.com/downloads/examples/CSharp.zip examples] and unpack them into a folder. Here, you can find the HelloWorld example which works with any Phidget.  You can also find example programs for all the devices. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
As the examples were written in newer versions of Visual Studio, Visual Studio 2003 is not able to open the examples. Fortunately, you can import the &#039;&#039;&#039;simple examples&#039;&#039;&#039; to a Visual Studio 2003 project. It will be difficult to import the full examples as you will need to recreate the GUI components. &lt;br /&gt;
&lt;br /&gt;
2. Next, a new project will need to be created. Generate a new Visual C# console application project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp_VS2003 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Add a reference to the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp_VS2003 Add Reference 1.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
4. Under the .NET tab, select {{Code|Phidget21.NET1.1.dll}}. If you used our installer, by default, this file is placed in {{Code|C:\Program Files\Phidgets}}. If it is in another location, please change the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp_VS2003 Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
5. To import the simple example program into your project, please: open up {{Code|Class1.cs}}.&lt;br /&gt;
&lt;br /&gt;
6. Traverse to the example in Windows Explorer and locate the {{Code|Program.cs}} file.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2003 Source Code.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
7. Copy and paste the contents from that file into {{Code|Class1.cs}}.&lt;br /&gt;
&lt;br /&gt;
8. Comment out the following line as it is not supported in .NET 1.1:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using System.Collections.Generic;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2003 Source Code 2.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
9. Now, you can run the example. Click on Debug &amp;amp;rarr; Start.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2003 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching ]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget .NET library. Please see the [[#Use Our Examples 2 | Use Our Examples ]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Mono===&lt;br /&gt;
&lt;br /&gt;
This section will provide instructions on how to compile using the {{Code|mcs}} compiler. Other compilers such as {{Code|gmcs}}, {{Code|smcs}}, and {{Code|dmcs}} all work in the same way.&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Download the [http://www.phidgets.com/downloads/examples/CSharp.zip examples] and unpack them into a folder. Here, you can find the HelloWorld program that will work with any Phidget.  You will also find example programs for all the devices. {{FindYourDevice}}. &lt;br /&gt;
&lt;br /&gt;
Please only use the simple examples. The full examples uses Windows Forms, which Mono and the Gtk# toolkit are not completely compatible with. Locate the {{Code|Program.cs}} file as this contains the example source code. Copy the file into your working directory, and rename it to {{Code|example.cs}}.&lt;br /&gt;
&lt;br /&gt;
Place the {{Code|Phidget21.NET.dll}} in the same directory as your source code.&lt;br /&gt;
&lt;br /&gt;
To compile and build an executable, run:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
mcs /out:example.exe /r:phidget21.NET.dll example.cs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have the {{Code|Phidget21.NET.dll}} installed in another location, please change the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
Afterwards, you will have an executable named {{Code|example.exe}} that you can run. Type the following to run the program:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
mono example.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget .NET library. Please see the [[#Use Our Examples 3 | Use Our Example ]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===MonoDevelop===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Download the [http://www.phidgets.com/downloads/examples/CSharp.zip examples] and unpack them into a folder. Here, you can find example programs for all the devices, as well as a HelloWorld program that will work with any Phidget. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
These examples were written in Visual Studio 2005 and 2008, but are also compatible with MonoDevelop.&lt;br /&gt;
&lt;br /&gt;
To load all projects in MonoDevelop, go to File &amp;amp;rarr; Open, and open {{Code|AllExamples/AllExamples.sln}}&lt;br /&gt;
&lt;br /&gt;
This will load all of the examples available for C#, and then you can set your main project to be the one that matches your device.   If you are running under the .NET framework, you can use either the full or simple examples. Otherwise, if you are running under the Mono framework, please only use the simple examples. The full examples uses Windows Forms, which is not completely compatible with Mono&#039;s Gtk#.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win Start Up.PNG|link=|alt=Start Up Project]]&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Right click the project, and click on {{Code|Run With}} and select the target framework. Please note that the projects, by default try to find the {{Code|Phidget21.NET.dll}} in the {{Code|C\Program Files\Phidgets}}. If you have it installed in another location, please change the path to the file&#039;s location accordingly. If you are receiving an error message regarding that the namespace Phidgets cannot be found, please re-add the reference to {{Code|Phidget21.NET.dll}}. Please see the [[#Write Your Own Code 4 | Write Your Own Code]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win Run As.PNG|link=|alt=Run As]]&lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your  development environment to properly link the Phidget .NET library. To begin:&lt;br /&gt;
&lt;br /&gt;
1. Create a new C# empty project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win Reference.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Select {{Code|Phidget21.NET.dll}}. If you used our installer, by default, this file is placed in {{Code|C:\Program Files\Phidgets}}. If it is in another location, please change the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
The first thing you are going to need to do is install [http://www.mono-project.com/Main_Page Mono] (Note that Mono is only available for Intel Macs and not PowerPC).  You will need both the SDK and the runtime.  &lt;br /&gt;
&lt;br /&gt;
Then, you will need the Phidget .NET libraries.  These are part of the Windows library zip file download:&lt;br /&gt;
&lt;br /&gt;
* [http://www.phidgets.com/downloads/libraries/Phidget21-windevel.zip Phidget Windows Library Zip File]&lt;br /&gt;
&lt;br /&gt;
Extract the library zip file.  Descriptions for the files are available on the [[OS - Windows]] page, but for now we only need the {{Code|Phidget21.NET.dll}} file to run the Phidget C# examples in Mono.  So remember where you unzipped these Windows libraries - you will need to copy the {{Code|Phidget21.NET.dll}} file into your example directory shortly.&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to download and extract the Phidget C# Examples (For Windows, not for .NET Compact):&lt;br /&gt;
&lt;br /&gt;
* [http://www.phidgets.com/downloads/examples/CSharp.zip C Sharp Examples for Windows]&lt;br /&gt;
&lt;br /&gt;
One more thing needs to be done before you can compile and run the examples.  You need to set up a special configuration file so that Mono knows where to find the phidget21.dll.  Since Mac does not use dll&#039;s you need to redirect it to the appropriate file.  Create a new file in the same directory as the example you wish to compile and name it &amp;lt;code&amp;gt;Phidget21.NET.dll.config&amp;lt;/code&amp;gt;.  Put the following into the file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=xml&amp;gt;&lt;br /&gt;
&amp;lt;configuration&amp;gt;&lt;br /&gt;
	&amp;lt;dllmap dll=&amp;quot;phidget21.dll&amp;quot; target=&amp;quot;/Library/Frameworks/Phidget21.framework/Versions/Current/Phidget21&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/configuration&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All that is left is to compile and run the code.  When compiling, you need to link to the Phidget library. As the Phidget21.NET file is an &amp;quot;additional assembly&amp;quot; in C#/Mono, you can link to the assembly using the {{Code|-r}} &amp;quot;reference&amp;quot; switch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
gmcs Program.cs -r:Phidget21.NET.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will compile a {{Code|*.exe}} file - in this case, {{Code|Program.exe}}.  This you can then run under Mono:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo mono Program.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you will be compiling with an IDE such as GTK# or MonoDevelop, we don&#039;t have explicit instructions by IDE for OS X.  However, you will probably find the [[#MonoDevelop | MonoDevelop]] section in the Windows portion above useful.&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
C# has support on Linux through the Mono framework.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
 &lt;br /&gt;
The first step in using C# with Phidgets on Linux is to make sure that you have all of Mono installed.  Although you probably have already done this if you&#039;re a C# programmer, you want to make sure you have all of the packages you&#039;ll need.  Try:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo apt-get mono-complete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to install the main Phidget Libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
Then, you will need the Phidget .NET libraries.  These are part of the Windows library zip file download:&lt;br /&gt;
&lt;br /&gt;
* [http://www.phidgets.com/downloads/libraries/Phidget21-windevel.zip Phidget Windows Library Zip File]&lt;br /&gt;
&lt;br /&gt;
Extract the library zip file.  Descriptions for the files are available on the [[OS - Windows]] page, but for now we only need the {{Code|Phidget21.NET.dll}} file to run the Phidget C# examples in Mono.  So remember where you unzipped these Windows libraries - you will need to copy the {{Code|Phidget21.NET.dll}} file into your example directory shortly.&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to download and extract the Phidget C# Examples (For Windows, not for .NET Compact):&lt;br /&gt;
&lt;br /&gt;
* [http://www.phidgets.com/downloads/examples/CSharp.zip C Sharp Examples for Windows]&lt;br /&gt;
&lt;br /&gt;
To check that your Linux, Phidget, and Mono setup is all working together, you&#039;ll want to run the C# examples.  Specifically, you&#039;ll want to run the &#039;&#039;simple&#039;&#039; C# examples. You can either use the HelloWorld program that will work with any Phidget, or you can find the source code for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Let&#039;s say you&#039;re running the Temperature Sensor example (for the 1048 or 1051).  The source code for the example is in the directory: &lt;br /&gt;
&lt;br /&gt;
:{{Code|TemperatureSensorExamples}} &amp;amp;rarr; {{Code|TemperatureSensor-simple}} &amp;amp;rarr; {{Code|TemperatureSensor-simple}} &amp;amp;rarr; {{Code|Program.cs}}&lt;br /&gt;
&lt;br /&gt;
Other examples will be in directories named appropriately for their software object name.  Once you have found the example you want to run, copy the {{Code|Phidget21.NET.dll}} file that you unzipped earlier into that example directory where the {{Code|Program.cs}} file is.  &lt;br /&gt;
&lt;br /&gt;
Then, compile the code.  When compiling, you need to link to the Phidget library. As the Phidget21.NET file is an &amp;quot;additional assembly&amp;quot; in C#/Mono, you can link to the assembly using the {{Code|-r}} &amp;quot;reference&amp;quot; switch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
gmcs Program.cs -r:Phidget21.NET.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will compile a {{Code|*.exe}} file - in this case, {{Code|Program.exe}}.  This you can then run under Mono:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo mono Program.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember that the {{Code|sudo}} is needed unless you have your [[OS - Linux#Setting udev Rules|udev rules set on your Linux system]].&lt;br /&gt;
&lt;br /&gt;
If you will be compiling with an IDE such as GTK# or MonoDevelop, we don&#039;t have explicit instructions by IDE for Linux.  However, you will probably find the [[#MonoDevelop | MonoDevelop]] section in the Windows portion above useful.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C# code on Linux, such as within a text editor like Emacs, Vi, Gedit, or Kate. In your .cs source code file, you must include a reference to the Phidget Library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using Phidgets; &lt;br /&gt;
using Phidgets.Events; &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C# code the same way as the examples above.&lt;br /&gt;
&lt;br /&gt;
Mono also has a few different IDEs which you can use to develop code, and these are especially useful if you are doing GUI development.  We provide instructions for MonoDevelop - one such IDE - being used [[#MonoDevelop|under Windows]].&lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching section]] to help you follow the provided C# examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==Windows CE==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C# programs on Windows depend on the following files, which the installers above put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
You will also need one of the following two files, depending on the .NET framework version you are targeting:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;2.0&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET1.1.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.1&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt;. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
You can optionally install the following files:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.XML}}&amp;lt;/b&amp;gt; provides the IntelliSense in-line documentation for the .NET library in Visual Studio/MonoDevelop. This documentation is also visible in the Object Browser in Visual Studio. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Policy.2.1.Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the policy assembly for {{Code|Phidget21.NET.dll}}. Our installer places this file in the Global Assembly Cache(GAC) directory. It directs any programs compiled against version 2.1.0 or higher of {{Code|Phidget21.NET.dll}} to use the most recent installed version. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the five [http://www.phidgets.com/downloads/libraries/Phidget21-windevel.zip files].&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each compiler below.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2005/2008/2010===&lt;br /&gt;
&lt;br /&gt;
Microsoft makes free versions of Visual Studio available known as Express Editions.  The Express editions are suitable for most applications, but are limited in features for more complex applications. Please see [http://www.microsoft.com/visualstudio Microsoft Visual Studio] for more information.&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Please start by downloading the [http://www.phidgets.com/downloads/examples/CSharp.zip examples] and unpack them into a folder.  While these examples were written in Visual Studio 2005 and 2008, Visual Studio 2010 will easily open and upgrade them. To load all projects in Visual Studio, go to File &amp;amp;rarr; Open &amp;amp;rarr; Project, and open {{Code|AllExamples/AllExamples.sln}} or {{Code|AllExamples/AllExamples_vs2008.sln}} for Visual Studio 2005 and 2008, respectively.&lt;br /&gt;
&lt;br /&gt;
If you are opening the Phidget examples in Visual Studio 2010, you will need to go through the Visual Studio Conversion Wizard to convert the 2005 or 2008 project. &lt;br /&gt;
[[File:VS2005 Conversion Wizard.PNG|link=|alt=Conversion Wizard]]&lt;br /&gt;
&lt;br /&gt;
The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
Start by setting the {{Code|HelloWorld}} project as your start up project.&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the example! Click on Debug &amp;amp;rarr; Start Debugging. Please note that the projects, by default try to find the {{Code|Phidget21.NET.dll}} in the {{Code|C:\Program Files\Phidgets}}. If you have it installed in another location, please change the path to the file&#039;s location accordingly. If you are receiving an error message regarding that the namespace Phidgets cannot be found, please re-add the reference to {{Code|Phidget21.NET.dll}}. Please see the [[#Write Your Own Code | Write Your Own Code ]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}  Please ensure that you have set your start up project to be the one that matches your device before compiling. &lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your environment to properly link the Phidget C# libraries. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C# Windows Applications project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Add Reference.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Under the .NET tab, select {{Code|Phidget21.NET.dll}}.&lt;br /&gt;
If you used our installer, these files are installed in {{Code|C:\Program Files\Phidgets}}, by default. If it does not appear in this list, then you can browse to the Phidget Framework installation directory and add the file.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching ]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  This teaching section has resources for you to learn from the examples and write your own.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing C# code will be our C# API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in C#|[http://www.phidgets.com/documentation/Phidget21.NET.zip .NET API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In C#, you can name these &#039;&#039;&#039;event&#039;&#039;&#039; functions whatever you like.  You will add them to the Phidget .NET library in the Main Code section.  This hooks them into the actual events when they occur. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
In the example code, the event functions common to all Phidgets are things like attach, detach, and error handling.&amp;lt;br&amp;gt;&lt;br /&gt;
Other event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.&lt;br /&gt;
|Creating a Phidget software object in C# is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating a {{Code|Spatial}} object.  The examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The object provides device specific methods and properties which are available from the API for your specific Phidget.|&lt;br /&gt;
[http://www.phidgets.com/documentation/Phidget21.NET.zip .NET API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
Specific calls in MATLAB will differ in syntax from those on the [[General Phidget Programming]] page, but the concepts stay the same.  &lt;br /&gt;
&lt;br /&gt;
It may help to have the [[General Phidget Programming]] page and this section open at the same time, because they parallel each other and you can refer to the C# syntax.  However, &#039;&#039;many&#039;&#039; additional concepts are covered on the General Phidget Programming page on a high level, such as using multiple Phidgets, handling errors, and different styles of programming.&lt;br /&gt;
&lt;br /&gt;
====Step One: Initialize and Open====&lt;br /&gt;
&lt;br /&gt;
The open() function opens the software object, but not hardware.  So, it is not a guarantee you can use the Phidget immediately.&lt;br /&gt;
&lt;br /&gt;
The different types of open can be used with parameters to try and get the first device it can find, open based on its serial number, or even open across the network. The API manual lists and [[General Phidget Programming]] discusses all of the available modes that open provides.&lt;br /&gt;
&lt;br /&gt;
For example, if we were using a Temperature Sensor board as our device, the general calls would look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using Phidgets;&lt;br /&gt;
using Phidgets.Events;&lt;br /&gt;
// using.....&lt;br /&gt;
&lt;br /&gt;
namespace Program {&lt;br /&gt;
    class Code {&lt;br /&gt;
        static void Main(string[] args) {&lt;br /&gt;
            try {&lt;br /&gt;
&lt;br /&gt;
                // Declare a TemperatureSensor object&lt;br /&gt;
                TemperatureSensor device = new TemperatureSensor(); &lt;br /&gt;
                &lt;br /&gt;
                // Hook in any event handlers&lt;br /&gt;
                // ...&lt;br /&gt;
&lt;br /&gt;
                // Open the device&lt;br /&gt;
                device.open();&lt;br /&gt;
&lt;br /&gt;
            } catch (PhidgetException ex) { Console.WriteLine(ex.Description); }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Two: Wait for Attachment (plugging in) of the Phidget====&lt;br /&gt;
&lt;br /&gt;
To use the Phidget, it must be plugged in (attached). We can handle this by using event driven programming and tracking the AttachEvents and DetachEvents, or we can handle this by calling waitForAttachment. This function works for any Phidget. WaitForAttachment will block indefinitely until a connection is made to the Phidget, or an optional timeout is exceeded:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  device.open();&lt;br /&gt;
  Console.WriteLine(&amp;quot;Waiting for TemperatureSensor to be attached....&amp;quot;);&lt;br /&gt;
  device.waitForAttachment();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One important thing to remember is that when working with Phidgets, a local connection will reserve the device until closed. This means only one program can access the Phidget locally. Many computers can access one Phidget over the [[Phidget WebService]].&lt;br /&gt;
&lt;br /&gt;
====Step Three: Do Things with the Phidget====&lt;br /&gt;
&lt;br /&gt;
We recommend the use of event driven programming when working with Phidgets. This allows the program to execute other tasks until the Phidget generates a new event.  You can hook a custom function into an event trigger like this, using the Interface Kit Phidget as an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
ifKit.SensorChange += new SensorChangeEventHandler(ifKit_SensorChange);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ifKit_SensorChange method is defined as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
void ifKit_SensorChange(object sender, SensorChangeEventArgs e) {&lt;br /&gt;
   textBox1.Text = &amp;quot;Index &amp;quot; + e.Index + &amp;quot; Value: &amp;quot; + e.Value;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some values can be directly read and set on the Phidget, and inside polling loops used as an alternative to event driven programming.  These functions can be used inside a polling loop as an alternative to event driven programming.  The line inside the loop would be something like this, after which you could do something with the value:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
int val = device.sensors[0].Value;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Four: Close and Delete====&lt;br /&gt;
&lt;br /&gt;
At the end of your program, unhook any events and call Application.DoEvents(). This will make sure there are no outstanding events being processed before calling close.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
private void Form1_FormClosing(object sender, FormClosingEventArgs e)  {&lt;br /&gt;
    ifKit.SensorChange -= new SensorChangeEventHandler(ifKit_SensorChange);&lt;br /&gt;
    //run any events in the message queue&lt;br /&gt;
    Application.DoEvents();&lt;br /&gt;
    ifKit.close();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{MoreHowTos}}&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;complete&#039;&#039; set of functions you have available for all Phidgets can be found in the [http://www.phidgets.com/documentation/Phidget21.NET.zip .NET API].  You can also find more description on any device-specific function in the Device API page for your specific Phidget, which can be found on its product page on our [http://www.phidgets.com main website].&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
==={{ProblemSolution|All Operating Systems|The Phidgets.Events.ErrorEventHandler conflicts with System.IO.ErrorEventHandler.}}===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using Phidgets;&lt;br /&gt;
using Phidgets.Events;&lt;br /&gt;
...&lt;br /&gt;
spatial.Error += new ErrorEventHandler(spatial_Error);&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
void spatial_Error(object sender, ErrorEventArgs e){&lt;br /&gt;
   ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code produces the following errors:&lt;br /&gt;
&lt;br /&gt;
{{Code|&#039;ErrorEventHandler&#039; is an ambiguous reference between &#039;System.IO.ErrorEventHandler&#039; and &#039;Phidgets.Events.ErrorEventHandler&#039;}}.&lt;br /&gt;
&lt;br /&gt;
and&lt;br /&gt;
&lt;br /&gt;
{{Code|&#039;ErrorEventArgs&#039; is an ambiguous reference between &#039;System.IO.ErrorEventArgs&#039; and &#039;Phidgets.Events.ErrorEventArgs&#039;}}.&lt;br /&gt;
&lt;br /&gt;
The error is due to the {{Code|System.IO}} and {{Code|Phidgets.Events}} namespaces both having a class called {{Code|ErrorEventHandler}}.&lt;br /&gt;
&lt;br /&gt;
To get around this issue, use the fully qualified namespace when referring to the {{Code|ErrorEventHandler}} and {{Code|ErrorEventArgs}} classes:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using Phidgets;&lt;br /&gt;
using Phidgets.Events;&lt;br /&gt;
...&lt;br /&gt;
spatial.Error += new Phidgets.Events.ErrorEventHandler(spatial_Error);&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
void spatial_Error(object sender, Phidgets.Events.ErrorEventArgs e){&lt;br /&gt;
   ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>192.168.3.183</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_C_Sharp&amp;diff=19771</id>
		<title>Language - C Sharp</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_C_Sharp&amp;diff=19771"/>
		<updated>2012-05-16T18:48:27Z</updated>

		<summary type="html">&lt;p&gt;192.168.3.183: /* OS X */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-CSharp.png|64x64px|link=|alt=]]|C# is a modern, object-oriented programming language developed by [http://www.microsoft.com Microsoft].}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|C#|the complete Phidget API, including events|all Phidget devices.|the .NET or Mono framework. Both of the frameworks are supported on Windows. For Linux and OS X, only the Mono framework can be used. We provide instructions on how to set up your environment/compilers for [[#Visual Studio 2005/2008/2010 | Visual Studio 2005/2008/2010]], [[#Visual Studio 2003 | Visual Studio 2003]], [[#MonoDevelop | MonoDevelop]] and the [[#Mono | Mono command line compilers]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
{{QuickDownloads|C#|&lt;br /&gt;
{{APIQuickDownloads|http://www.phidgets.com/documentation/Phidget21.NET.zip .NET}}|&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/CSharp.zip|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|http://www.phidgets.com/downloads/libraries/phidget21-x86.zip|.NET Framework Files|}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with C#==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C# programs on Windows depend on the following files, which the installers above put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
You will also need one of the following two files, depending on the .NET framework version you are targeting:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;2.0&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET1.1.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.1&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt;. Your compiler has to know where this file is. By default, is is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
You can optionally install the following files:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.XML}}&amp;lt;/b&amp;gt; provides the IntelliSense in-line documentation for the .NET library in Visual Studio/MonoDevelop. This documentation is also visible in the Object Browser in Visual Studio. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Policy.2.1.Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the policy assembly for {{Code|Phidget21.NET.dll}}. Our installer places this file in the Global Assembly Cache(GAC) directory. It directs any programs compiled against version 2.1.0 or higher of {{Code|Phidget21.NET.dll}} to use the most recent installed version. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the five [http://www.phidgets.com/downloads/libraries/Phidget21-windevel.zip files].&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each compiler below.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2005/2008/2010===&lt;br /&gt;
&lt;br /&gt;
Microsoft makes free versions of Visual Studio available known as Express Editions.  The Express editions are suitable for most applications, but are limited in features for more complex applications. Please see [http://www.microsoft.com/visualstudio Microsoft Visual Studio] for more information.&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Please start by downloading the [http://www.phidgets.com/downloads/examples/CSharp.zip examples] and unpack them into a folder.  While these examples were written in Visual Studio 2005 and 2008, Visual Studio 2010 will easily open and upgrade them. To load all projects in Visual Studio, go to File &amp;amp;rarr; Open &amp;amp;rarr; Project, and open {{Code|AllExamples/AllExamples.sln}} or {{Code|AllExamples/AllExamples_vs2008.sln}} for Visual Studio 2005 and 2008, respectively.&lt;br /&gt;
&lt;br /&gt;
If you are opening the Phidget examples in Visual Studio 2010, you will need to go through the Visual Studio Conversion Wizard to convert the 2005 or 2008 project. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Conversion Wizard.PNG|link=|alt=Conversion Wizard]]&lt;br /&gt;
&lt;br /&gt;
The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
Start by setting the {{Code|HelloWorld}} project as your start up project.&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the example! Click on Debug &amp;amp;rarr; Start Debugging. Please note that the projects, by default try to find the {{Code|Phidget21.NET.dll}} in the {{Code|C:\Program Files\Phidgets}}. If you have it installed in another location, please change the path to the file&#039;s location accordingly. If you are receiving an error message regarding that the namespace Phidgets cannot be found, please re-add the reference to {{Code|Phidget21.NET.dll}}. Please see the [[#Write Your Own Code | Write Your Own Code ]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}} &lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your environment to properly link the Phidget C# libraries. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C# Windows Applications project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Add Reference.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Under the .NET tab, select {{Code|Phidget21.NET.dll}}.&lt;br /&gt;
If you used our installer, these files are installed in {{Code|C:\Program Files\Phidgets}}, by default. If it does not appear in this list, then you can browse to the Phidget Framework installation directory and add the file.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching ]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2003===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [http://www.phidgets.com/downloads/examples/CSharp.zip examples] and unpack them into a folder. Here, you can find the HelloWorld example which works with any Phidget.  You can also find example programs for all the devices. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
As the examples were written in newer versions of Visual Studio, Visual Studio 2003 is not able to open the examples. Fortunately, you can import the &#039;&#039;&#039;simple examples&#039;&#039;&#039; to a Visual Studio 2003 project. It will be difficult to import the full examples as you will need to recreate the GUI components. &lt;br /&gt;
&lt;br /&gt;
2. Next, a new project will need to be created. Generate a new Visual C# console application project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp_VS2003 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Add a reference to the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp_VS2003 Add Reference 1.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
4. Under the .NET tab, select {{Code|Phidget21.NET1.1.dll}}. If you used our installer, by default, this file is placed in {{Code|C:\Program Files\Phidgets}}. If it is in another location, please change the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp_VS2003 Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
5. To import the simple example program into your project, please: open up {{Code|Class1.cs}}.&lt;br /&gt;
&lt;br /&gt;
6. Traverse to the example in Windows Explorer and locate the {{Code|Program.cs}} file.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2003 Source Code.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
7. Copy and paste the contents from that file into {{Code|Class1.cs}}.&lt;br /&gt;
&lt;br /&gt;
8. Comment out the following line as it is not supported in .NET 1.1:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using System.Collections.Generic;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2003 Source Code 2.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
9. Now, you can run the example. Click on Debug &amp;amp;rarr; Start.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2003 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching ]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget .NET library. Please see the [[#Use Our Examples 2 | Use Our Examples ]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Mono===&lt;br /&gt;
&lt;br /&gt;
This section will provide instructions on how to compile using the {{Code|mcs}} compiler. Other compilers such as {{Code|gmcs}}, {{Code|smcs}}, and {{Code|dmcs}} all work in the same way.&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Download the [http://www.phidgets.com/downloads/examples/CSharp.zip examples] and unpack them into a folder. Here, you can find the HelloWorld program that will work with any Phidget.  You will also find example programs for all the devices. {{FindYourDevice}}. &lt;br /&gt;
&lt;br /&gt;
Please only use the simple examples. The full examples uses Windows Forms, which Mono and the Gtk# toolkit are not completely compatible with. Locate the {{Code|Program.cs}} file as this contains the example source code. Copy the file into your working directory, and rename it to {{Code|example.cs}}.&lt;br /&gt;
&lt;br /&gt;
Place the {{Code|Phidget21.NET.dll}} in the same directory as your source code.&lt;br /&gt;
&lt;br /&gt;
To compile and build an executable, run:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
mcs /out:example.exe /r:phidget21.NET.dll example.cs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have the {{Code|Phidget21.NET.dll}} installed in another location, please change the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
Afterwards, you will have an executable named {{Code|example.exe}} that you can run. Type the following to run the program:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
mono example.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget .NET library. Please see the [[#Use Our Examples 3 | Use Our Example ]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===MonoDevelop===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Download the [http://www.phidgets.com/downloads/examples/CSharp.zip examples] and unpack them into a folder. Here, you can find example programs for all the devices, as well as a HelloWorld program that will work with any Phidget. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
These examples were written in Visual Studio 2005 and 2008, but are also compatible with MonoDevelop.&lt;br /&gt;
&lt;br /&gt;
To load all projects in MonoDevelop, go to File &amp;amp;rarr; Open, and open {{Code|AllExamples/AllExamples.sln}}&lt;br /&gt;
&lt;br /&gt;
This will load all of the examples available for C#, and then you can set your main project to be the one that matches your device.   If you are running under the .NET framework, you can use either the full or simple examples. Otherwise, if you are running under the Mono framework, please only use the simple examples. The full examples uses Windows Forms, which is not completely compatible with Mono&#039;s Gtk#.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win Start Up.PNG|link=|alt=Start Up Project]]&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Right click the project, and click on {{Code|Run With}} and select the target framework. Please note that the projects, by default try to find the {{Code|Phidget21.NET.dll}} in the {{Code|C\Program Files\Phidgets}}. If you have it installed in another location, please change the path to the file&#039;s location accordingly. If you are receiving an error message regarding that the namespace Phidgets cannot be found, please re-add the reference to {{Code|Phidget21.NET.dll}}. Please see the [[#Write Your Own Code 4 | Write Your Own Code]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win Run As.PNG|link=|alt=Run As]]&lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your  development environment to properly link the Phidget .NET library. To begin:&lt;br /&gt;
&lt;br /&gt;
1. Create a new C# empty project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win Reference.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Select {{Code|Phidget21.NET.dll}}. If you used our installer, by default, this file is placed in {{Code|C:\Program Files\Phidgets}}. If it is in another location, please change the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
The first thing you are going to need to do is install [http://www.mono-project.com/Main_Page Mono] (Note that Mono is only available for Intel Macs and not PowerPC).  You will need both the SDK and the runtime.  &lt;br /&gt;
&lt;br /&gt;
Then, you will need the Phidget .NET libraries.  These are part of the Windows library zip file download:&lt;br /&gt;
&lt;br /&gt;
* [http://www.phidgets.com/downloads/libraries/Phidget21-windevel.zip Phidget Windows Library Zip File]&lt;br /&gt;
&lt;br /&gt;
Extract the library zip file.  Descriptions for the files are available on the [[OS - Windows]] page, but for now we only need the {{Code|Phidget21.NET.dll}} file to run the Phidget C# examples in Mono.  So remember where you unzipped these Windows libraries - you will need to copy the {{Code|Phidget21.NET.dll}} file into your example directory shortly.&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to download and extract the Phidget C# Examples (For Windows, not for .NET Compact):&lt;br /&gt;
&lt;br /&gt;
* [http://www.phidgets.com/downloads/examples/CSharp.zip C Sharp Examples for Windows]&lt;br /&gt;
&lt;br /&gt;
One more thing needs to be done before you can compile and run the examples.  You need to set up a special configuration file so that Mono knows where to find the phidget21.dll.  Since Mac does not use dll&#039;s you need to redirect it to the appropriate file.  Create a new file in the same directory as the example you wish to compile and name it &amp;lt;code&amp;gt;Phidget21.NET.dll.config&amp;lt;/code&amp;gt;.  Put the following into the file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=xml&amp;gt;&lt;br /&gt;
&amp;lt;configuration&amp;gt;&lt;br /&gt;
	&amp;lt;dllmap dll=&amp;quot;phidget21.dll&amp;quot; target=&amp;quot;/Library/Frameworks/Phidget21.framework/Versions/Current/Phidget21&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/configuration&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
C# has support on Linux through the Mono framework.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
 &lt;br /&gt;
The first step in using C# with Phidgets on Linux is to make sure that you have all of Mono installed.  Although you probably have already done this if you&#039;re a C# programmer, you want to make sure you have all of the packages you&#039;ll need.  Try:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo apt-get mono-complete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to install the main Phidget Libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
Then, you will need the Phidget .NET libraries.  These are part of the Windows library zip file download:&lt;br /&gt;
&lt;br /&gt;
* [http://www.phidgets.com/downloads/libraries/Phidget21-windevel.zip Phidget Windows Library Zip File]&lt;br /&gt;
&lt;br /&gt;
Extract the library zip file.  Descriptions for the files are available on the [[OS - Windows]] page, but for now we only need the {{Code|Phidget21.NET.dll}} file to run the Phidget C# examples in Mono.  So remember where you unzipped these Windows libraries - you will need to copy the {{Code|Phidget21.NET.dll}} file into your example directory shortly.&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to download and extract the Phidget C# Examples (For Windows, not for .NET Compact):&lt;br /&gt;
&lt;br /&gt;
* [http://www.phidgets.com/downloads/examples/CSharp.zip C Sharp Examples for Windows]&lt;br /&gt;
&lt;br /&gt;
To check that your Linux, Phidget, and Mono setup is all working together, you&#039;ll want to run the C# examples.  Specifically, you&#039;ll want to run the &#039;&#039;simple&#039;&#039; C# examples. You can either use the HelloWorld program that will work with any Phidget, or you can find the source code for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Let&#039;s say you&#039;re running the Temperature Sensor example (for the 1048 or 1051).  The source code for the example is in the directory: &lt;br /&gt;
&lt;br /&gt;
:{{Code|TemperatureSensorExamples}} &amp;amp;rarr; {{Code|TemperatureSensor-simple}} &amp;amp;rarr; {{Code|TemperatureSensor-simple}} &amp;amp;rarr; {{Code|Program.cs}}&lt;br /&gt;
&lt;br /&gt;
Other examples will be in directories named appropriately for their software object name.  Once you have found the example you want to run, copy the {{Code|Phidget21.NET.dll}} file that you unzipped earlier into that example directory where the {{Code|Program.cs}} file is.  &lt;br /&gt;
&lt;br /&gt;
Then, compile the code.  When compiling, you need to link to the Phidget library. As the Phidget21.NET file is an &amp;quot;additional assembly&amp;quot; in C#/Mono, you can link to the assembly using the {{Code|-r}} &amp;quot;reference&amp;quot; switch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
gmcs Program.cs -r:Phidget21.NET.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will compile a {{Code|*.exe}} file - in this case, {{Code|Program.exe}}.  This you can then run under Mono:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo mono Program.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember that the {{Code|sudo}} is needed unless you have your [[OS - Linux#Setting udev Rules|udev rules set on your Linux system]].&lt;br /&gt;
&lt;br /&gt;
If you will be compiling with an IDE such as GTK# or MonoDevelop, we don&#039;t have explicit instructions by IDE for Linux.  However, you will probably find the [[#MonoDevelop | MonoDevelop]] section in the Windows portion above useful.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C# code on Linux, such as within a text editor like Emacs, Vi, Gedit, or Kate. In your .cs source code file, you must include a reference to the Phidget Library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using Phidgets; &lt;br /&gt;
using Phidgets.Events; &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C# code the same way as the examples above.&lt;br /&gt;
&lt;br /&gt;
Mono also has a few different IDEs which you can use to develop code, and these are especially useful if you are doing GUI development.  We provide instructions for MonoDevelop - one such IDE - being used [[#MonoDevelop|under Windows]].&lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching section]] to help you follow the provided C# examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==Windows CE==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C# programs on Windows depend on the following files, which the installers above put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
You will also need one of the following two files, depending on the .NET framework version you are targeting:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;2.0&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET1.1.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.1&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt;. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
You can optionally install the following files:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.XML}}&amp;lt;/b&amp;gt; provides the IntelliSense in-line documentation for the .NET library in Visual Studio/MonoDevelop. This documentation is also visible in the Object Browser in Visual Studio. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Policy.2.1.Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the policy assembly for {{Code|Phidget21.NET.dll}}. Our installer places this file in the Global Assembly Cache(GAC) directory. It directs any programs compiled against version 2.1.0 or higher of {{Code|Phidget21.NET.dll}} to use the most recent installed version. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the five [http://www.phidgets.com/downloads/libraries/Phidget21-windevel.zip files].&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each compiler below.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2005/2008/2010===&lt;br /&gt;
&lt;br /&gt;
Microsoft makes free versions of Visual Studio available known as Express Editions.  The Express editions are suitable for most applications, but are limited in features for more complex applications. Please see [http://www.microsoft.com/visualstudio Microsoft Visual Studio] for more information.&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Please start by downloading the [http://www.phidgets.com/downloads/examples/CSharp.zip examples] and unpack them into a folder.  While these examples were written in Visual Studio 2005 and 2008, Visual Studio 2010 will easily open and upgrade them. To load all projects in Visual Studio, go to File &amp;amp;rarr; Open &amp;amp;rarr; Project, and open {{Code|AllExamples/AllExamples.sln}} or {{Code|AllExamples/AllExamples_vs2008.sln}} for Visual Studio 2005 and 2008, respectively.&lt;br /&gt;
&lt;br /&gt;
If you are opening the Phidget examples in Visual Studio 2010, you will need to go through the Visual Studio Conversion Wizard to convert the 2005 or 2008 project. &lt;br /&gt;
[[File:VS2005 Conversion Wizard.PNG|link=|alt=Conversion Wizard]]&lt;br /&gt;
&lt;br /&gt;
The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
Start by setting the {{Code|HelloWorld}} project as your start up project.&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the example! Click on Debug &amp;amp;rarr; Start Debugging. Please note that the projects, by default try to find the {{Code|Phidget21.NET.dll}} in the {{Code|C:\Program Files\Phidgets}}. If you have it installed in another location, please change the path to the file&#039;s location accordingly. If you are receiving an error message regarding that the namespace Phidgets cannot be found, please re-add the reference to {{Code|Phidget21.NET.dll}}. Please see the [[#Write Your Own Code | Write Your Own Code ]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}  Please ensure that you have set your start up project to be the one that matches your device before compiling. &lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your environment to properly link the Phidget C# libraries. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C# Windows Applications project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Add Reference.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Under the .NET tab, select {{Code|Phidget21.NET.dll}}.&lt;br /&gt;
If you used our installer, these files are installed in {{Code|C:\Program Files\Phidgets}}, by default. If it does not appear in this list, then you can browse to the Phidget Framework installation directory and add the file.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching ]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  This teaching section has resources for you to learn from the examples and write your own.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing C# code will be our C# API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in C#|[http://www.phidgets.com/documentation/Phidget21.NET.zip .NET API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In C#, you can name these &#039;&#039;&#039;event&#039;&#039;&#039; functions whatever you like.  You will add them to the Phidget .NET library in the Main Code section.  This hooks them into the actual events when they occur. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
In the example code, the event functions common to all Phidgets are things like attach, detach, and error handling.&amp;lt;br&amp;gt;&lt;br /&gt;
Other event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.&lt;br /&gt;
|Creating a Phidget software object in C# is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating a {{Code|Spatial}} object.  The examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The object provides device specific methods and properties which are available from the API for your specific Phidget.|&lt;br /&gt;
[http://www.phidgets.com/documentation/Phidget21.NET.zip .NET API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
Specific calls in MATLAB will differ in syntax from those on the [[General Phidget Programming]] page, but the concepts stay the same.  &lt;br /&gt;
&lt;br /&gt;
It may help to have the [[General Phidget Programming]] page and this section open at the same time, because they parallel each other and you can refer to the C# syntax.  However, &#039;&#039;many&#039;&#039; additional concepts are covered on the General Phidget Programming page on a high level, such as using multiple Phidgets, handling errors, and different styles of programming.&lt;br /&gt;
&lt;br /&gt;
====Step One: Initialize and Open====&lt;br /&gt;
&lt;br /&gt;
The open() function opens the software object, but not hardware.  So, it is not a guarantee you can use the Phidget immediately.&lt;br /&gt;
&lt;br /&gt;
The different types of open can be used with parameters to try and get the first device it can find, open based on its serial number, or even open across the network. The API manual lists and [[General Phidget Programming]] discusses all of the available modes that open provides.&lt;br /&gt;
&lt;br /&gt;
For example, if we were using a Temperature Sensor board as our device, the general calls would look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using Phidgets;&lt;br /&gt;
using Phidgets.Events;&lt;br /&gt;
// using.....&lt;br /&gt;
&lt;br /&gt;
namespace Program {&lt;br /&gt;
    class Code {&lt;br /&gt;
        static void Main(string[] args) {&lt;br /&gt;
            try {&lt;br /&gt;
&lt;br /&gt;
                // Declare a TemperatureSensor object&lt;br /&gt;
                TemperatureSensor device = new TemperatureSensor(); &lt;br /&gt;
                &lt;br /&gt;
                // Hook in any event handlers&lt;br /&gt;
                // ...&lt;br /&gt;
&lt;br /&gt;
                // Open the device&lt;br /&gt;
                device.open();&lt;br /&gt;
&lt;br /&gt;
            } catch (PhidgetException ex) { Console.WriteLine(ex.Description); }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Two: Wait for Attachment (plugging in) of the Phidget====&lt;br /&gt;
&lt;br /&gt;
To use the Phidget, it must be plugged in (attached). We can handle this by using event driven programming and tracking the AttachEvents and DetachEvents, or we can handle this by calling waitForAttachment. This function works for any Phidget. WaitForAttachment will block indefinitely until a connection is made to the Phidget, or an optional timeout is exceeded:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  device.open();&lt;br /&gt;
  Console.WriteLine(&amp;quot;Waiting for TemperatureSensor to be attached....&amp;quot;);&lt;br /&gt;
  device.waitForAttachment();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One important thing to remember is that when working with Phidgets, a local connection will reserve the device until closed. This means only one program can access the Phidget locally. Many computers can access one Phidget over the [[Phidget WebService]].&lt;br /&gt;
&lt;br /&gt;
====Step Three: Do Things with the Phidget====&lt;br /&gt;
&lt;br /&gt;
We recommend the use of event driven programming when working with Phidgets. This allows the program to execute other tasks until the Phidget generates a new event.  You can hook a custom function into an event trigger like this, using the Interface Kit Phidget as an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
ifKit.SensorChange += new SensorChangeEventHandler(ifKit_SensorChange);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ifKit_SensorChange method is defined as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
void ifKit_SensorChange(object sender, SensorChangeEventArgs e) {&lt;br /&gt;
   textBox1.Text = &amp;quot;Index &amp;quot; + e.Index + &amp;quot; Value: &amp;quot; + e.Value;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some values can be directly read and set on the Phidget, and inside polling loops used as an alternative to event driven programming.  These functions can be used inside a polling loop as an alternative to event driven programming.  The line inside the loop would be something like this, after which you could do something with the value:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
int val = device.sensors[0].Value;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Four: Close and Delete====&lt;br /&gt;
&lt;br /&gt;
At the end of your program, unhook any events and call Application.DoEvents(). This will make sure there are no outstanding events being processed before calling close.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
private void Form1_FormClosing(object sender, FormClosingEventArgs e)  {&lt;br /&gt;
    ifKit.SensorChange -= new SensorChangeEventHandler(ifKit_SensorChange);&lt;br /&gt;
    //run any events in the message queue&lt;br /&gt;
    Application.DoEvents();&lt;br /&gt;
    ifKit.close();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{MoreHowTos}}&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;complete&#039;&#039; set of functions you have available for all Phidgets can be found in the [http://www.phidgets.com/documentation/Phidget21.NET.zip .NET API].  You can also find more description on any device-specific function in the Device API page for your specific Phidget, which can be found on its product page on our [http://www.phidgets.com main website].&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
==={{ProblemSolution|All Operating Systems|The Phidgets.Events.ErrorEventHandler conflicts with System.IO.ErrorEventHandler.}}===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using Phidgets;&lt;br /&gt;
using Phidgets.Events;&lt;br /&gt;
...&lt;br /&gt;
spatial.Error += new ErrorEventHandler(spatial_Error);&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
void spatial_Error(object sender, ErrorEventArgs e){&lt;br /&gt;
   ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code produces the following errors:&lt;br /&gt;
&lt;br /&gt;
{{Code|&#039;ErrorEventHandler&#039; is an ambiguous reference between &#039;System.IO.ErrorEventHandler&#039; and &#039;Phidgets.Events.ErrorEventHandler&#039;}}.&lt;br /&gt;
&lt;br /&gt;
and&lt;br /&gt;
&lt;br /&gt;
{{Code|&#039;ErrorEventArgs&#039; is an ambiguous reference between &#039;System.IO.ErrorEventArgs&#039; and &#039;Phidgets.Events.ErrorEventArgs&#039;}}.&lt;br /&gt;
&lt;br /&gt;
The error is due to the {{Code|System.IO}} and {{Code|Phidgets.Events}} namespaces both having a class called {{Code|ErrorEventHandler}}.&lt;br /&gt;
&lt;br /&gt;
To get around this issue, use the fully qualified namespace when referring to the {{Code|ErrorEventHandler}} and {{Code|ErrorEventArgs}} classes:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using Phidgets;&lt;br /&gt;
using Phidgets.Events;&lt;br /&gt;
...&lt;br /&gt;
spatial.Error += new Phidgets.Events.ErrorEventHandler(spatial_Error);&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
void spatial_Error(object sender, Phidgets.Events.ErrorEventArgs e){&lt;br /&gt;
   ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>192.168.3.183</name></author>
	</entry>
	<entry>
		<id>https://www.phidgets.com/docs/index.php?title=Language_-_C_Sharp&amp;diff=19761</id>
		<title>Language - C Sharp</title>
		<link rel="alternate" type="text/html" href="https://www.phidgets.com/docs/index.php?title=Language_-_C_Sharp&amp;diff=19761"/>
		<updated>2012-05-16T18:23:35Z</updated>

		<summary type="html">&lt;p&gt;192.168.3.183: /* OS X */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Language]]&lt;br /&gt;
{{OSLang|[[File:icon-CSharp.png|64x64px|link=|alt=]]|C# is a modern, object-oriented programming language developed by [http://www.microsoft.com Microsoft].}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
{{LanguageSupport|C#|the complete Phidget API, including events|all Phidget devices.|the .NET or Mono framework. Both of the frameworks are supported on Windows. For Linux and OS X, only the Mono framework can be used. We provide instructions on how to set up your environment/compilers for [[#Visual Studio 2005/2008/2010 | Visual Studio 2005/2008/2010]], [[#Visual Studio 2003 | Visual Studio 2003]], [[#MonoDevelop | MonoDevelop]] and the [[#Mono | Mono command line compilers]]|}}&lt;br /&gt;
&lt;br /&gt;
==Quick Downloads==&lt;br /&gt;
{{QuickDownloads|C#|&lt;br /&gt;
{{APIQuickDownloads|http://www.phidgets.com/documentation/Phidget21.NET.zip .NET}}|&lt;br /&gt;
{{ExampleQuickDownloads|http://www.phidgets.com/downloads/examples/CSharp.zip|}}|&lt;br /&gt;
{{ExtraLibraryQuickDownloads|http://www.phidgets.com/downloads/libraries/phidget21-x86.zip|.NET Framework Files|}}&lt;br /&gt;
{{WindowsQuickDownloads}}&lt;br /&gt;
{{MacQuickDownloads}}&lt;br /&gt;
{{LinuxQuickDownloads}}}}&lt;br /&gt;
&lt;br /&gt;
==Getting started with C#==&lt;br /&gt;
&lt;br /&gt;
If you are new to writing code for Phidgets, we recommend starting by running, then modifying existing examples. This will allow you to:&lt;br /&gt;
{{ExampleCodeReasons}}&lt;br /&gt;
&lt;br /&gt;
Instructions are divided up by operating system. Choose:&lt;br /&gt;
*[[#Windows(2000/XP/Vista/7)|Windows 2000 / XP / Vista / 7]]&lt;br /&gt;
*[[#OS X |OS X]]&lt;br /&gt;
*[[#Linux | Linux]] (including PhidgetSBC)&lt;br /&gt;
&lt;br /&gt;
==Windows (2000/XP/Vista/7)==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C# programs on Windows depend on the following files, which the installers above put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
You will also need one of the following two files, depending on the .NET framework version you are targeting:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;2.0&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET1.1.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.1&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt;. Your compiler has to know where this file is. By default, is is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
You can optionally install the following files:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.XML}}&amp;lt;/b&amp;gt; provides the IntelliSense in-line documentation for the .NET library in Visual Studio/MonoDevelop. This documentation is also visible in the Object Browser in Visual Studio. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Policy.2.1.Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the policy assembly for {{Code|Phidget21.NET.dll}}. Our installer places this file in the Global Assembly Cache(GAC) directory. It directs any programs compiled against version 2.1.0 or higher of {{Code|Phidget21.NET.dll}} to use the most recent installed version. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the five [http://www.phidgets.com/downloads/libraries/Phidget21-windevel.zip files].&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each compiler below.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2005/2008/2010===&lt;br /&gt;
&lt;br /&gt;
Microsoft makes free versions of Visual Studio available known as Express Editions.  The Express editions are suitable for most applications, but are limited in features for more complex applications. Please see [http://www.microsoft.com/visualstudio Microsoft Visual Studio] for more information.&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Please start by downloading the [http://www.phidgets.com/downloads/examples/CSharp.zip examples] and unpack them into a folder.  While these examples were written in Visual Studio 2005 and 2008, Visual Studio 2010 will easily open and upgrade them. To load all projects in Visual Studio, go to File &amp;amp;rarr; Open &amp;amp;rarr; Project, and open {{Code|AllExamples/AllExamples.sln}} or {{Code|AllExamples/AllExamples_vs2008.sln}} for Visual Studio 2005 and 2008, respectively.&lt;br /&gt;
&lt;br /&gt;
If you are opening the Phidget examples in Visual Studio 2010, you will need to go through the Visual Studio Conversion Wizard to convert the 2005 or 2008 project. &lt;br /&gt;
&lt;br /&gt;
[[File:VS2005 Conversion Wizard.PNG|link=|alt=Conversion Wizard]]&lt;br /&gt;
&lt;br /&gt;
The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
Start by setting the {{Code|HelloWorld}} project as your start up project.&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the example! Click on Debug &amp;amp;rarr; Start Debugging. Please note that the projects, by default try to find the {{Code|Phidget21.NET.dll}} in the {{Code|C:\Program Files\Phidgets}}. If you have it installed in another location, please change the path to the file&#039;s location accordingly. If you are receiving an error message regarding that the namespace Phidgets cannot be found, please re-add the reference to {{Code|Phidget21.NET.dll}}. Please see the [[#Write Your Own Code | Write Your Own Code ]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}} &lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your environment to properly link the Phidget C# libraries. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C# Windows Applications project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Add Reference.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Under the .NET tab, select {{Code|Phidget21.NET.dll}}.&lt;br /&gt;
If you used our installer, these files are installed in {{Code|C:\Program Files\Phidgets}}, by default. If it does not appear in this list, then you can browse to the Phidget Framework installation directory and add the file.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching ]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2003===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
1. Download the [http://www.phidgets.com/downloads/examples/CSharp.zip examples] and unpack them into a folder. Here, you can find the HelloWorld example which works with any Phidget.  You can also find example programs for all the devices. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
As the examples were written in newer versions of Visual Studio, Visual Studio 2003 is not able to open the examples. Fortunately, you can import the &#039;&#039;&#039;simple examples&#039;&#039;&#039; to a Visual Studio 2003 project. It will be difficult to import the full examples as you will need to recreate the GUI components. &lt;br /&gt;
&lt;br /&gt;
2. Next, a new project will need to be created. Generate a new Visual C# console application project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp_VS2003 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
3. Add a reference to the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp_VS2003 Add Reference 1.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
4. Under the .NET tab, select {{Code|Phidget21.NET1.1.dll}}. If you used our installer, by default, this file is placed in {{Code|C:\Program Files\Phidgets}}. If it is in another location, please change the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp_VS2003 Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
5. To import the simple example program into your project, please: open up {{Code|Class1.cs}}.&lt;br /&gt;
&lt;br /&gt;
6. Traverse to the example in Windows Explorer and locate the {{Code|Program.cs}} file.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2003 Source Code.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
7. Copy and paste the contents from that file into {{Code|Class1.cs}}.&lt;br /&gt;
&lt;br /&gt;
8. Comment out the following line as it is not supported in .NET 1.1:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using System.Collections.Generic;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2003 Source Code 2.PNG|link=|alt=Source Code]]&lt;br /&gt;
&lt;br /&gt;
9. Now, you can run the example. Click on Debug &amp;amp;rarr; Start.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2003 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching ]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget .NET library. Please see the [[#Use Our Examples 2 | Use Our Examples ]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
Then, in your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===Mono===&lt;br /&gt;
&lt;br /&gt;
This section will provide instructions on how to compile using the {{Code|mcs}} compiler. Other compilers such as {{Code|gmcs}}, {{Code|smcs}}, and {{Code|dmcs}} all work in the same way.&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Download the [http://www.phidgets.com/downloads/examples/CSharp.zip examples] and unpack them into a folder. Here, you can find the HelloWorld program that will work with any Phidget.  You will also find example programs for all the devices. {{FindYourDevice}}. &lt;br /&gt;
&lt;br /&gt;
Please only use the simple examples. The full examples uses Windows Forms, which Mono and the Gtk# toolkit are not completely compatible with. Locate the {{Code|Program.cs}} file as this contains the example source code. Copy the file into your working directory, and rename it to {{Code|example.cs}}.&lt;br /&gt;
&lt;br /&gt;
Place the {{Code|Phidget21.NET.dll}} in the same directory as your source code.&lt;br /&gt;
&lt;br /&gt;
To compile and build an executable, run:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
mcs /out:example.exe /r:phidget21.NET.dll example.cs&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have the {{Code|Phidget21.NET.dll}} installed in another location, please change the path to the file&#039;s location accordingly.&lt;br /&gt;
&lt;br /&gt;
Afterwards, you will have an executable named {{Code|example.exe}} that you can run. Type the following to run the program:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
mono example.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your development environment to properly link the Phidget .NET library. Please see the [[#Use Our Examples 3 | Use Our Example ]] section for instructions.&lt;br /&gt;
&lt;br /&gt;
In your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
===MonoDevelop===&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Download the [http://www.phidgets.com/downloads/examples/CSharp.zip examples] and unpack them into a folder. Here, you can find example programs for all the devices, as well as a HelloWorld program that will work with any Phidget. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
These examples were written in Visual Studio 2005 and 2008, but are also compatible with MonoDevelop.&lt;br /&gt;
&lt;br /&gt;
To load all projects in MonoDevelop, go to File &amp;amp;rarr; Open, and open {{Code|AllExamples/AllExamples.sln}}&lt;br /&gt;
&lt;br /&gt;
This will load all of the examples available for C#, and then you can set your main project to be the one that matches your device.   If you are running under the .NET framework, you can use either the full or simple examples. Otherwise, if you are running under the Mono framework, please only use the simple examples. The full examples uses Windows Forms, which is not completely compatible with Mono&#039;s Gtk#.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win Start Up.PNG|link=|alt=Start Up Project]]&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the examples! Right click the project, and click on {{Code|Run With}} and select the target framework. Please note that the projects, by default try to find the {{Code|Phidget21.NET.dll}} in the {{Code|C\Program Files\Phidgets}}. If you have it installed in another location, please change the path to the file&#039;s location accordingly. If you are receiving an error message regarding that the namespace Phidgets cannot be found, please re-add the reference to {{Code|Phidget21.NET.dll}}. Please see the [[#Write Your Own Code 4 | Write Your Own Code]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win Run As.PNG|link=|alt=Run As]]&lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your  development environment to properly link the Phidget .NET library. To begin:&lt;br /&gt;
&lt;br /&gt;
1. Create a new C# empty project with a descriptive name such as PhidgetTest.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win Reference.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Select {{Code|Phidget21.NET.dll}}. If you used our installer, by default, this file is placed in {{Code|C:\Program Files\Phidgets}}. If it is in another location, please change the path to the file&#039;s location accordingly. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp MonoDevelop Win Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==OS X==&lt;br /&gt;
&lt;br /&gt;
The first thing you are going to need to do is install [http://www.mono-project.com/Main_Page Mono].  You will need both the SDK and the runtime.  &lt;br /&gt;
&lt;br /&gt;
The first step in using C# on Mac is to install the Phidget .NET libraries.  Compile and install them as explained on the [[OS - OS X]] page, which also describes the different Phidget files, their installed locations, and their roles....&lt;br /&gt;
&lt;br /&gt;
==Linux==&lt;br /&gt;
&lt;br /&gt;
C# has support on Linux through the Mono framework.&lt;br /&gt;
&lt;br /&gt;
===Use Our Examples===&lt;br /&gt;
 &lt;br /&gt;
The first step in using C# with Phidgets on Linux is to make sure that you have all of Mono installed.  Although you probably have already done this if you&#039;re a C# programmer, you want to make sure you have all of the packages you&#039;ll need.  Try:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo apt-get mono-complete&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to install the main Phidget Libraries.  Compile and install them as explained on the main [[OS - Linux | Linux page]].  That Linux page also describes the different Phidget files, their installed locations, and their roles.&lt;br /&gt;
&lt;br /&gt;
Then, you will need the Phidget .NET libraries.  These are part of the Windows library zip file download:&lt;br /&gt;
&lt;br /&gt;
* [http://www.phidgets.com/downloads/libraries/Phidget21-windevel.zip Phidget Windows Library Zip File]&lt;br /&gt;
&lt;br /&gt;
Extract the library zip file.  Descriptions for the files are available on the [[OS - Windows]] page, but for now we only need the {{Code|Phidget21.NET.dll}} file to run the Phidget C# examples in Mono.  So remember where you unzipped these Windows libraries - you will need to copy the {{Code|Phidget21.NET.dll}} file into your example directory shortly.&lt;br /&gt;
&lt;br /&gt;
Next, you&#039;ll want to download and extract the Phidget C# Examples (For Windows, not for .NET Compact):&lt;br /&gt;
&lt;br /&gt;
* [http://www.phidgets.com/downloads/examples/CSharp.zip C Sharp Examples for Windows]&lt;br /&gt;
&lt;br /&gt;
To check that your Linux, Phidget, and Mono setup is all working together, you&#039;ll want to run the C# examples.  Specifically, you&#039;ll want to run the &#039;&#039;simple&#039;&#039; C# examples. You can either use the HelloWorld program that will work with any Phidget, or you can find the source code for your device. {{FindYourDevice}}&lt;br /&gt;
&lt;br /&gt;
Let&#039;s say you&#039;re running the Temperature Sensor example (for the 1048 or 1051).  The source code for the example is in the directory: &lt;br /&gt;
&lt;br /&gt;
:{{Code|TemperatureSensorExamples}} &amp;amp;rarr; {{Code|TemperatureSensor-simple}} &amp;amp;rarr; {{Code|TemperatureSensor-simple}} &amp;amp;rarr; {{Code|Program.cs}}&lt;br /&gt;
&lt;br /&gt;
Other examples will be in directories named appropriately for their software object name.  Once you have found the example you want to run, copy the {{Code|Phidget21.NET.dll}} file that you unzipped earlier into that example directory where the {{Code|Program.cs}} file is.  &lt;br /&gt;
&lt;br /&gt;
Then, compile the code.  When compiling, you need to link to the Phidget library. As the Phidget21.NET file is an &amp;quot;additional assembly&amp;quot; in C#/Mono, you can link to the assembly using the {{Code|-r}} &amp;quot;reference&amp;quot; switch:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
gmcs Program.cs -r:Phidget21.NET.dll&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will compile a {{Code|*.exe}} file - in this case, {{Code|Program.exe}}.  This you can then run under Mono:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
sudo mono Program.exe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remember that the {{Code|sudo}} is needed unless you have your [[OS - Linux#Setting udev Rules|udev rules set on your Linux system]].&lt;br /&gt;
&lt;br /&gt;
If you will be compiling with an IDE such as GTK# or MonoDevelop, we don&#039;t have explicit instructions by IDE for Linux.  However, you will probably find the [[#MonoDevelop | MonoDevelop]] section in the Windows portion above useful.&lt;br /&gt;
&lt;br /&gt;
===Write Your Own Code===&lt;br /&gt;
&lt;br /&gt;
When writing your code from scratch, you start it as you would any C# code on Linux, such as within a text editor like Emacs, Vi, Gedit, or Kate. In your .cs source code file, you must include a reference to the Phidget Library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using Phidgets; &lt;br /&gt;
using Phidgets.Events; &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, you would compile your completed C# code the same way as the examples above.&lt;br /&gt;
&lt;br /&gt;
Mono also has a few different IDEs which you can use to develop code, and these are especially useful if you are doing GUI development.  We provide instructions for MonoDevelop - one such IDE - being used [[#MonoDevelop|under Windows]].&lt;br /&gt;
&lt;br /&gt;
To learn how to write your own code for your Phidget, and to learn more about our API, we have a [[#Follow the Examples|teaching section]] to help you follow the provided C# examples and which has resources such as the API reference.&lt;br /&gt;
&lt;br /&gt;
==Windows CE==&lt;br /&gt;
&lt;br /&gt;
===Description of Library Files===&lt;br /&gt;
C# programs on Windows depend on the following files, which the installers above put onto your system:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|phidget21.dll}}&amp;lt;/b&amp;gt; contains the actual Phidget library, which is used at run-time.  By default, it is placed in {{Code|C:\Windows\System32}}.&lt;br /&gt;
You will also need one of the following two files, depending on the .NET framework version you are targeting:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;2.0&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt; or higher. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET1.1.dll}}&amp;lt;/b&amp;gt; is the Phidget library for .NET framework &amp;lt;i&amp;gt;&amp;lt;b&amp;gt;1.1&amp;lt;/b&amp;gt;&amp;lt;/i&amp;gt;. Your compiler has to know where this file is. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. You can either point your compiler to that location, or copy and link to it in a directory for your project workspace. &lt;br /&gt;
You can optionally install the following files:&lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Phidget21.NET.XML}}&amp;lt;/b&amp;gt; provides the IntelliSense in-line documentation for the .NET library in Visual Studio/MonoDevelop. This documentation is also visible in the Object Browser in Visual Studio. By default, it is placed into {{Code|C:\Program Files\Phidgets}}. &lt;br /&gt;
* &amp;lt;b&amp;gt;{{Code|Policy.2.1.Phidget21.NET.dll}}&amp;lt;/b&amp;gt; is the policy assembly for {{Code|Phidget21.NET.dll}}. Our installer places this file in the Global Assembly Cache(GAC) directory. It directs any programs compiled against version 2.1.0 or higher of {{Code|Phidget21.NET.dll}} to use the most recent installed version. &lt;br /&gt;
&lt;br /&gt;
If you do not want to use our installer, you can download the five [http://www.phidgets.com/downloads/libraries/Phidget21-windevel.zip files].&lt;br /&gt;
&lt;br /&gt;
Running the examples and writing your own code can be fairly compiler-specific, so we include instructions for each compiler below.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio 2005/2008/2010===&lt;br /&gt;
&lt;br /&gt;
Microsoft makes free versions of Visual Studio available known as Express Editions.  The Express editions are suitable for most applications, but are limited in features for more complex applications. Please see [http://www.microsoft.com/visualstudio Microsoft Visual Studio] for more information.&lt;br /&gt;
&lt;br /&gt;
=====Use Our Examples=====&lt;br /&gt;
&lt;br /&gt;
Please start by downloading the [http://www.phidgets.com/downloads/examples/CSharp.zip examples] and unpack them into a folder.  While these examples were written in Visual Studio 2005 and 2008, Visual Studio 2010 will easily open and upgrade them. To load all projects in Visual Studio, go to File &amp;amp;rarr; Open &amp;amp;rarr; Project, and open {{Code|AllExamples/AllExamples.sln}} or {{Code|AllExamples/AllExamples_vs2008.sln}} for Visual Studio 2005 and 2008, respectively.&lt;br /&gt;
&lt;br /&gt;
If you are opening the Phidget examples in Visual Studio 2010, you will need to go through the Visual Studio Conversion Wizard to convert the 2005 or 2008 project. &lt;br /&gt;
[[File:VS2005 Conversion Wizard.PNG|link=|alt=Conversion Wizard]]&lt;br /&gt;
&lt;br /&gt;
The easiest way to confirm that your environment is set up properly will be to compile and run the {{Code|HelloWorld}} C/C++ example.&lt;br /&gt;
&lt;br /&gt;
Start by setting the {{Code|HelloWorld}} project as your start up project.&lt;br /&gt;
&lt;br /&gt;
The only thing left to do is to run the example! Click on Debug &amp;amp;rarr; Start Debugging. Please note that the projects, by default try to find the {{Code|Phidget21.NET.dll}} in the {{Code|C:\Program Files\Phidgets}}. If you have it installed in another location, please change the path to the file&#039;s location accordingly. If you are receiving an error message regarding that the namespace Phidgets cannot be found, please re-add the reference to {{Code|Phidget21.NET.dll}}. Please see the [[#Write Your Own Code | Write Your Own Code ]] section for details. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Run.PNG|link=|alt=Run]]&lt;br /&gt;
&lt;br /&gt;
This program will detect for devices that are attached/detached on the computer. Go ahead, and attach or detach your devices! Here is an example output:&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 HelloWorld Output.PNG|link=|alt=HelloWorld Output]]&lt;br /&gt;
&lt;br /&gt;
After confirming that the {{Code|HelloWorld}} example is working, you can proceed to run the example for your device. {{FindYourDevice}}  Please ensure that you have set your start up project to be the one that matches your device before compiling. &lt;br /&gt;
&lt;br /&gt;
Once you have the C# examples running, we have a [[#Follow the Examples|teaching]] section below to help you follow them.&lt;br /&gt;
&lt;br /&gt;
=====Write Your Own Code=====&lt;br /&gt;
&lt;br /&gt;
When you are building a project from scratch, or adding Phidget function calls to an existing project, you&#039;ll need to configure your environment to properly link the Phidget C# libraries. To begin: &lt;br /&gt;
&lt;br /&gt;
1. Generate a new Visual C# Windows Applications project with a descriptive name such as PhidgetTest. &lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 New Project.PNG|link=|alt=New Project]]&lt;br /&gt;
&lt;br /&gt;
2. Add a reference to the Phidget .NET library.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Add Reference.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
3. Under the .NET tab, select {{Code|Phidget21.NET.dll}}.&lt;br /&gt;
If you used our installer, these files are installed in {{Code|C:\Program Files\Phidgets}}, by default. If it does not appear in this list, then you can browse to the Phidget Framework installation directory and add the file.&lt;br /&gt;
&lt;br /&gt;
[[File:CSharp VS2005 Add Reference 2.PNG|link=|alt=Add Reference]]&lt;br /&gt;
&lt;br /&gt;
4. Then, in your code, you will need to include the Phidget .NET library:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  using Phidgets;&lt;br /&gt;
  using Phidgets.Events;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The project now has access to the Phidget function calls and you are ready to begin coding.&lt;br /&gt;
&lt;br /&gt;
The same [[#Follow the Examples|teaching ]] section which describes the examples also has further resources for programming your Phidget.&lt;br /&gt;
&lt;br /&gt;
==Follow the Examples==&lt;br /&gt;
&lt;br /&gt;
By following the instructions for your operating system and compiler above, you probably now have a working example and want to understand it better so you can change it to do what you want.  This teaching section has resources for you to learn from the examples and write your own.&lt;br /&gt;
&lt;br /&gt;
Your main reference for writing C# code will be our C# API information, with syntax for all of our functions:&lt;br /&gt;
&lt;br /&gt;
{{UsingAPhidgetInCodeGeneral|both of which are available in C#|[http://www.phidgets.com/documentation/Phidget21.NET.zip .NET API]}}&lt;br /&gt;
&lt;br /&gt;
===Example Flow===&lt;br /&gt;
&lt;br /&gt;
{{ExamplePseudocode|In C#, you can name these &#039;&#039;&#039;event&#039;&#039;&#039; functions whatever you like.  You will add them to the Phidget .NET library in the Main Code section.  This hooks them into the actual events when they occur. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
In the example code, the event functions common to all Phidgets are things like attach, detach, and error handling.&amp;lt;br&amp;gt;&lt;br /&gt;
Other event functions will be specific to each device, like when a tag is read on an RFID board, or when a sensor value changes on an Interface Kit.&lt;br /&gt;
|Creating a Phidget software object in C# is specific to the Phidget.  For a Phidget Spatial, for example, this would involve creating a {{Code|Spatial}} object.  The examples show how to do this and other API functions.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
The object provides device specific methods and properties which are available from the API for your specific Phidget.|&lt;br /&gt;
[http://www.phidgets.com/documentation/Phidget21.NET.zip .NET API]}}&lt;br /&gt;
&lt;br /&gt;
===Code Snippets===&lt;br /&gt;
&lt;br /&gt;
Specific calls in MATLAB will differ in syntax from those on the [[General Phidget Programming]] page, but the concepts stay the same.  &lt;br /&gt;
&lt;br /&gt;
It may help to have the [[General Phidget Programming]] page and this section open at the same time, because they parallel each other and you can refer to the C# syntax.  However, &#039;&#039;many&#039;&#039; additional concepts are covered on the General Phidget Programming page on a high level, such as using multiple Phidgets, handling errors, and different styles of programming.&lt;br /&gt;
&lt;br /&gt;
====Step One: Initialize and Open====&lt;br /&gt;
&lt;br /&gt;
The open() function opens the software object, but not hardware.  So, it is not a guarantee you can use the Phidget immediately.&lt;br /&gt;
&lt;br /&gt;
The different types of open can be used with parameters to try and get the first device it can find, open based on its serial number, or even open across the network. The API manual lists and [[General Phidget Programming]] discusses all of the available modes that open provides.&lt;br /&gt;
&lt;br /&gt;
For example, if we were using a Temperature Sensor board as our device, the general calls would look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using Phidgets;&lt;br /&gt;
using Phidgets.Events;&lt;br /&gt;
// using.....&lt;br /&gt;
&lt;br /&gt;
namespace Program {&lt;br /&gt;
    class Code {&lt;br /&gt;
        static void Main(string[] args) {&lt;br /&gt;
            try {&lt;br /&gt;
&lt;br /&gt;
                // Declare a TemperatureSensor object&lt;br /&gt;
                TemperatureSensor device = new TemperatureSensor(); &lt;br /&gt;
                &lt;br /&gt;
                // Hook in any event handlers&lt;br /&gt;
                // ...&lt;br /&gt;
&lt;br /&gt;
                // Open the device&lt;br /&gt;
                device.open();&lt;br /&gt;
&lt;br /&gt;
            } catch (PhidgetException ex) { Console.WriteLine(ex.Description); }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Two: Wait for Attachment (plugging in) of the Phidget====&lt;br /&gt;
&lt;br /&gt;
To use the Phidget, it must be plugged in (attached). We can handle this by using event driven programming and tracking the AttachEvents and DetachEvents, or we can handle this by calling waitForAttachment. This function works for any Phidget. WaitForAttachment will block indefinitely until a connection is made to the Phidget, or an optional timeout is exceeded:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
  device.open();&lt;br /&gt;
  Console.WriteLine(&amp;quot;Waiting for TemperatureSensor to be attached....&amp;quot;);&lt;br /&gt;
  device.waitForAttachment();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One important thing to remember is that when working with Phidgets, a local connection will reserve the device until closed. This means only one program can access the Phidget locally. Many computers can access one Phidget over the [[Phidget WebService]].&lt;br /&gt;
&lt;br /&gt;
====Step Three: Do Things with the Phidget====&lt;br /&gt;
&lt;br /&gt;
We recommend the use of event driven programming when working with Phidgets. This allows the program to execute other tasks until the Phidget generates a new event.  You can hook a custom function into an event trigger like this, using the Interface Kit Phidget as an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
ifKit.SensorChange += new SensorChangeEventHandler(ifKit_SensorChange);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ifKit_SensorChange method is defined as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
void ifKit_SensorChange(object sender, SensorChangeEventArgs e) {&lt;br /&gt;
   textBox1.Text = &amp;quot;Index &amp;quot; + e.Index + &amp;quot; Value: &amp;quot; + e.Value;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some values can be directly read and set on the Phidget, and inside polling loops used as an alternative to event driven programming.  These functions can be used inside a polling loop as an alternative to event driven programming.  The line inside the loop would be something like this, after which you could do something with the value:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
int val = device.sensors[0].Value;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Step Four: Close and Delete====&lt;br /&gt;
&lt;br /&gt;
At the end of your program, unhook any events and call Application.DoEvents(). This will make sure there are no outstanding events being processed before calling close.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
private void Form1_FormClosing(object sender, FormClosingEventArgs e)  {&lt;br /&gt;
    ifKit.SensorChange -= new SensorChangeEventHandler(ifKit_SensorChange);&lt;br /&gt;
    //run any events in the message queue&lt;br /&gt;
    Application.DoEvents();&lt;br /&gt;
    ifKit.close();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{MoreHowTos}}&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;complete&#039;&#039; set of functions you have available for all Phidgets can be found in the [http://www.phidgets.com/documentation/Phidget21.NET.zip .NET API].  You can also find more description on any device-specific function in the Device API page for your specific Phidget, which can be found on its product page on our [http://www.phidgets.com main website].&lt;br /&gt;
&lt;br /&gt;
==Common Problems and Solutions/Workarounds==&lt;br /&gt;
&lt;br /&gt;
==={{ProblemSolution|All Operating Systems|The Phidgets.Events.ErrorEventHandler conflicts with System.IO.ErrorEventHandler.}}===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using Phidgets;&lt;br /&gt;
using Phidgets.Events;&lt;br /&gt;
...&lt;br /&gt;
spatial.Error += new ErrorEventHandler(spatial_Error);&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
void spatial_Error(object sender, ErrorEventArgs e){&lt;br /&gt;
   ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code produces the following errors:&lt;br /&gt;
&lt;br /&gt;
{{Code|&#039;ErrorEventHandler&#039; is an ambiguous reference between &#039;System.IO.ErrorEventHandler&#039; and &#039;Phidgets.Events.ErrorEventHandler&#039;}}.&lt;br /&gt;
&lt;br /&gt;
and&lt;br /&gt;
&lt;br /&gt;
{{Code|&#039;ErrorEventArgs&#039; is an ambiguous reference between &#039;System.IO.ErrorEventArgs&#039; and &#039;Phidgets.Events.ErrorEventArgs&#039;}}.&lt;br /&gt;
&lt;br /&gt;
The error is due to the {{Code|System.IO}} and {{Code|Phidgets.Events}} namespaces both having a class called {{Code|ErrorEventHandler}}.&lt;br /&gt;
&lt;br /&gt;
To get around this issue, use the fully qualified namespace when referring to the {{Code|ErrorEventHandler}} and {{Code|ErrorEventArgs}} classes:&lt;br /&gt;
&amp;lt;div class=&amp;quot;source&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=csharp&amp;gt;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using Phidgets;&lt;br /&gt;
using Phidgets.Events;&lt;br /&gt;
...&lt;br /&gt;
spatial.Error += new Phidgets.Events.ErrorEventHandler(spatial_Error);&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
void spatial_Error(object sender, Phidgets.Events.ErrorEventArgs e){&lt;br /&gt;
   ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>192.168.3.183</name></author>
	</entry>
</feed>