Recent

Author Topic: detecting the Arduino serial port  (Read 254 times)

Rik

  • New Member
  • *
  • Posts: 25
detecting the Arduino serial port
« on: October 10, 2019, 03:16:39 pm »
Is there a way to detect the serial port (number) of an Arduino board?
For that I would need to know not only the number but also the "name" of the available serial ports, as shown in the Windows Device Manager (see attached image).
For numbers I can use the SerialPort.GetPortNames method, but how to get the names?

Thanks,

Rik

MarkMLl

  • Full Member
  • ***
  • Posts: 134
Re: detecting the Arduino serial port
« Reply #1 on: October 10, 2019, 03:34:36 pm »
Is there a way to detect the serial port (number) of an Arduino board?
For that I would need to know not only the number but also the "name" of the available serial ports, as shown in the Windows Device Manager (see attached image).
For numbers I can use the SerialPort.GetPortNames method, but how to get the names?

I can't speak for Windows, but for Linux there are various properties in the /sys tree which can be parsed with reasonable reliability to select a specified piece of hardware.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

avra

  • Hero Member
  • *****
  • Posts: 1685
    • Additional info
Re: detecting the Arduino serial port
« Reply #2 on: October 10, 2019, 04:14:44 pm »
On Windows you can try to use WMI to get list of all ports. One of the examples from the net uses:
Code: SQL  [Select]
  1. SELECT * FROM Win32_PnPEntity WHERE Name LIKE '%COM%'
You could check if that is sufficient or you need something else.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

MarkMLl

  • Full Member
  • ***
  • Posts: 134
Re: detecting the Arduino serial port
« Reply #3 on: October 10, 2019, 04:23:38 pm »
Although it might be necessary to look a bit more deeply than that. The things that I'm using (on Linux) is the name of the loaded driver and the chip name, in addition for /some/ hardware (FTDI) you can write a serial number to the interface chip which means that after that you can track which port it's on even if moved.
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7432

Cityalex

  • Newbie
  • Posts: 2
Re: detecting the Arduino serial port
« Reply #5 on: October 11, 2019, 05:00:52 am »
Really thank you That brought about such good stories to be spoken agai

Rik

  • New Member
  • *
  • Posts: 25
Re: detecting the Arduino serial port
« Reply #6 on: October 11, 2019, 04:45:32 pm »
Thanks to all for responding.
Meanwhile I found something more or less useful at http://patotech.blogspot.com/2012/04/enumerate-com-ports-in-windows-with.html
The function GetComPortList returns the friendly names, but it shows only the "real" serial ports, not the ones that go via USB such as the Arduino board.

Rik