Tutorial for Windows

Contents

Overview

The GemSDK for Windows has two important files, GemSDK.dll and GemSDK.Net.dll. GemSDK.dll is the native implementation of the API and can be used directly from C/C++ or other languages that support C interfacing. You can also write your own bindings for your other languages using this dll and the provided headers. The second file, GemSDK.Net.dll, is a wrapper around the native GemSDK.dll providing support for .NET languages (C#, VB.NET, etc…). This tutorial will focus on the usage of GemSDK.Net.dll in the C# languages.

Getting Started

Downloads

In this tutorial we are going to use Visual Studio 2015. If you’re using an older version of Visual Studio you’d have to download and install the following:

The GemSDK is available to download from here: Windows SDK 0.0.3v BETA (x86 / 32 bit)

Preparation

Hardware requirements:

Software requirements:

  1. Extract the downloaded zip archive
  2. Create a new C# Console Application in Visual Studio by navigating to: File > New > Project… and selecting Visual C# under templates, and then Console Application
  3. Add a reference to GemSDK.Net.dll by right clicking on References under the newly created project on the Solution tree and selecting Add Reference…, in the new window, click on Browse in the left menu, and then click on the button Browse… in the bottom. Navigate to the folder you extraced the SDK and select it. When you done press OK.

Pairing a Gem with Windows

Before we start to write code, we need to pair the Gem(s) with Windows. For each Gem we want to connect, do the following:

Make sure the Gem is on, and is discoverable. The gem can be in the following 4 states:
1. When the Gem is discoverable the blue led will blink every 5 seconds.
2. If the Gem is connected to something it will not be discoverable and the led will blink very fast.
3. The Gem is off, either because the battery is too low or the on/off switch is flipped. (All leds are off)
4. The Gem is charging, it is not discoverable and cannot be connected to. (The yellow led will be on constantly while charging)

Open your system tray, click on the Bluetooth symbol and then Show Bluetooth Devices

Alt

The Bluetooth Settings window will open up, and you will see all your discoverable Gems in the format “Amber_XXXX” where XXXX is the last 2 bytes of the Gem’s MAC address (each byte represented as 2 hexadecimal digits).

Note: Older versions of Gem’s firmware (1.1.7 and below) will be displayed as “Amber_v03” instead.

Alt

Click on your Gem and then press the Pair button. When Windows is finished pairing the Gem, the subtext under the Gem will say either “Connected” or “Paired”.

Alt

That’s it, now Windows will remember your Gem until you remove it by clicking “Remove device”.

Scanning for Gems

The first things we have to do in order to connect to a Gem is scan for nearby Gems, select the one we want to connect to, and connect to it.
In the Windows, there is no option to scan for Gems, instead, we need to choose a Gem from a list of paired Gems.

First we’ll add using GemSDK.Net; to the top of our program to allow access to the GemSDK API.
Next, we add the following line in order to initialize the GemSDK library: (This method must be called before calling to anything else)

static void Main(string[] args)
{
GemManager.Initialize();
}

For this example, we will take the first Gem in the list:

 Gem gem = GemManager.Gems.FirstOrDefault();

Now check if we got a Gem:

if(gem == null)
{
    Console.WriteLine("Gem not found");
    GemManager.Terminate();
    // TODO terminate the program
}

Receiving data

Now that we have our Gem, we want to receive data from it. When the Gem is connected it starts sending CombinedData immedietly, so before we connect to the Gem we will subscribe to the OnCombinedData event:

gem.OnCombinedData += (float[] quaternion, float[] acceleration) =>
{
    Console.WriteLine("{0},{1},{2},{3}", quaternion[0], quaternion[1], quaternion[2], quaternion[3]);
};

Now we can finally connect the Gem:

gem.Connect();
Console.WriteLine("Connected");
Console.ReadLine(); // Block and the user press enter
gem.Disconnect();
Console.WriteLine("Disconnected");
GemManager.Terminate();

After we finished with the GemSDK we call to the GemManager.Terminate() to free up any resources used by it.

The entire program should look like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GemSDK.Net;

namespace Tutorial
{
    class Program
    {
        static void Main(string[] args)
        {
            GemManager.Initialize();

            Gem gem = GemManager.Gems.FirstOrDefault();

            if(gem == null)
            {
                Console.WriteLine("Gem not found");
                GemManager.Terminate();
            }
            else
            {
                gem.OnCombinedData += (float[] quaternion, float[] acceleration) =>
                {
                    Console.WriteLine("{0},{1},{2},{3}", quaternion[0], quaternion[1], quaternion[2], quaternion[3]);
                };

                gem.Connect();

                Console.WriteLine("Connected");
                Console.ReadLine();
                gem.Disconnect();
                Console.WriteLine("Disconnected");

                GemManager.Terminate();
                Console.ReadLine();
            }
        }
    }
}

Now we can run the program:

Alt

Now you can use this data to do whatever! Happy coding!

For further information about the API, you can check out the API Reference documentation.

Samples

Currently there are no samples available for Windows’s GemSDK.