(revised) test for linux serial ports


Author Message
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2541
Posted: 02:31pm 24 Dec 2024      

here is a further evolved test version:

ports2 (inc source).zip

again, this is a 64-bit LINUX CONSOLE program with no versioned GLIBC symbols - so it should run on pretty much anything.


this time the checking method employed is to:

- search through /dev/class/tty/* to get our initial list of potential serial ports. this means we should now also pick up any rfcomm* bluetooth devices.

- perform an 'access' syscall on the corresponding /dev entry to check that a) the entry exists there, and b) we have the necessary permissions to access it as a serial device - one result of this is that if we are not a member of dialout then no ports are returned no matter what - i see this as a good thing.

- make sure the driver path /sys/class/tty/DeviceName/device/driver exists. we no longer need to do any expansion of symlinks or checking of the driver's name.

- check for the existence of the pseudo-file /sys/class/tty/DeviceName/type to distinguish between fixed (.../type file exists) and removable (no .../type file found) serial devices. note: we do not need to actually read the .../type file.

- if .../type exists then we further perform an ioctl/TCGETS call - if the call fails we know the fixed port does not exist.


it would be very much appreciated if folks could check that sensible output is produced, preferably on machines that have one or two fixed serial ports. i'd also be really interested in hearing back if bluetooth serial ports (rfcomm*) are successfully detected.

Jim: the source code is now much easier to follow - if anyone has complained about mmedit finding phantom ttyS* ports, or missing rfcomm* ports, then it it may be worth looking at incorporating this detection method into mmedit.


cheers,
rob   :-)