<small id='je1IB'></small><noframes id='je1IB'>

  • <i id='je1IB'><tr id='je1IB'><dt id='je1IB'><q id='je1IB'><span id='je1IB'><b id='je1IB'><form id='je1IB'><ins id='je1IB'></ins><ul id='je1IB'></ul><sub id='je1IB'></sub></form><legend id='je1IB'></legend><bdo id='je1IB'><pre id='je1IB'><center id='je1IB'></center></pre></bdo></b><th id='je1IB'></th></span></q></dt></tr></i><div id='je1IB'><tfoot id='je1IB'></tfoot><dl id='je1IB'><fieldset id='je1IB'></fieldset></dl></div>
      <bdo id='je1IB'></bdo><ul id='je1IB'></ul>

      1. <tfoot id='je1IB'></tfoot>

      2. <legend id='je1IB'><style id='je1IB'><dir id='je1IB'><q id='je1IB'></q></dir></style></legend>

        获取 USB 适配器的 com 端口号

        时间:2023-11-10

          <tfoot id='sK1ww'></tfoot>
              <i id='sK1ww'><tr id='sK1ww'><dt id='sK1ww'><q id='sK1ww'><span id='sK1ww'><b id='sK1ww'><form id='sK1ww'><ins id='sK1ww'></ins><ul id='sK1ww'></ul><sub id='sK1ww'></sub></form><legend id='sK1ww'></legend><bdo id='sK1ww'><pre id='sK1ww'><center id='sK1ww'></center></pre></bdo></b><th id='sK1ww'></th></span></q></dt></tr></i><div id='sK1ww'><tfoot id='sK1ww'></tfoot><dl id='sK1ww'><fieldset id='sK1ww'></fieldset></dl></div>
                <legend id='sK1ww'><style id='sK1ww'><dir id='sK1ww'><q id='sK1ww'></q></dir></style></legend>

                <small id='sK1ww'></small><noframes id='sK1ww'>

                  <bdo id='sK1ww'></bdo><ul id='sK1ww'></ul>
                    <tbody id='sK1ww'></tbody>
                  本文介绍了获取 USB 适配器的 com 端口号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试编写一个使用 arduino mega 和基于 FTDI 的 USB 转 RS485 适配器的程序.

                  I am trying to write a program that uses an arduino mega and a FTDI-based USB to RS485 adapter.

                  我想让程序对用户友好,因此我不希望用户手动检查 com 端口号,但我想自动检测它.这是代码片段

                  I want to make the program user-friendly, thus I don't wont the user to manually check the com port number, but I want to auto-detect it. Here's a snippet of the code

                      ManagementScope scope = new ManagementScope();
                      SelectQuery query = new SelectQuery("SELECT * FROM Win32_SerialPort");
                      ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
                  
                      try
                      {
                          foreach (ManagementObject item in searcher.Get())
                          {
                              String description = item["Description"].ToString();
                              String deviceID = item["DeviceID"].ToString();
                  
                              Console.WriteLine("Porta " + description + " deviceID " + deviceID);
                  
                              if (description.Contains("USB Serial Port"))
                                  return deviceID;
                          }
                      }
                      catch (ManagementException)
                      {
                      }
                  

                  我无法理解的一点是为什么我可以找到 Arduino 的 USB 串行端口(匹配 description.Contains("Arduino") )但找不到 USB 的 com 端口RS485 接口.

                  The point that I am not able to understand is why I can find the USB Serial port of the Arduino (matching description.Contains("Arduino") ) but not the com port of the USB RS485 port.

                  您知道为什么会发生这种情况吗?查询 SELECT * FROM Win32_SerialPort 错了吗?

                  Do you have an idea why this could happen? is the query SELECT * FROM Win32_SerialPort wrong?

                  推荐答案

                  嗯,研究了几个论坛后,我发现如果我运行查询 SELECT * FROM 会列出与 USB/RS485 适配器关联的 com 端口Win32_PnPEntity .

                  Well, after studying several forums, I discovered that the com port associated to the USB/RS485 adapter is listed if I run the query SELECT * FROM Win32_PnPEntity .

                  但我真的不明白为什么 arduino 的串行端口由查询显示,而另一个端口与另一个查询显示......我的意思是,它们都是 uSB<-> 串行适配器!

                  But I really don't understand why the serial port of the arduino is shown by a query and the other port with the other query.... I mean, those are both uSB<->serial adapters!

                  这篇关于获取 USB 适配器的 com 端口号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在c#中创建多个线程 下一篇:同一台 Windows 机器上的串行端口通信不起作用

                  相关文章

                • <tfoot id='ZyvyP'></tfoot>

                    <bdo id='ZyvyP'></bdo><ul id='ZyvyP'></ul>

                    <small id='ZyvyP'></small><noframes id='ZyvyP'>

                    <i id='ZyvyP'><tr id='ZyvyP'><dt id='ZyvyP'><q id='ZyvyP'><span id='ZyvyP'><b id='ZyvyP'><form id='ZyvyP'><ins id='ZyvyP'></ins><ul id='ZyvyP'></ul><sub id='ZyvyP'></sub></form><legend id='ZyvyP'></legend><bdo id='ZyvyP'><pre id='ZyvyP'><center id='ZyvyP'></center></pre></bdo></b><th id='ZyvyP'></th></span></q></dt></tr></i><div id='ZyvyP'><tfoot id='ZyvyP'></tfoot><dl id='ZyvyP'><fieldset id='ZyvyP'></fieldset></dl></div>

                      <legend id='ZyvyP'><style id='ZyvyP'><dir id='ZyvyP'><q id='ZyvyP'></q></dir></style></legend>