.. _naoqi-dot-net: .Net SDK ======== :ref:`Overview ` | :ref:`C++` | :ref:`Python ` | .Net | :ref:`Java ` | :ref:`Matlab ` | :ref:`Urbi ` What it does ------------ **NAOqi.Net** allows you to call any NAOqi method from most Microsoft .Net languages. Featuring a very small download size, and comming with autocompletion, it is one of the easiest ways to program NAO from a remote Windows based machine. It has been principally tested for c# but is known to work in Visual Basic and F#. Limitations ----------- **NAOqi.Net** can only be used on remote Windows machines. It cannot be used on the robot, even via the Mono framework. It does not currently implement NAOqi's ALModule class, and as a consequence, it cannot receive event notifications. Requirements ------------ * .Net version 2 or above for Visual Studio 2005 or Visual Studio 2008 * .Net version 4 or above for Visual Studio 2010 Getting started --------------- Depending on which version of .Net that you wish to target, choose the install that is right for you: * .Net4: naoqi-dotnet4-sdk-*VERSION*.msi * .Net2: naoqi-dotnet2-sdk-*VERSION*.msi On 32 bit machines, files will be placed in: * C:\\Program Files\\Aldebaran\\NAOqi.Net \*VERSION\* On 64 bit machine files will be placed in: * C:\\Program Files (x86)\\Aldebaran\\NAOqi.Net \*VERSION\* Hello World Example ------------------- This example shows how to create a "HelloWorld" application using naoqi-dotnet4 in Visual Studio 2010. **1. Create a New CSharp Project** From the **File** Menu of Visual Studio 2010, choose **New Project**, then select a .Net project type that corresponds to the type of project you wish to create. In this example we will choose to make the simplest C# Console Application. .. image:: /medias/dev/dotnet/new_project-dotnet4.jpg **2. Add a reference** Select the project in **Solution Explorer** and right click to **add a reference**. .. image:: /medias/dev/dotnet/add_reference1-dotnet4.jpg Choose the **Browse** tab and navigate to the naoqi-dotnet4.dll. If you installed to the default location, this will be c:\\Program Files\\Aldebaran\\NAOqi.Net SDK \*VERSION\* .. image:: /medias/dev/dotnet/add_reference2-dotnet4.jpg **3. Add the namespace** .. code-block:: csharp using Aldebaran.Proxies; **4. Connect to a proxy** .. code-block:: csharp TextToSpeechProxy tts = new TextToSpeechProxy("", 9559); The first argument is the IP address or hostname of the NaoQi that you wish to connect to. The second argument is the port which is typically 9559 **5. Call a method** .. code-block:: csharp tts.say("Hello World"); The 'say' method of the TextToSpeech module takes a string argument containing the text that you wish to say. **Complete example** .. code-block:: csharp using Aldebaran.Proxies; class Program { static void Main(string[] args) { TextToSpeechProxy tts = new TextToSpeechProxy("", 9559); tts.say("Hello World"); } } Further examples ---------------- In the install directory, you will find a simple example called NaoCamCSharp which shows how to make a simple windows forms application that controls the head orientation and receives images from the camera. .. _understanding-dotnet-types: Type mappings between c++ and .Net ---------------------------------- The underlying modules of NAOqi use c++ types. All the basic types of c++ that are used in bound methods have very similar types in .Net so need no special translation. More complex c++ types such as std::vector and AL::ALValue are mapped as follows: **Using Generic Lists** std::vector becomes System.Collections.Generic.List .. code-block:: csharp using System.Collections.Generic; ... MotionProxy _motion = new MotionProxy(ip, 9559); // Add items one by one List names = new List(); names.Add("HeadYaw"); names.Add("HeadPitch"); _motion.setStiffnesses(names, 1.0F); // or // Add elements in the constructor List times = new List() {1.0f, 2.0f}; **Using ArrayLists** AL::ALValue becomes System.Collections.ArrayList .. code-block:: csharp using System.Collections; // Using ArrayList ArrayList list = new ArrayList(); list.Add("HeadYaw"); list.Add("HeadPitch"); **Using object[]** The .Net ArrayList is a collection of objects. Because in .Net all types derive from Object, any basic type, or array of objects will be automatically cast into an object or object array if that is what the method accepts. .. code-block:: csharp MotionProxy _motion = new MotionProxy(ip, 9559); object names = new object[] { "HeadYaw", "HeadPitch" }; _motion.setStiffnesses(names, 1.0F); **Complex ArrayLists** This example shows how to get the bytes of an image object. .. code-block:: csharp VideoDeviceProxy _videoDeviceProxy = new VideoDeviceProxy(ip, 9559); // The numbers describe the format: 160*120, RGB, 5fps _videoDeviceProxy.subscribe("dotNetExample", 0, 15, 5); Object imageObject = _videoDeviceProxy.getImageRemote("dotNetExample"); // Take the 6th element of the imageObject as a byte array byte[] imageBytes = (byte[]) ((ArrayList) imageObject)[6]; .. _dotnet-faq: FAQ --- Mismatched target frameworks ++++++++++++++++++++++++++++ If you try to use a naoqi-dotnet2 in Visual Studio 2010, you will receive an error about mis-matched targets. The solution is either to use naoqi-dotnet4, or to add an app.config file to your project which tells Visual Studio to play nice. .. code-block:: xml Building on 64bit machines ++++++++++++++++++++++++++ To build projects on 64 bit machines, you need to choose "x86" in Configuration Manager. If you attempt "Any CPU" you will get errors about mixed architectures. .. _dotnet-changes-in-1.12: Changes in version 1.12 ----------------------- * Support for VS2010 and .Net4 * Support for generic proxies - allows you to call your own c++ modules * Support for non-ascii languages - automatic managed UTF16 to native UTF8 convertion * Updated against NAOqi 1.12 modules and methods