How to fix the com number for arduino-pc connection?

I try to make arduino a data collect adapter and have it connect to a PC (windows) via usb ports. But when I plugged it into another usb port of the PC or/and use another arduino board, usually the com number shown in the PC changed.

I plan to write my own PC program (python, matlab or labview) to collect the data from this arduino. Is there a way to fix this com number, so everytime when I plug it in, the PC program can correctly identify this device and connect to it.

what I do is a scan of COM ports opening each in turn sending a prompt command, e.g. ?, which the correct target replies with a known string, e.g. Weather_Station.

this C# code searches for a modem attached to a COM port, e.g. send AT command and waits for an OK response

       public Form1()
        {
            InitializeComponent();
			// scan for COM ports and add to menu item if found
			for(int port = 0; port <= 10; port++)
				{
				serialPort1.PortName = "COM" + port.ToString();
				try
					{
					serialPort1.Open();			// attempt to open serial port
					serialPort1.BaudRate=115200;			
					textBox1.AppendText("Found " + serialPort1.PortName + "\n");
					Console.WriteLine("serial port open OK {0}", serialPort1.PortName);
					serialPort1.Write("AT\r\n"); 
                        Thread.Sleep(100);                         
                        String response = serialPort1.ReadExisting();                                                
                           Console.WriteLine("response " +  response);
                        if (response.Contains( "OK"))
                        {
                           Console.WriteLine("Fastrack XTEND modem found");
                        }
					serialPort1.Close() ;														//open OK, close it
					ToolStripMenuItem item = new ToolStripMenuItem(serialPort1.PortName);	// create a new menu item
                    item.Click += comPortsStripMenuItem_Click;	// add event handler
                    comPortsStripMenuItem.DropDownItems.Add(item);	// add to the menu of COM ports
 					}
				catch ( Exception ex)
					{ Console.WriteLine("serial port open fail {0} ", serialPort1.PortName, ex); }
			}

        Console.WriteLine("COM ports found {0} ", comPortsStripMenuItem.DropDownItems.Count);
		textBox1.AppendText(String.Format("{0} COM ports found - select from COM ports menu\r\n\r\n", comPortsStripMenuItem.DropDownItems.Count));
        // if no COM ports were found display message
        if(comPortsStripMenuItem.DropDownItems.Count == 0 )
           textBox1.AppendText("No COM ports found\r\n");
        }

Good idea and thanks. In case I have multiple usb devices, could the host program identify these devices?

What do the devices such as my mouse and usb camera does? Does the HID standard work for me on this?

which language are you using?
e.g. for C# a web search for c# get usb device list gives plenty of links

I prefer to use labview, if it is not available, then python...

don't know Labview - try their forum
for Python have a look at retrieve-list-of-usb-items-using-python

@joedodo Are you and @oliverjames07207 working on the same project because you have both posted remarkably similar topics

See https://forum.arduino.cc/review?sort_order=score

Plug the same board into the same usb port each time and it will get the same COM port number.

You can change them in Device Manager -> Ports (COM & LPT) -> [The device] -> Port Settings -> Advanced..., but that applies only to that particular USB to serial chipset (CP210x, CH340, etc) on that particular port. (If you plug an Arduino Nano into a port, then remove it and plug in another Nano, they will both have the same COM port. Windows is relatively dumb when it comes to identifying different generic devices - that's why when you plug a printer/keyboard/mouse/joystick/thumb drive into a different port it does the whole add new hardware crap again - it thinks it's a completely new device. A client's computer had 5 copies of the same printer driver because of this, and he never knew which one to print to.)

I don't know what happened. I thought someone helped me to post it in the right section, but... maybe this oliverjames07207 is another me from one of the parallel universes...

The other topic has been locked but be aware that the moderators are keeping an eye on what is going on

If you are found to have infringed the forum rules you run the risk of being suspended

PM me if you have anything to tell me

you should know what's the reality... come clean to the moderator in PM.

I really don't know what happened ....

Is it possible to use HID mode or follow the HID standard so that it is easier for PC program part to identify the device?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.