C# 在StreamSocket.ConnectAsync()上找不到元素错误
我在尝试与蓝牙设备(不是BLE)通信时遇到了一个问题,这让我困扰了好几个小时 我使用的是Windows Phone 8.1 Silverlight应用程序 我在appxmanifest中使用serviceid设置DeviceCapability部分:C# 在StreamSocket.ConnectAsync()上找不到元素错误,c#,silverlight,bluetooth,windows-phone-8.1,rfcomm,C#,Silverlight,Bluetooth,Windows Phone 8.1,Rfcomm,我在尝试与蓝牙设备(不是BLE)通信时遇到了一个问题,这让我困扰了好几个小时 我使用的是Windows Phone 8.1 Silverlight应用程序 我在appxmanifest中使用serviceid设置DeviceCapability部分: <!-- bluetooth --> <m2:DeviceCapability Name="bluetooth.rfcomm"> <m2:Device Id="any"> <m2:Functi
<!-- bluetooth -->
<m2:DeviceCapability Name="bluetooth.rfcomm">
<m2:Device Id="any">
<m2:Function Type="serviceId:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" />
</m2:Device>
</m2:DeviceCapability>
当我尝试将一些数据写入设备时,出现了“Element not found”(未找到元素)错误:
当我在ConnectAsync()中从ServiceId中删除大括号时,出现了另一个错误(文件名不正确0x8007007B)
如果你有任何想法,谢谢你的帮助
[编辑:6/4/2015]
我在WinRT(WP 8.1)应用程序上进行了测试,并成功连接到我的设备,改变了操作方式:
var devices = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.FromUuid(new Guid("00001101-0000-1000-8000-00805F9B34FB"))));
var device = devices.First();
var service = await RfcommDeviceService.FromIdAsync(device.Id);
byte[] data = new byte[] { 0xB0, 0x11, 0x11, 0x01, 0xAA, 0xFA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB6 };
try
{
using (StreamSocket socket = new StreamSocket())
{
await socket.ConnectAsync(service.ConnectionHostName, service.ConnectionServiceName);
await socket.OutputStream.WriteAsync(data.AsBuffer());
}
}
catch (Exception)
{
throw;
}
因此,我将这段代码移到了我的WP8.1 Silverlight应用程序中,但变量服务始终为空…很晚了,但你找到了解决方案吗?遗憾的是,没有,我被迫将我的应用程序移到了WP8.1商店应用程序中:/Darn。我也有同样的问题:很晚了,但你找到解决方案了吗?遗憾的是,没有,我被迫将我的应用程序移动到WP8.1商店应用程序:/Darn。我也有同样的问题:很晚了,但你找到解决方案了吗?遗憾的是,没有,我被迫将我的应用程序移动到WP8.1商店应用程序:/Darn。我也有同样的问题:
try
{
//PeerFinder.Start();
//using (var streamSocket = await PeerFinder.ConnectAsync(Peer))
using (var streamSocket = new StreamSocket())
{
// I have to put manually the serviceid because the ServiceId property in the PeerInformation object is always empty...
await streamSocket.ConnectAsync(PeerInformation.HostName, "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}");
// data is a byte[] filled earlier
await streamSocket.OutputStream.WriteAsync(data.AsBuffer());
}
return true;
}
catch
{
return false;
}
finally
{
//PeerFinder.Stop();
}
var devices = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.FromUuid(new Guid("00001101-0000-1000-8000-00805F9B34FB"))));
var device = devices.First();
var service = await RfcommDeviceService.FromIdAsync(device.Id);
byte[] data = new byte[] { 0xB0, 0x11, 0x11, 0x01, 0xAA, 0xFA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB6 };
try
{
using (StreamSocket socket = new StreamSocket())
{
await socket.ConnectAsync(service.ConnectionHostName, service.ConnectionServiceName);
await socket.OutputStream.WriteAsync(data.AsBuffer());
}
}
catch (Exception)
{
throw;
}