Dotnet

From RobotinoWiki
Jump to: navigation, search

Contents

Introduction

Robotino dotnet icon 64.png .Net is supported by wrapping Robotino's C++ API using Swig

Package links

How to use the C-interface of rec_robotino_api2.dll directly from C#

Set Properties/Build/Platform target from Any to x86 or x64 depending on the bitness of the rec_robotino_api2.dll. Copy rec_robotino_api2.dll to the folder with you C# exe.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{
    class Program
    {
        
        [DllImport("rec_robotino_api2.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern int Com_construct();

        [DllImport("rec_robotino_api2.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool Com_setAddress(int id, [MarshalAs(UnmanagedType.LPStr)] string address);

        [DllImport("rec_robotino_api2.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool Com_connect(int id);

        static void Main(string[] args)
        {
            Console.WriteLine("This is C# program");

            int comId = Com_construct();
            Console.WriteLine("comId={0}", comId);

            bool ok = Com_setAddress(comId, "192.168.1.240");
            Console.WriteLine("Com_setAddress returned {0}", ok);

            ok = Com_connect(comId);
            Console.WriteLine("Com_connect returned {0}", ok);
        }
    }
}

Prerequisites

  1. Firstly, make sure you have the RobotinoAPI2 installed on your system. You also have the option of building it from the sources which can be done from here. If building from the sources, DO NOT forget to set the environment variables pointing to the RobotinoAPI2 install folder.
  2. Swigwin - Download the swigwin package from here and unzip it in the C:\Program Files or (C:\Program Files (x86) for 64Bit Windows) directory.

Building the wrapper

  1. Check out the package from here.
  2. Build and install the package using CMake. Note: the CMake looks for the Robotino API2 package using the environment variable. Make sure it is set.
  3. Once built and installed, set the evironment variable ROBOTINOAPI2WRAPPER32_DIR (if built using a 32Bit compiler ) pointing to the install folder. For example:
    ROBOTINOAPI2WRAPPER32_DIR=C:\Projects\_builds\build_openrobotino_api2_wrapper\install
    or if built using a 64Bit compiler then set an environment variable ROBOTINOAPI2WRAPPER64_DIR instead.
  4. Done!

Examples

A few examples (CS projects) have been provided and can be found under the examples/dotnet folder.

The Openrobotino Forum

The Openrobotino Forum connects the developers with the users. Here you will find more support and you can also post your questions/problems/bugs etc and get a quick response.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox