Shamim Hafiz - MSFT
Shamim Hafiz - MSFT

Reputation: 22094

Mysterious error message "The port 'COM1' does not exist"

I am getting the following error message when trying to access devices connected by USB port.

The port 'COM1' does not exist

By looking into device manager, I am certain that the device has been assigned COM1 and no other device is attached to COM1. Why would this behavior occur?

Is this environment dependent, because the same version of the App doesn't produce this message when executed in a different system.

Upvotes: 4

Views: 17747

Answers (3)

Ashokan Sivapragasam
Ashokan Sivapragasam

Reputation: 2189

Source: MsdnLink

I figured out problem and answer. We need to get name of the port where drivers for Arduino is installed on your machine. Not all Arduino is getting installed on 'COM1' port. My Arduino Mega 2560 R3 was installed on port, 'COM3'

Paste the code in C# Main() function,

var serialPort = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One);
 try
 {
     while (true)
     {
         serialPort.ReadTimeout = 2000;
         if (!serialPort.IsOpen) serialPort.Open();
         int readData = serialPort.ReadByte();
         Console.Write((char)readData);
     }
 }
 catch (Exception ex)  // Press CTRL-C to exit.
 {
     Console.WriteLine(ex.Message);
     Console.ReadKey();
 }
 serialPort.Close();

Steps to find the port name:

  1. Start > Run > devmgmt.msc
  2. Expand the node called, 'Port (COM & LPT)'
  3. You find the name of the port for your Arduino device.

Upvotes: 0

Shamim Hafiz - MSFT
Shamim Hafiz - MSFT

Reputation: 22094

My case is a very specific one.

What was happening is, there was a device that was previously connected. When it's removed, the Object making the connection was still holding on to the port. Now, when a new device was inserted, although a search for that device revealed that it was in COM1, but trying to open it caused this exception as the previous and still live object was holding on to the port.

Upvotes: 2

Oliver
Oliver

Reputation: 45101

Currently i don't know what exactly .Net wants, but back in the old C/C++ days you had to open COM1: (take care for the colon after the port name).

Upvotes: 0

Related Questions