Recent

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

Rik

  • Jr. Member
  • **
  • Posts: 72
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

  • Hero Member
  • *****
  • Posts: 6686
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
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

avra

  • Hero Member
  • *****
  • Posts: 2514
    • 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

  • Hero Member
  • *****
  • Posts: 6686
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.
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11453
  • FPC developer.

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

  • Jr. Member
  • **
  • Posts: 72
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

 

TinyPortal © 2005-2018