目前,我正在C#2010中編程USB藍牙適配器。我想以這種方式進行編程,使其可以自動與找到的藍牙設備配對。我不希望用戶手動接受手機以及Windows 7中的配對請求。我正在使用我的手機(X Peria S)對此進行測試。這種編程方法是可行的嗎?我試圖代碼,藍牙這種使用32feet.net庫,這裏是我的代碼帶有Windows 7和手機的自動(藍牙配對)
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 InTheHand.Net;
using InTheHand.Net.Bluetooth;
using InTheHand.Net.Sockets;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private Guid service = BluetoothService.BluetoothBase;
private BluetoothClient bluetoothClient;
public Form1()
{
InitializeComponent();
}
private void Search_Bluetooth(object sender, EventArgs e)
{
BluetoothRadio.PrimaryRadio.Mode = RadioMode.Discoverable;
bluetoothClient = new BluetoothClient();
Cursor.Current = Cursors.WaitCursor;
BluetoothDeviceInfo [] bluetoothDeviceInfo = bluetoothClient.DiscoverDevices(10);
comboBox1.DataSource = bluetoothDeviceInfo;
comboBox1.DisplayMember = "DeviceName";
comboBox1.ValueMember = "DeviceAddress";
comboBox1.Focus();
Cursor.Current = Cursors.Default;
}
private void Pair(object sender, EventArgs e)
{
if (comboBox1.SelectedValue != null)
{
try
{
bluetoothClient.Connect(new BluetoothEndPoint((BluetoothAddress)comboBox1.SelectedValue, service));
MessageBox.Show("Connected");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
}
當我運行這個項目中,我看到在藍牙設備列表中,但周圍當過我要配對它給我一個錯誤說「連接嘗試失敗,因爲連接的方沒有正確響應一段時間」
我認爲這個問題是私人的Guid =服務BluetoothService.BluetoothBase,但我不知道,我是使用正確的服務.BluetoothBase與我的手機配對?
這是否有任何現有的解決方案?任何幫助和建議,高度讚賞。
謝謝。
我一時舉不出任何具體文件,但我很確定這不是藍牙的工作原理。用戶需要有一個協議來配對他們的設備,否則如果一個設備可以在未經他們許可的情況下與他們配對,那麼這將會是一個安全漏洞。 – tnw 2013-05-10 15:26:38
你好Salomonder, – 2013-05-10 18:21:44