[IoT] Windows.Devices.SerialCommunication.SerialDevice再次无效。 [英] [IoT]Windows.Devices.SerialCommunication.SerialDevice Not working, again.

查看:132
本文介绍了[IoT] Windows.Devices.SerialCommunication.SerialDevice再次无效。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前一段时间,我试图在Win 10桌面上打开一个串口,但是在获取SerialDevice.FromIdAsync()方法返回SerialDevice对象时遇到了麻烦。截至目前(在Build 10130上)它现在正在工作,这很棒。但是现在我有完全相同的
问题,但这次是物联网。


这是我为之前遇到的问题打开的主题:


https://social.msdn.microsoft.com/Forums/windowsapps/en-US/0c638b8e-482d-462a-97e6-4d8bc86d8767/uwp-windows-10-apps-windowsdevicesserialcommunicationserialdevice-class-not- work?forum = wpdevelop


以下是设备在"devcon.exe stack *"返回列表中的显示方式。命令(通过PowerShell):



USB \VID_10C4& PID_EA60\0001

    名称:Silicon Labs CP210x USB转UART桥接器(COM3)

    设置类:{4d36e978-e325-11ce-bfc1-08002be10318}端口

    上层过滤器:

         silabenm

    控制服务:

         silabser



这是我正在使用的代码,它在Windows 10的桌面版本上运行(Build 10130) :
$

使用System; 
使用Windows.UI.Xaml.Controls;
使用Windows.Devices.SerialCommunication;
使用Windows.Devices.Enumeration;
使用System.Diagnostics;

名称空间WUP_Serial_IO_Testing
{
公共密封分部类MainPage:Page
{
public MainPage()
{
this。的InitializeComponent();
ConnectToSerialPort();
}

private async void ConnectToSerialPort()
{
string _serialSelector = SerialDevice.GetDeviceSelector(" COM3");
// _serialSelector =
// System.Devices.InterfaceClassGuid:=" {86E0D1E0-8089-11D0-9CE4-08003E301F73}" AND System.Devices.InterfaceEnabled:= System.StructuredQueryType.Boolean #True AND(System.Devices.DeviceInstanceId:= USB\VID_10C4& PID_EA60\0001)
DeviceInformationCollection tempInfo = await DeviceInformation.FindAllAsync(_serialSelector);
SerialDevice tempSerial = await SerialDevice.FromIdAsync(tempInfo [0] .Id);
// tempInfo [0] .Id =
// \\?\ USB#VID_10C4& PID_EA60#0001#{86e0d1e0-8089-11d0-9ce4-08003e301f73}

if(tempSerial == null)
Debug.WriteLine(" tempSerial Is null");
else
tempSerial.Dispose();
}
}
}

以上代码是Universal App项目的Code-Behind。我没有添加对项目的任何引用,所以其余的是默认的应用程序模板。


在IoT核心上默认启动的应用程序上,USB转串口适配器显示在"连接设备"上列为"CP2102 USB转UART桥接控制器"。


哦,这一切都在RPi 2上,操作系统版本 - 10.0.10152.0


我不确定它是否有所作为,但是我使用的物联网构建我在29日下载。


这是另一个Bug ?

解决方案

将此信息与新信息混为一谈。


我在我的网站上下载并安装了build 10162桌面和更新代码以使用供应商和产品ID,因此代码现在如下:

使用System; 
使用System.Diagnostics;
使用System.Threading.Tasks;
使用Windows.Devices.SerialCommunication;
使用Windows.UI.Xaml.Controls;

namespace SerialOpenerTester_NetVer_4_5_2
{
public sealed partial class MainPage:Page
{
public MainPage()
{
this。的InitializeComponent();
OpenSerialPort();
}

private async void OpenSerialPort()
{
// USB到UART适配器的USB VID-PID
ushort vid = 0x10C4;
ushort pid = 0xEA60;
string aqs = SerialDevice.GetDeviceSelectorFromUsbVidPid(vid,pid);
var myDevices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(aqs,null);

//使用第一个实例
string id = myDevices [0] .Id; // id == \\?\USB#VID_10C4& PID_EA60#0001#{86e0d1e0-8089-11d0-9ce4-08003e301f73}

SerialDevice serialDevice = await SerialDevice.FromIdAsync(id); //抛出异常

if(serialDevice == null)
{
Debug.WriteLine("Serial Port is Null");
返回;
}

Debug.WriteLine("Serial Port is Opened");

//关闭连接
serialDevice.Dispose();
}
}
}




我现在的问题是

  SerialDevice   serialDevice   =  < span class ="pln"> await   SerialDevice    FromIdAsync    id  );  


要么返回NULL,要么挂起并且永远不会返回。
$

BTW:在两个代码实例中我确实将以下内容添加到'功能'中在'Package.appxmanifest'文件中。

   < DeviceCapability    名称  =  " serialcommunication"  >   
< Device Id = " any" ; >
<功能 类型 = " name: serialPort" />
< span class ="tag">< / Device>
< / DeviceCapability>

有人想过吗?


Awhile ago, I was trying to open a Serial Port on Win 10 Desktop and was having trouble getting the SerialDevice.FromIdAsync() method to return a SerialDevice Object. As of now (on Build 10130) its now working which is great. But now I'm having the exact same issue but this time on IoT.

Here's the thread that I opened for the issue i was having before:

https://social.msdn.microsoft.com/Forums/windowsapps/en-US/0c638b8e-482d-462a-97e6-4d8bc86d8767/uwp-windows-10-apps-windowsdevicesserialcommunicationserialdevice-class-not-working?forum=wpdevelop

Here's how the Device shows up in the returned list from a "devcon.exe stack *" command (via PowerShell):

USB\VID_10C4&PID_EA60\0001
    Name: Silicon Labs CP210x USB to UART Bridge (COM3)
    Setup Class: {4d36e978-e325-11ce-bfc1-08002be10318} Ports
    Upper filters:
        silabenm
    Controlling service:
        silabser

This is the code that I'm using which works as-is on the desktop version of Windows 10 (Build 10130):

using System;
using Windows.UI.Xaml.Controls;
using Windows.Devices.SerialCommunication;
using Windows.Devices.Enumeration;
using System.Diagnostics;

namespace WUP_Serial_IO_Testing
{
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
            ConnectToSerialPort();
        }
        
        private async void ConnectToSerialPort()
        {
            string _serialSelector = SerialDevice.GetDeviceSelector("COM3");
            //  _serialSelector =
            //  System.Devices.InterfaceClassGuid:="{86E0D1E0-8089-11D0-9CE4-08003E301F73}" AND System.Devices.InterfaceEnabled:=System.StructuredQueryType.Boolean#True AND (System.Devices.DeviceInstanceId := USB\VID_10C4&PID_EA60\0001)
            DeviceInformationCollection tempInfo = await DeviceInformation.FindAllAsync(_serialSelector);
            SerialDevice tempSerial = await SerialDevice.FromIdAsync(tempInfo[0].Id);
            //  tempInfo[0].Id =
            //  \\?\USB#VID_10C4&PID_EA60#0001#{86e0d1e0-8089-11d0-9ce4-08003e301f73}

            if (tempSerial == null)
                Debug.WriteLine("tempSerial Is null");
            else
                tempSerial.Dispose();
        }
    }
}

The above code is the Code-Behind from a Universal App project. I haven't added any references to the project so the rest is the default app template.

On the App that's set to start by default on the IoT core, the USB to Serial adapter shows up on the "Connected devices" list as "CP2102 USB to UART Bridge Controller".

Oh, and this is all on a RPi 2, OS version - 10.0.10152.0

I'm not sure if it makes a difference, but the IoT Build that I'm using i downloaded on the 29th.

Is this another Bug?

解决方案

Bumping this with new info.

I downloaded and installed build 10162 on my Desktop and updated the code to use the Vendor and product IDs, So the code is now the following:

using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Windows.Devices.SerialCommunication;
using Windows.UI.Xaml.Controls;

namespace SerialOpenerTester_NetVer_4_5_2
{
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
            OpenSerialPort();
        }

        private async void OpenSerialPort()
        {
            //USB VID-PID of the USB to UART adapter
            ushort vid = 0x10C4;
            ushort pid = 0xEA60;
            string aqs = SerialDevice.GetDeviceSelectorFromUsbVidPid(vid, pid);
            var myDevices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(aqs, null);

            //Use first instance
            string id = myDevices[0].Id; //id == \\?\USB#VID_10C4&PID_EA60#0001#{86e0d1e0-8089-11d0-9ce4-08003e301f73}

            SerialDevice serialDevice = await SerialDevice.FromIdAsync(id); //This throws the Exception

            if (serialDevice == null)
            {
                Debug.WriteLine("Serial Port is Null");
                return;
            }

            Debug.WriteLine("Serial Port is Opened");

            // Close connection
            serialDevice.Dispose();
        }
    }
}


The issue that I have now is that th

SerialDevice serialDevice = await SerialDevice.FromIdAsync(id);

either returns NULL or hangs and never returns.

BTW: in both code instances i did add the following to the 'Capabilities' in the 'Package.appxmanifest' file.

    <DeviceCapability Name="serialcommunication">
      <Device Id="any">
        <Function Type="name:serialPort" />
      </Device>
    </DeviceCapability>

Any thoughts anyone?


这篇关于[IoT] Windows.Devices.SerialCommunication.SerialDevice再次无效。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆