[fpc-pascal] How to detect serial/usb-serial ports.

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Thu Jul 28 19:33:04 CEST 2011


P. vanderWal wrote:
> ----- Original Message ----- From: "Mark Morgan Lloyd" 
> <markMLl.fpc-pascal at telemetry.co.uk>
> To: <fpc-pascal at lists.freepascal.org>
> Sent: Wednesday, July 27, 2011 10:36 PM
> Subject: Re: [fpc-pascal] How to detect serial/usb-serial ports.
> 
> 
>> P.vanderWal wrote:
>>> Debian and Ubuntu
>>>
>>> grtjs Piet
>>>
>>> ----- Original Message ----- From: "Felipe Monteiro de Carvalho" 
>>> <felipemonteiro.carvalho at gmail.com>
>>> To: "FPC-Pascal users discussions" <fpc-pascal at lists.freepascal.org>
>>> Sent: Wednesday, July 27, 2011 10:39 AM
>>> Subject: Re: [fpc-pascal] How to detect serial/usb-serial ports.
>>>
>>>
>>>> For which operating system?
>>
>> I'd expect (recent versions of) those to only create devices that were 
>> known to exist. I detect what's available by looking for up to 12 
>> /dev/ttyS*, 8 /dev/ttyUSB* and 4 /dev/ttyI*, then later checking that 
>> they can actually be opened (bearing in mind that this might glitch a 
>> control line).
>>
>> It's worth noting that a few weeks ago I was updating the standard 
>> serial.pp unit and noticed that Solaris designated serial ports as 
>> /dev/ttya and /dev/ttyb.
>>
>> Windows of course is \COM1, or strictly \\.\COM1 etc.; I note Fabio's 
>> test but in the past have used the registry to find e.g. named ports 
>> simulated by an AVR box.
>>
>> -- 
>> Mark Morgan Lloyd
>> markMLl .AT. telemetry.co .DOT. uk
>>
>> [Opinions above are the author's, not those of his employers or 
>> colleagues]
>> _______________________________________________
>> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
>> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> 
> I'll use Mark's method of com-port detection in my program under linux and
> GetComPorts under Windows. In a few days time I'll let you know the result.
> Mark thank for the suggestions.

I was discussing this elsewhere a few days ago and a Windows developer 
pointed out to me that the Windows COMn names are simply a convention, 
and that a driver writer can choose whatever he wants. A bit of Googling 
suggests that HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM is worth 
looking at, but I don't know how portable (i.e. over different versions 
and variants of Windows) that is.

Google also suggests that in some cases (Bluetooth?) the registry might 
append a garbage character, and that possibly reading it multiple times 
might improve things.

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]



More information about the fpc-pascal mailing list