简体   繁体   English

C#SerialDevice没有端口信息(Raspberry Pi 3)

[英]C# SerialDevice no port information (Raspberry Pi 3)

I have two USB receivers for bar-code scanners connected to a raspberry pi3 (Windows IOT Core). 我有两个用于条形码扫描仪的USB接收器,它们连接到树莓派pi3(Windows IOT核心)。

I can connect to them and list the USB Virtual COM devices and connect to them and receive data. 我可以连接到它们并列出USB虚拟COM设备,然后连接到它们并接收数据。 But I can't differentiate between the two, the IDs are identical and the system is not providing Port numbers. 但是我无法区分两者,ID相同,系统未提供端口号。

When I call Current.portnumber.ToString() the string is empty. 当我调用Current.portnumber.ToString()时,字符串为空。

I am hoping to assign each device to a person and have them scan a bar-code for their username and would like to display which scanner is associated with which person (Such as Com5 = Bill Com6 = Dave) but just can't find a unique identifier for each virtual com 我希望将每个设备分配给一个人,让他们扫描条形码以查找其用户名,并希望显示与哪个人关联的扫描仪(例如Com5 = Bill Com6 = Dave),但找不到每个虚拟com的唯一标识符

private async void ListAvailablePorts()
        {
            try
            {
                string aqs = SerialDevice.GetDeviceSelector();
                var infos = await DeviceInformation.FindAllAsync(aqs);

                foreach (var info in infos)
                {
                    var serialDevice = await SerialDevice.FromIdAsync(info.Id);
                    DeviceInformation Current = info as DeviceInformation;
                    if (serialDevice != null && Current.Name == "USB Virtual COM")
                    {
                        listOfDevices.Add(Current);
                        ComList.Items.Add(Current.Name.ToString());
                    }
                }

                DeviceList.ItemsSource = listOfDevices;

                ComList.SelectedIndex = -1;
                DeviceList.SelectedIndex = -1;
            }
            catch (Exception ex)
            {
                txtUser.Text = ex.Message;
            }
        }

After additional scrutiny I found that the ID fields are different on a single digit within an 86 character string. 经过进一步的审查,我发现ID字段在86个字符串中的一位数字上有所不同。

\\\\?\\USB#VID_0416&PID_5011#5&3753427a&0& 5 #{86e0d1e0-8089-11d0-9ce4-08003e301f73} \\\\?\\ USB#VID_0416&PID_5011#5&3753427a&0& 5 #{86e0d1e0-8089-11d0-9ce4-08003e301f73}

VS VS

\\\\?\\USB#VID_0416&PID_5011#5&3753427a&0& 2 #{86e0d1e0-8089-11d0-9ce4-08003e301f73} \\\\?\\ USB#VID_0416&PID_5011#5&3753427a&0& 2 #{86e0d1e0-8089-11d0-9ce4-08003e301f73}

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM