2017-07-27 164 views
0

UWP应用程序,要与串行设备(如COM3)连接,我成功获取所有可用的设备列表以下代码。但有一点很奇怪。我的设备没有VID,没有PID。UWP SerialDevice:我的设备坏了吗?无法连接Vid,Pid

USB-RS485 convertor

  1. 首先,我用 “GetDeviceSelector”,我能找到我的串行设备。并且,我得到了这个字符串“\?\ FTDIBUS#VID_0403 + PID_6001 + AL03INW7A#0000#{86e0d1e0-8089-11d0-9ce4-08003e301f73}”然后我知道我的设备有Vid = 0x0403,Pid = 0x6001。
  2. Next如果我使用“GetDeviceSelectorFromUsbVidPid(0x0403,0x6001)”。 UWP找不到我的设备...

为什么?

首先是测试代码。

public MainPage()                             
     {                               
      this.InitializeComponent();                        

      Task.Run(() => this.test()).Wait();                      

     }                               

     public async Task test()                         
     {                               
      try                              
      {                              
       // Not Work                           
       // var DeviceSelector = SerialDevice.GetDeviceSelectorFromUsbVidPid(0x0403, 0x6001); //        

       // Work                            
       var DeviceSelector = SerialDevice.GetDeviceSelector();               
       var DeviceInformations = await DeviceInformation.FindAllAsync(DeviceSelector);          

       for (int i = 0; i < DeviceInformations.Count; i++)                 
       {                             
        var d = DeviceInformations[i];                     
        SerialDevice port = await SerialDevice.FromIdAsync(d.Id);              

        Debug.WriteLine(String.Format("{0}\n{1}\n{2}\n{3}\n{4}\n{5}\n---------------------",       
         d.Name,                          
         d.Id,                          
         d.IsEnabled,                        
         port?.PortName,                        
         port?.UsbProductId.ToString("X4"),                    
         port?.UsbVendorId.ToString("X4")                    
         ));                           


       }                             
      }                              
      catch (Exception ex)                         
      {                              
       Debug.WriteLine("SerialController/ListAvailablePorts/Exception/" + ex.Message);          
      }                              

      return;                             
     }                               

Package.appxmanifest也必须这样做。

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

以下是GetDeviceSelector的结果。

FT232R USB UART 
\\?\FTDIBUS#VID_0403+PID_6001+AL03INW7A#0000#{86e0d1e0-8089-11d0-9ce4-08003e301f73} 
True 
COM12 
0000 
0000 

查看最后两个零值。 VID,PID看起来像零。哪里不对 ?

UPDATE1

与Sunteen吴的建议(谢谢),我尝试使用其他设备。下一个设备是RS232-USB设备。这两个设备都是虚拟COM端口。我尝试了相同的代码。第二个设备有Vid,Pid!嗯.....我的设备是错误的.....

ATEN USB to Serial Bridge (COM13) 
\\?\USB#VID_0557&PID_2008#8&1d38065f&1&4#{86e0d1e0-8089-11d0-9ce4-08003e301f73} 
System.Runtime.InteropServices.WindowsRuntime.ReadOnlyDictionaryValueCollection`2[System.String,System.Object] 
COM13 
2008 
0557 

enter image description here

+0

我能知道什么是你的设备你有测试其他设备? ? –

+0

我在这里买了设备。(http://www.usconverters.com/usb-to-rs485-converter-iu100)...我将在稍后测试另一个设备.... –

+0

我尝试了另一个设备。有虚拟COM端口。第二个设备有Vid,PId!..hmm ....我向制造商请求这个。我的第一个设备是FTDI。是否有自己设置Vid,Pid ...?无论如何,谢谢。 ... –

回答

0

这是我的设备发生故障。我报告要制造。我希望他们会加上Vid,Pid的未来。 关于详情,请阅读我的问题中的“更新”。

购买之前,有没有办法知道它...。(

我喜欢他们的产品这是非常好的