0

I'm trying to send bytes down COM1, which has a printer attached to it.

I have the following:

foreach (var portName in SerialPort.GetPortNames())
{
    WriteLine(portName);
}
var mPort = new SerialPort();
if (mPort.IsOpen)
    mPort.Close();
mPort.PortName = "COM1";
mPort.Open();

"COM1" is returned by SerialPort.GetPortNames, however, when I get to the mPort.Open() line I get an ArgumentException:

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

BanksySan
  • 27,362
  • 33
  • 117
  • 216
  • 1
    How is it connected? Do you have a RS232 port on your PC? Or are you using USB to serial? – Baddack Feb 27 '18 at 18:03
  • @Baddack It's connected directly. – BanksySan Feb 28 '18 at 12:33
  • `COM1` is generally reserved for the physical serial port on your PC. If you don't have a serial port on your PC then I suspect that `COM1` isn't what you want. If you are connected to the PC via USB, then you probably need drivers from the vendor. Once you have the drivers installed it will show up as a different `COM #`. – Baddack Feb 28 '18 at 16:56
  • https://stackoverflow.com/questions/11605429/c-sharp-serialportopen-method-throws-argumentexception-because-of-port-name – Jim Hewitt Feb 28 '18 at 23:28

0 Answers0