Hi,
I’ve got a little time now to tinker somewhat. Does anyone have a starting point to begin using a Bluetooth dongle on the FEZ Dominio? I rewritten the USB mouse interface example to test communication with the dongle. I get a response of:
Data = 15 4 0 1 0 0 0 0 0 0 0 0 0 0 0 0
Here is the code:
using System;
using System.Threading;
using Microsoft.SPOT;
using GHIElectronics.NETMF.USBHost;
using GHIElectronics.NETMF.System;
namespace BlueTooth
{
public class Program
{
static USBH_RawDevice bluetooth;
static USBH_RawDevice.Pipe bluetoothPipe; // needed to read the bluetooth data
static Thread bluetoothThread; // polls the bluetooth for data
public static void Main()
{
// Subscribe to USBH event.
USBHostController.DeviceConnectedEvent += DeviceConnectedEvent;
// Sleep forever
Thread.Sleep(Timeout.Infinite);
}
static void DeviceConnectedEvent(USBH_Device device)
{
Debug.Print("BlueTooth connected");
bluetooth = new USBH_RawDevice(device);
// Get descriptors
USB_Descriptors.ConfigurationDescriptor cd = bluetooth.GetConfigurationDescriptors(0);
// communication endpoint
USB_Descriptors.EndpointDescriptor bluetoothEP = null;
// look for HID class
for (int i = 0; i < cd.interfaces.Length; i++)
{
// look for input interrupt Endpoint
for (int ep = 0; ep < cd.interfaces[i].endpoints.Length; ep++)
{
// is it interrupt Endpoint?
if (cd.interfaces[i].endpoints[ep].bmAttributes == 0x03)
{
// set configuration
bluetooth.SendSetupTransfer(0x00, 0x09, cd.bConfigurationValue, 0x00);
bluetoothEP = cd.interfaces[i].endpoints[ep]; // get endpoint
bluetoothPipe = bluetooth.OpenPipe(bluetoothEP); // open pipe
bluetoothPipe.TransferTimeout = 0; // recommended for interrupt transfers
bluetoothThread = new Thread(BlueToothThread); // create the polling thread
bluetoothThread.Priority = ThreadPriority.Highest; // we should read as fast as possible
bluetoothThread.Start();
break;
}
}
}
}
static void BlueToothThread()
{
int count,i;
string btdatastring = "";
// Maximum data is wMaxPacketSize
byte[] bluetoothData = new byte[bluetoothPipe.PipeEndpoint.wMaxPacketSize];
// Read every bInterval
while (true)
{
Thread.Sleep(bluetoothPipe.PipeEndpoint.bInterval);
count = bluetoothPipe.TransferData(bluetoothData, 0, bluetoothData.Length);
btdatastring = "Data = ";
for(i=0; i<bluetoothData.Length;i++)
{
btdatastring = btdatastring +((sbyte)(bluetoothData[i]) + " ");
}
Debug.Print(btdatastring);
}
}
}
}
Any help would be greatly appreciated!