C # SerialPort # Metoda Open () zgłasza ArgumentException z powodu nazwy portu?
Na mojej lokalnej maszynie
Windows XPPorty (COM i LPT)COM3RIM Virtual Serial Port v2 (COM4)RIM Virtual Serial Port v2 (COM5)następujący kod,
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();
}
}
}
rzuci następująceArgumentException
,
To jest,
Podana nazwa portu nie rozpoczyna się od COM / com lub nie jest rozpoznawana jako prawidłowy port szeregowy.
Czy ktoś wie, dlaczego tak się dzieje?