我有一个项目可以在C#应用程序和手机之间连接蓝牙,并通过Stream使用AT命令在我的应用程序上拨打号码。
我看过https://github.com/sidiandi/Sidi.HandsFree,但我听不懂这段代码。
我尝试扫描并配对,它工作正常,但无法连接。你能帮我吗?
我的英语不好
我的下面的代码:
private void button2_Click(object sender, EventArgs e)
{
BluetoothDeviceInfo[] paired = localClient.DiscoverDevices(255, false, true, false, false);
foreach (BluetoothDeviceInfo device in devices)
{
bool isPaired = false;
for (int i = 0; i < paired.Length; i++)
{
if (device.Equals(paired[i]))
{
isPaired = true;
break;
}
}
// if the device is not paired, pair it!
if (!isPaired)
{
// replace DEVICE_PIN here, synchronous method, but fast
isPaired = BluetoothSecurity.PairRequest(BluetoothAddress.Parse(Addconnect), null);
if (isPaired)
{
// now it is paired
}
else
{
// pairing failed
}
}
}
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
Addconnect = dataGridView1.CurrentCell.Value.ToString();
}
private void button3_Click(object sender, EventArgs e)
{
foreach (BluetoothDeviceInfo device in devices)
{
if (device.DeviceAddress.ToString() == Addconnect)
{
try
{
localClient.SetPin(null);
localClient.BeginConnect(device.DeviceAddress, BluetoothService.SerialPort, new AsyncCallback(Connect), device);
}
catch
{
}
}
}
}