<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 端口?

      How to find available COM ports?(如何找到可用的 COM 端口?)
        • <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 端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
                Parameter count mismatch with Invoke?(参数计数与调用不匹配?)
                How to store delegates in a List(如何将代表存储在列表中)
                How delegates work (in the background)?(代表如何工作(在后台)?)
                C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)
                Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)
              • <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>
                        <tbody id='Wp2Lg'></tbody>
                    1. <small id='Wp2Lg'></small><noframes id='Wp2Lg'>