0
我们正在创建的应用程序COMMUNICAT与Windows PC外部设备(在这里我们使用的是Windows 7),在PC,我们正在使用蓝牙适配器。在32Feet窗口BluetoothListener.AcceptBluetooth客户端块7
,当我们试图发现和配对设备是在Windows PC全成。
但在代码方面,我们正在试图连接它不是全成设备,在这里我们使用32feet.net连接设备。
下面的代码我试图连接设备。
////_serviceClassId = new Guid("9bde4762-89a6-418e-bacf-fcd82f1e0677");
Guid serviceClass = BluetoothService.RFCommProtocol;
int selectedIndex = device_list.SelectedIndex;
BluetoothDeviceInfo selectedDevice = this.array[selectedIndex];
var lsnr = new BluetoothListener(serviceClass);
lsnr.Start();
Task.Run(() => Listener(lsnr));
与收听方法是
private void Listener(BluetoothListener lsnr)
{
try
{
while (true)
{
using (var client = lsnr.AcceptBluetoothClient())
{
using (var streamReader = new StreamReader(client.GetStream()))
{
try
{
var content = streamReader.ReadToEnd();
if (!string.IsNullOrEmpty(content))
{
////_responseAction(content);
}
}
catch (IOException)
{
client.Close();
break;
}
}
}
}
}
catch (Exception exception)
{
// todo handle the exception
// for the sample it will be ignored
}
}
如果我运行会受阻于lsnr.AcceptBluetoothClient()
任何一个可以帮助错在这是何种应用?
注:蓝牙设备创建了两个相称一个是输入和花药一个是输出端口,当我们通过PC连接。