How to send array via Bluetooth Low Energy in Windows Desktop APP?

0

I'm having enormous trouble communicating with my arduino over BLE in my Windows desktop application. I did understand that i have to enable WinRT API in my application to access GATT and to use win 8.1 etc. (I followed this tutorial https://software.intel.com/en-us/articles/using-winrt-apis-from-desktop-applications). I don't understand how to communicate with my device from this point.

So i have this values for the device (adafruit nrf8001):

UART Service UUID: 6E400001-B5A3-F393-E0A9-E50E24DCCA9E TX Characteristic UUID: 6E400002-B5A3-F393-E0A9-E50E24DCCA9E RX Characteristic UUID: 6E400003-B5A3-F393-E0A9-E50E24DCCA9E

how do i send a simple array - or easier a simple ASCII value to the device? On iOS and android i find plenty of examples, but not for a windows desktop app ...

would be super happy if someone can help!

phil edit: i thought this should do the job... but the app crashes on the last point:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Windows.Devices.Bluetooth.GenericAttributeProfile;
using Windows.Devices.Enumeration;
using Windows.UI.Xaml;

namespace LucidMobileCCproto
{
    public partial class LucidMIControlPanel : Form
    {

        GattDeviceService service2 = null;


        private async void Discover_Click(object sender, EventArgs e)
        {
            var Services = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(new Guid("6E400001-B5A3-F393-E0A9-E50E24DCCA9E")), null);
            GattDeviceService Service = await GattDeviceService.FromIdAsync(Services[0].Id);

            //Check Service Name
            textBox1.Text = "Using service: " + Services[0].Name;

            GattReliableWriteTransaction gattTransaction = new GattReliableWriteTransaction(); //Orientation on MSDN Article

            GattCharacteristic gattCharacteristic = Service.GetCharacteristics(new Guid("6E400002-B5A3-F393-E0A9-E50E24DCCA9E"))[0];

            //Check Characteristic 
            textBox2.Text = Convert.ToString(gattCharacteristic.CharacteristicProperties);

            //initialize Buffer
            var writer = new Windows.Storage.Streams.DataWriter();
            writer.WriteByte(2);
            gattTransaction.WriteValue(gattCharacteristic, writer.DetachBuffer());


            //Programm Crashes here
            GattCommunicationStatus status = await gattTransaction.CommitAsync();
        }
    }

The crash: Exception:Thrown: "The attribute cannot be written. (Exception from HRESULT: 0x80650003)" (System.Exception) A System.Exception was thrown: "The attribute cannot be written. (Exception from HRESULT: 0x80650003)"

c#
bluetooth
windows-runtime
arduino
bluetooth-lowenergy
asked on Stack Overflow Aug 9, 2015 by Philip • edited Aug 10, 2015 by Philip

1 Answer

3

wow just took me a few hours to get the solution:

I Just had to add the write option (i deleted the reliable write as well)

    private async void Discover_Click(object sender, EventArgs e)
    {
        var Services = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(new Guid("6E400001-B5A3-F393-E0A9-E50E24DCCA9E")));
        GattDeviceService Service = await GattDeviceService.FromIdAsync(Services[0].Id);
        GattCharacteristic gattCharacteristic = Service.GetCharacteristics(new Guid("6E400002-B5A3-F393-E0A9-E50E24DCCA9E"))[0];

        var writer = new DataWriter();
        writer.WriteString("#FF00FF");
        var res = await gattCharacteristic.WriteValueAsync(writer.DetachBuffer(), GattWriteOption.WriteWithoutResponse);
    }
answered on Stack Overflow Aug 10, 2015 by Philip

User contributions licensed under CC BY-SA 3.0