• <bdo id='3A375'></bdo><ul id='3A375'></ul>
    <tfoot id='3A375'></tfoot>

    <small id='3A375'></small><noframes id='3A375'>

    <legend id='3A375'><style id='3A375'><dir id='3A375'><q id='3A375'></q></dir></style></legend>

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

      1. C# 检查 COM(串行)端口是否已打开

        时间:2023-11-10
        <i id='lb6N0'><tr id='lb6N0'><dt id='lb6N0'><q id='lb6N0'><span id='lb6N0'><b id='lb6N0'><form id='lb6N0'><ins id='lb6N0'></ins><ul id='lb6N0'></ul><sub id='lb6N0'></sub></form><legend id='lb6N0'></legend><bdo id='lb6N0'><pre id='lb6N0'><center id='lb6N0'></center></pre></bdo></b><th id='lb6N0'></th></span></q></dt></tr></i><div id='lb6N0'><tfoot id='lb6N0'></tfoot><dl id='lb6N0'><fieldset id='lb6N0'></fieldset></dl></div>
          <bdo id='lb6N0'></bdo><ul id='lb6N0'></ul>

                <legend id='lb6N0'><style id='lb6N0'><dir id='lb6N0'><q id='lb6N0'></q></dir></style></legend>
                  <tfoot id='lb6N0'></tfoot>

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

                    <tbody id='lb6N0'></tbody>
                • 本文介绍了C# 检查 COM(串行)端口是否已打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  是否有一种简单的方法可以以编程方式检查串行 COM 端口是否已打开/正在使用?

                  Is there an easy way of programmatically checking if a serial COM port is already open/being used?

                  通常我会使用:

                  try
                  {
                      // open port
                  }
                  catch (Exception ex)
                  {
                      // handle the exception
                  }
                  

                  但是,我想以编程方式进行检查,以便尝试使用其他 COM 端口或类似的端口.

                  However, I would like to programatically check so I can attempt to use another COM port or some such.

                  推荐答案

                  前段时间我需要类似的东西来搜索设备.

                  I needed something similar some time ago, to search for a device.

                  我获得了可用 COM 端口的列表,然后简单地迭代它们,如果它没有引发异常,我尝试与设备通信.有点粗糙但工作.

                  I obtained a list of available COM ports and then simply iterated over them, if it didn't throw an exception i tried to communicate with the device. A bit rough but working.

                  var portNames = SerialPort.GetPortNames();
                  
                  foreach(var port in portNames) {
                      //Try for every portName and break on the first working
                  }
                  

                  这篇关于C# 检查 COM(串行)端口是否已打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:检测串口插入/移除 下一篇:如何显示在串口的 DataReceived 事件处理程序中读取的数据

                  相关文章

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

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

                      <tfoot id='caMoz'></tfoot>