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

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

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

      2. C# SerialPort#Open() 方法由于端口名称而引发 ArgumentException?

        C# SerialPort#Open() method throws ArgumentException because of port name?(C# SerialPort#Open() 方法由于端口名称而引发 ArgumentException?)

        <tfoot id='nfvaI'></tfoot>

            <legend id='nfvaI'><style id='nfvaI'><dir id='nfvaI'><q id='nfvaI'></q></dir></style></legend>
            • <bdo id='nfvaI'></bdo><ul id='nfvaI'></ul>
              1. <small id='nfvaI'></small><noframes id='nfvaI'>

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

                  本文介绍了C# SerialPort#Open() 方法由于端口名称而引发 ArgumentException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在我的本地机器上,

                  • Windows XP
                  • 端口(COM 和 LPT)
                    • COM3
                    • RIM 虚拟串行端口 v2 (COM4)
                    • RIM 虚拟串行端口 v2 (COM5)

                    以下代码,

                    using System;
                    using System.Collections.Generic;
                    using System.Linq;
                    using System.Text;
                    using System.IO.Ports;
                    using System.Threading;
                    
                    namespace OpenSerialPortTest
                    {
                        class Test
                        {
                            static void Main(string[] args)
                            {
                                foreach (String serialPortName in SerialPort.GetPortNames())
                                {
                                    SerialPort serialPort = new SerialPort(serialPortName);
                                    try
                                    {
                                        serialPort.Open(); // Line 19
                                        Console.WriteLine(serialPort.PortName);
                                    }
                                    catch (Exception ex1)
                                    {
                                        Console.WriteLine(ex1);
                                        try
                                        {
                                            serialPort.Close();
                                        }
                                        catch (Exception ex2)
                                        {
                                            Console.WriteLine(ex2);   
                                        }
                                    }
                                }
                                Console.ReadLine();
                            }
                        }
                    }
                    

                    会抛出以下ArgumentException

                    也就是说,

                    给定的端口名称不以 COM/com 开头或不解析为一个有效的串口.

                    The given port name does not start with COM/com or does not resolve to a valid serial port.

                    有人知道为什么会这样吗?

                    Does anybody know why this is happening?

                    推荐答案

                    看看http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/35954173-2eeb-46af-bb3e-86840c6b5484

                    似乎问题在于那些 COM 端口被映射到其他东西并给出了这个奇怪的错误作为响应.

                    seems the problem was that those COM ports were mapped to something else and gives this strange error in response.

                    我遇到了完全相同的问题.我发现我有一个 Windows 打印机设置来使用相同的端口.一旦我更改了打印机设置中的端口,SerialPort.Open() 就起作用了.

                    I had exactly the same problem. I found that I had a windows printer setup to use the same port. As soon as I changed the port in the printers settings, the SerialPort.Open() worked.

                    这篇关于C# SerialPort#Open() 方法由于端口名称而引发 ArgumentException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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() 和泛型:错误绑定到目标方法)
                    <bdo id='PFj2a'></bdo><ul id='PFj2a'></ul>
                      <tbody id='PFj2a'></tbody>
                    <legend id='PFj2a'><style id='PFj2a'><dir id='PFj2a'><q id='PFj2a'></q></dir></style></legend>

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

                      1. <small id='PFj2a'></small><noframes id='PFj2a'>

                            <tfoot id='PFj2a'></tfoot>