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

    <bdo id='QeNZt'></bdo><ul id='QeNZt'></ul>
  1. <small id='QeNZt'></small><noframes id='QeNZt'>

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

      如何找到可用的 COM 端口?

      时间:2023-11-10
        • <legend id='Wp1LR'><style id='Wp1LR'><dir id='Wp1LR'><q id='Wp1LR'></q></dir></style></legend>
            <tbody id='Wp1LR'></tbody>

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

          1. <tfoot id='Wp1LR'></tfoot>
            <i id='Wp1LR'><tr id='Wp1LR'><dt id='Wp1LR'><q id='Wp1LR'><span id='Wp1LR'><b id='Wp1LR'><form id='Wp1LR'><ins id='Wp1LR'></ins><ul id='Wp1LR'></ul><sub id='Wp1LR'></sub></form><legend id='Wp1LR'></legend><bdo id='Wp1LR'><pre id='Wp1LR'><center id='Wp1LR'></center></pre></bdo></b><th id='Wp1LR'></th></span></q></dt></tr></i><div id='Wp1LR'><tfoot id='Wp1LR'></tfoot><dl id='Wp1LR'><fieldset id='Wp1LR'></fieldset></dl></div>
              • <bdo id='Wp1LR'></bdo><ul id='Wp1LR'></ul>
              • 本文介绍了如何找到可用的 COM 端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                如何在我的 PC 中找到可用的 COM 端口?我正在使用框架 v1.1.是否可以找到所有 COM 端口?如果可能,请帮我解决问题.

                How to find available COM ports in my PC? I am using framework v1.1. Is it possible to find all COM ports? If possible, help me solve the problem.

                推荐答案

                正如其他人建议的那样,您可以使用 WMI.您可以找到示例 在 CodeProject 中

                As others suggested, you can use WMI. You can find a sample in CodeProject

                try
                {
                    ManagementObjectSearcher searcher =
                        new ManagementObjectSearcher("root\WMI",
                        "SELECT * FROM MSSerial_PortName");
                
                    foreach (ManagementObject queryObj in searcher.Get())
                    {
                        Console.WriteLine("-----------------------------------");
                        Console.WriteLine("MSSerial_PortName instance");
                        Console.WriteLine("-----------------------------------");
                        Console.WriteLine("InstanceName: {0}", queryObj["InstanceName"]);
                
                        Console.WriteLine("-----------------------------------");
                        Console.WriteLine("MSSerial_PortName instance");
                        Console.WriteLine("-----------------------------------");
                        Console.WriteLine("PortName: {0}", queryObj["PortName"]);
                
                        //If the serial port's instance name contains USB 
                        //it must be a USB to serial device
                        if (queryObj["InstanceName"].ToString().Contains("USB"))
                        {
                            Console.WriteLine(queryObj["PortName"] + " 
                            is a USB to SERIAL adapter/converter");
                        }
                    }
                }
                catch (ManagementException e)
                {
                    Console.WriteLine("An error occurred while querying for WMI data: " + e.Message);
                } 
                

                这篇关于如何找到可用的 COM 端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:数据到来时C#只读串口 下一篇:从串口解析/格式化数据 - C#

                相关文章

              • <i id='Wp2Lg'><tr id='Wp2Lg'><dt id='Wp2Lg'><q id='Wp2Lg'><span id='Wp2Lg'><b id='Wp2Lg'><form id='Wp2Lg'><ins id='Wp2Lg'></ins><ul id='Wp2Lg'></ul><sub id='Wp2Lg'></sub></form><legend id='Wp2Lg'></legend><bdo id='Wp2Lg'><pre id='Wp2Lg'><center id='Wp2Lg'></center></pre></bdo></b><th id='Wp2Lg'></th></span></q></dt></tr></i><div id='Wp2Lg'><tfoot id='Wp2Lg'></tfoot><dl id='Wp2Lg'><fieldset id='Wp2Lg'></fieldset></dl></div>
                <tfoot id='Wp2Lg'></tfoot>
              • <legend id='Wp2Lg'><style id='Wp2Lg'><dir id='Wp2Lg'><q id='Wp2Lg'></q></dir></style></legend>
                • <bdo id='Wp2Lg'></bdo><ul id='Wp2Lg'></ul>
                1. <small id='Wp2Lg'></small><noframes id='Wp2Lg'>