3

我目前正在对蓝牙激活(刚刚启用和一定的操作之后,从Windows CE版本6自动禁用蓝牙)禁用蓝牙
我使用SmartDeviceFramework即CAB文件我然后在Windows CE安装如何启用和使用C#

下面是我的方法,我的工作是使用 (InTheHand.Net.Personal.dll文件蓝牙):

private static void setBluetoothConnection() 
    { 
    try 
     { 
      if (BluetoothRadio.IsSupported == true) 
      { 
       MessageBox.Show("Bluetooth Supported", "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); 
       BluetoothRadio radio = BluetoothRadio.PrimaryRadio; 
       MessageBox.Show(radio.Mode.ToString(), "Before Bluetooth Connection", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); 
       radio.Mode = RadioMode.Discoverable; 
       // here radio.Mode works only if the Windows Device has Bluetooth enabled otherwise gives error 
       MessageBox.Show(radio.Mode.ToString(), "RadioMode Discover", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); 
       bluetoothClient = new BluetoothClient(); 
       //Cursor.Current = Cursors.WaitCursor; 
       BluetoothDeviceInfo[] bluetoothDeviceInfo = bluetoothClient.DiscoverDevices(); 
       MessageBox.Show(bluetoothDeviceInfo.Length.ToString(), "Device Name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); 
       foreach(BluetoothDeviceInfo device in bluetoothDeviceInfo) 
       { 
       Cursor.Current = Cursors.Default; 
       MessageBox.Show(device.DeviceName, "Device Name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); 
       bluetoothClient.Connect(new BluetoothEndPoint(device.DeviceAddress, service)); 
       MessageBox.Show("Bluetooth Connected...", "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); 
       break; 
       } 
      } 
      else 
      { 
       MessageBox.Show("Bluetooth Not Supported", "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); 
      } 
     } 
     catch (Exception ex) 
     { 
      log.Error("[Bluetooth] Connection failed", ex); 
      MessageBox.Show(ex.Message,"Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); 
     } 
    } 

所以我面对错误的位置:

BluetoothRadio radio = BluetoothRadio.PrimaryRadio; 
radio.Mode = RadioMode.Discoverable; // gives error here 

错误

Error setting BluetoothRadio.Mode 

发生上述错误一次当蓝牙设备被禁用,并执行上面的行,并关闭该应用程序
但随着应用程序关闭,并且当我去移动蓝牙管理器,蓝牙启用

我的问题

我必须点击一个按钮2倍时, 应用程序错误关闭(但蓝牙设置为ON),并在范围内第2至 搜索设备使按钮(第1 )而不是1次点击。

我的假设

我认为有可能当程序试图 从OFF可发现能够从手机蓝牙的一些安全问题。

那么,有任何过程System.Digonostics; DLL),通过该我可以自动的WindowsMo​​bile CE在C#设定蓝牙ONOFF

我试图但没有得到它,所以任何人都可以帮助我,或建议任何dll文件的蓝牙连接。

感谢

+0

物联网,蓝牙和32feet.net?向我致敬; )。 – 2015-02-13 05:38:13

+0

感谢您的回复。我尝试使用32feet.net(InTheHand.Net.Personal.dll),但在启用蓝牙时出现错误。你知道我在哪里可以找到Microsoft.WindowsMo​​bile.SharedSource.Bluetooth DLL吗?这个DLL会工作吗?任何想法 – techGaurdian 2015-02-13 06:07:57

回答

3

你会发现这个有用:

Bluetooth Device Development using C#

和下载嵌入式代码工具蓝牙技术在Windows是在这里:

Download

希望这帮助:)

+0

其不是我想要的解决方案...尝试与Microsoft.WindowsMo​​bile.SharedSource.Bluetooth但找不到DLL(如果存在),但谢谢。 – techGaurdian 2015-02-20 05:44:24

+0

下载并安装上述然后导航到:C:\ Program Files文件\微软\ Windows嵌入式源工具\你会发现在那里的DLL;) – ravenx30 2015-02-20 16:54:11

1

我不完全确定你使用的库是什么,所以我不确定它为什么给你这个错误。

以下是关于如何在设备上设置蓝牙连接模式的MSFT文档。如果你可以使用这些DLL,你可能会有一些运气。

https://msdn.microsoft.com/en-us/library/bb416244.aspx

+0

是的,我已经尝试过,但没有成功实施它。我假设BthGetMode和BthSetMode的值是int ..我想RadioMode ......但是谢谢 – techGaurdian 2015-02-19 18:33:17