UWP应用程序开发环境: 1.桌面 2.windows 10 Pro 3. vs2017 15.6 4.插入式无线网卡
当我使用wifi直接技术直接连接到Android系统时,连接不稳定 1.“hs”在通电或读取设备配置时遇到错误。这可能是由于硬件故障或连接不良造成的。 (HRESULT异常:0x80070288) 2.找不到元素 上述两个错误经常出现。请有经验的人帮助我们。谢谢。代码如下:
private async void ConnectionDevice()
{
try
{
if (directDevice != null)
{
directDevice.Dispose();
directDevice = null;
}
await Views.MainPage.mainPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
_deviceViewModel.Message = "设备连接中...";
});
//
WiFiDirectConnectionParameters connectionParameters = new WiFiDirectConnectionParameters();
connectionParameters.PreferenceOrderedConfigurationMethods.Add(WiFiDirectConfigurationMethod.PushButton);
//connectionParameters.PreferredPairingProcedure = WiFiDirectPairingProcedure.GroupOwnerNegotiation;
directDevice = await WiFiDirectDevice.FromIdAsync(_deviceViewModel.DeviceId);
directDevice.ConnectionStatusChanged += DirectDevice_ConnectionStatusChanged;
if (directDevice != null)
{
var EndpointPairs = directDevice.GetConnectionEndpointPairs();
//创建SOCKET连接监听
StreamSocketListener socketListener = new StreamSocketListener();
await socketListener.BindEndpointAsync(EndpointPairs[0].LocalHostName, "9568");
//连接监听事件
socketListener.ConnectionReceived += SocketListener_ConnectionReceived;
await Views.MainPage.mainPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
_deviceViewModel.Message = "设备连成功";
});
}
}
catch (Exception ex)
{
await Views.MainPage.mainPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
_deviceViewModel.Message = ex.Message;
});
ConnectionDevice();
}
}
答案 0 :(得分:0)
我不知道您是否解决了该问题,但我认为这些错误来自功能,请确保您具有以下功能:
<Capability Name="internetClient" />
<Capability Name="internetClientServer" />
<DeviceCapability Name="proximity" />