public inbox for linux-serial@vger.kernel.org
 help / color / mirror / Atom feed
From: Jan-Benedict Glaw <jbglaw@lug-owl.de>
To: linux-serial@vger.kernel.org
Subject: Re: How to get a list of all available serial ports?
Date: Thu, 26 Aug 2004 12:51:30 +0200	[thread overview]
Message-ID: <20040826105130.GN18334@lug-owl.de> (raw)
In-Reply-To: <200408260924.02123.fmmarzoa@softronica.org>

[-- Attachment #1: Type: text/plain, Size: 2068 bytes --]

On Thu, 2004-08-26 09:24:02 +0200, Francisco M. Marzoa Alonso <fmmarzoa@softronica.org>
wrote in message <200408260924.02123.fmmarzoa@softronica.org>:
> 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));

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

  reply	other threads:[~2004-08-26 10:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-26  7:24 How to get a list of all available serial ports? Francisco M. Marzoa Alonso
2004-08-26 10:51 ` Jan-Benedict Glaw [this message]
2004-08-26 10:52 ` Salomon, Frank
2004-08-26 12:09   ` Jan-Benedict Glaw

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040826105130.GN18334@lug-owl.de \
    --to=jbglaw@lug-owl.de \
    --cc=linux-serial@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox