[Prev][Next][Index][Thread]

Re: how can I select a serial port?



> From: Naomaru Itoi <itoi@eecs.umich.edu>
> Subject: how can I select a serial port?
> 
> I am porting a serial port access library in OpenBSD to OSKit-0.97.
> So far I am successful, I basically replaced UNIX syscalls on
> /dev/tty** with functions on ttystream in OSKit (in libfreebsd_dev.a),
> e.g., 
> 
>    open("/dev/tty01", O_RDWR, 0)
> => oskit_ttydev_open(ttydev[1], OSKIT_O_RDWR, &ttystrm)
> 
> However, I am stuck with porting the select() syscall.  select()
> selects a set of file descriptors.  In OSKit, ttystream I open does
> not have a file descriptor (because it is not a file!), so I cannot
> use select() on it.  Is there any internal function to select
> ttystreams in OSKit?  Or should I write a new one with ioctl()?  Or
> can I open a serial port as a file? 

The way the oskit's FreeBSD C library is constructed, it is very easy
to "open" a serial port as a file, although not in the classic unix
sense.

Oskit interfaces like oskit_file and oskit_ttydev are mapped to POSIX
file descriptors using a very simple table-driven approach. At
present, this is not really exported, but its simple enough to take
advantage of. A fragment of code based on the POSIX open routine:

	#include <oskit/c/fd.h>

        fd = fd_alloc((oskit_iunknown_t*)ttystrm, 0);
	if (fd < 0) {
		/* something went wrong ... */
	}

With that done, you can use the POSIX "select" function (be sure to
compile and link against the FreeBSD C library, and not the minimal C
library). Other POSIX functions like read, close, etc., will all work
as expected.

In the future, the oskit might include a more general purpose
interface to support this, but in the meantime this should work just
fine.

Hope this helps.

Lbs

---------------------------------------------------------------------------
Leigh B. Stoller                     Computer Science - Flux Research Group
stoller@cs.utah.edu                  University of Utah
http://www.cs.utah.edu/~stoller      Salt Lake City, Utah 84112
Voice: (813) 899-9296                FAX: (801) 585-3743
---------------------------------------------------------------------------
=================================
To subscribe or unsubscribe, send mail with "subscribe" or "unsubscribe"
to oskit-users-request@flux.cs.utah.edu.  The oskit-announce list is low
volume - if you want to subscribe, mail oskit-announce-request@flux.cs.utah.edu