Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-11

Portable way to enumerate serial ports?

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bo Berglund

Is there a way that one can use to list the actual serial ports available on a system that will work on both Windows and Linux? That is, is there a class/method or such already coded to give me a list of com ports when called?

The com ports are differently named in Windows and Linux, but it should be possible to get a list of ports actually available. But not using a listing of dev with ttys in the name, because I have found that in my test Linux systems there are always 4 of these even though there is only hardware for a single port...

Bo Berglund Developer in Sweden

Reply by email

Paul Breneman
to Bo Berglund
Bo Berglund wrote 11 lines
Is there a way that one can use to list the actual serial ports available on a system that will work on both Windows and Linux? That is, is there a class/method or such already coded to give me a list of com ports when called? The com ports are differently named in Windows and Linux, but it should be possible to get a list of ports actually available. But not using a listing of dev with ttys in the name, because I have found that in my test Linux systems there are always 4 of these even though there is only hardware for a single port...

I haven't found a very good way for Linux. I modified the SynaSer Linux code for the GetSerialPortNames function in the code on this page: http://www.turbocontrol.com/simpleserial.htm

Here is what I scan on Linux:
     ScanForPorts( '/dev/ttyS*');
     ScanForPorts( '/dev/ttyUSB*');
     ScanForPorts( '/dev/ttyAM*'); // for ARM board

Reply by email

Bo Berglund
to Paul Breneman
Paul Breneman wrote 21 lines
Bo Berglund wrote: > Is there a way that one can use to list the actual serial ports > available on a system that will work on both Windows and Linux? > That is, is there a class/method or such already coded to give me a > list of com ports when called? > > The com ports are differently named in Windows and Linux, but it > should be possible to get a list of ports actually available. > But not using a listing of dev with ttys in the name, because I have > found that in my test Linux systems there are always 4 of these even > though there is only hardware for a single port... > I haven't found a very good way for Linux. I modified the SynaSer Linux code for the GetSerialPortNames function in the code on this page: http://www.turbocontrol.com/simpleserial.htm Here is what I scan on Linux: ScanForPorts( '/dev/ttyS*'); ScanForPorts( '/dev/ttyUSB*'); ScanForPorts( '/dev/ttyAM*'); // for ARM board

Are com ports on ARM based embedded Linux named 'ttyAM1', 'ttyAM2' etc?

And how is the found "file" /dev/ttyS* verified as a real port? I have found that on UBUNTU Linux there are always 4 such "files" even though only one port actually exists.
/dev/ttyS1
/dev/ttyS2
/dev/ttyS3
/dev/ttyS4 (or possibly 0-1-2-3, can't remember right now)

Anyway I did get no communication at all using /dev/ttyS1, but when I switched to /dev/ttyS2 I could get a connection to a program on Windows. Mind you it was even possible to open the non-existing port....

Strange...

Bo Berglund Developer in Sweden

Reply by email

Sven Barth
to Bo Berglund
Bo Berglund wrote 27 lines
On Sat, 27 Nov 2010 08:12:53 -0600, Paul Breneman wrote: > Bo Berglund wrote: >> Is there a way that one can use to list the actual serial ports >> available on a system that will work on both Windows and Linux? >> That is, is there a class/method or such already coded to give me a >> list of com ports when called? >> >> The com ports are differently named in Windows and Linux, but it >> should be possible to get a list of ports actually available. >> But not using a listing of dev with ttys in the name, because I have >> found that in my test Linux systems there are always 4 of these even >> though there is only hardware for a single port... >> > > I haven't found a very good way for Linux. I modified the SynaSer Linux > code for the GetSerialPortNames function in the code on this page: > http://www.turbocontrol.com/simpleserial.htm > > Here is what I scan on Linux: > ScanForPorts( '/dev/ttyS*'); > ScanForPorts( '/dev/ttyUSB*'); > ScanForPorts( '/dev/ttyAM*'); // for ARM board Are com ports on ARM based embedded Linux named 'ttyAM1', 'ttyAM2' etc?

It depends on the driver which the port uses. Besides ttyS*, ttyUSB* and ttyAM* I've also found ttyAMA*, ttyPSC*, ttySAC*, ttyUL*... (but I can only use the ttyAM* ones on my ARM board... the others where created by a static /dev creation)

Regards,
Sven

Reply by email