Thread (4 messages) 4 messages, 3 authors, 2004-08-26

Re: How to get a list of all available serial ports?

From: Jan-Benedict Glaw <jbglaw@lug-owl.de>
Date: 2004-08-26 10:51:31

On Thu, 2004-08-26 09:24:02 +0200, Francisco M. Marzoa Alonso [off-list ref]
wrote in message [ref]:
Under Windows my program is able to perform an autodetection of the device 
with which it work. For that it takes a list of all available serial ports 
from Windows registry. 

Is there any manner to do the same under LiNUX that works on all 
distributions?
There are several solutions:

- opendir()/readdir()/closedir() "/dev/" and strncmp(ent->d_name, "ttyS", 4),
  then open all matches with O_NONBLOCK to see if you not get ENODEV
  from errno. This works on "traditional" systems not using something
  like devfs. Also, you'd better stat() all hits to not get false
  positives from things like symlinks.
- opendir/readdir/closedir "/dev/ttyS/" and iterate through all entries.
  These are solely serial ports, so not that much postprocessing
  involved. However, that would only work with devfs...
- open /proc/tty/driver/serial, check the format (first line), read all
  further lines and check if uart is != "unknown".

For sure, there are more techniques, like
	- if you're runnung with root privileges, you'd temporarily
	  create new device nodes for char devices, and mojor/minor
	  number from /proc/tty/drivers (the "^serial" lines).
	- check major/minor from /sys/class/tty/ttyS* (open() checking
	  for ENODEV in errno...), but that'd require creating temporary
	  device nodes and also having a 2.6.x kernel...

Personally, I don't like software that tries to "know better" than I do.
I'd like telling a program "use this device node and shut up!" and
possibly others would like to have it work that way, too...

MfG, JBG

-- 
Jan-Benedict Glaw       jbglaw@lug-owl.de    . +49-172-7608481             _ O _
"Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg  _ _ O
 fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!   O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help