Using In The Hand 32feet library for .NET Compact Framework 3.5, when runing their sample project Chat2Device on a Datalogic Scorpio X3 running Windows Embedded Handheld 6.5 Professional CE OS 5.2.29366 Build 29366.5.3.12.48 the command to switch Bluetooth radio to "Discoverable" fails. I added some additional error reporting code and found the native error code is 1359 (Internal Error Occurred?)
There is no problem communicating between devices using Bluetooth within this sample project on the mobile device, only retrieving PrimaryRadio info or attempting to set RadioMode to any mode throws exception.
Full error message is:
Win32Exception Error setting BluetoothRadio Error Code 1359 at InTheHand.Net.Bluetooth.Msft.WindowsBluetoothRadio.set_Mode(RadioMode value)
Code is:
BluetoothRadio.PrimaryRadio.Mode = RadioMode.Discoverable;
The following code in the sample also fails with similar exception:
var myRadio = BluetoothRadio.PrimaryRadio;
if (myRadio == null) {
wtr.WriteLine("No radio hardware or unsupported software stack");
return;
}
var mode = myRadio.Mode;
// Warning: LocalAddress is null if the radio is powered-off.
wtr.WriteLine("* Radio, address: {0:C}", myRadio.LocalAddress);
wtr.WriteLine("Mode: " + mode.ToString());
wtr.WriteLine("Name: " + myRadio.Name);
wtr.WriteLine("HCI Version: " + myRadio.HciVersion
+ ", Revision: " + myRadio.HciRevision);
wtr.WriteLine("LMP Version: " + myRadio.LmpVersion
+ ", Subversion: " + myRadio.LmpSubversion);
wtr.WriteLine("ClassOfDevice: " + myRadio.ClassOfDevice
+ ", device: " + myRadio.ClassOfDevice.Device
+ " / service: " + myRadio.ClassOfDevice.Service);
wtr.WriteLine("S/W Manuf: " + myRadio.SoftwareManufacturer);
wtr.WriteLine("H/W Manuf: " + myRadio.Manufacturer);
Any suggestions for a fix, or alternate method to set the radio to discoverable programatically.
The relevant sections of library code;
private const string btdrtDll = "btdrt.dll";
[DllImport(btdrtDll, SetLastError = true)]
internal static extern int BthReadScanEnableMask(out WinCeScanMask pmask);
[DllImport(btdrtDll, SetLastError = true)]
internal static extern int BthWriteScanEnableMask(WinCeScanMask mask);
[Flags()]
internal enum WinCeScanMask : byte
{
None = 0,
InquiryScan = 1,
PageScan = 2,
}
public void SetMode(bool? connectable, bool? discoverable)
{
// TO-DO set power-on here
//
WinCeScanMask mask;
if (connectable.HasValue && discoverable.HasValue) {
// Will set both bits so do NOT need to know their current value.
mask = 0;
} else {
int resultR = NativeMethods.BthReadScanEnableMask(out mask);
if (resultR != 0) {
throw new System.ComponentModel.Win32Exception(resultR, "Error getting BluetoothRadio mode");
}
}
switch (connectable) {
case true:
mask |= WinCeScanMask.PageScan;
break;
case false:
mask &= ~WinCeScanMask.PageScan;
break;
// null NOP
}
switch (discoverable) {
case true:
mask |= WinCeScanMask.InquiryScan;
break;
case false:
mask &= ~WinCeScanMask.InquiryScan;
break;
// null NOP
}
var result = NativeMethods.BthWriteScanEnableMask(mask);
if (result != 0) {
throw new System.ComponentModel.Win32Exception(result, "Error setting BluetoothRadio mode");
}
}