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