www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/01/12/04:06:11

Date: Tue, 12 Jan 1999 11:04:41 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Dan Hensley <dansherryn AT juno DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: How to open COM port in DJGPP?
In-Reply-To: <369A9A22.9AF7AB2A@juno.com>
Message-ID: <Pine.SUN.3.91.990112110417.15876S-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com

On Mon, 11 Jan 1999, Dan Hensley wrote:

>     How does DJGPP handle serial port access?

Like all DOS programs do: either through DOS, or through BIOS, or by
directly programming the 8250 UART chip.

> Specifically, how can I open a COM port?

DJGPP already opens the COM1 port for you: you can use the predefined
stream `stdaux' (it is defined in stdio.h).

> I need to use the open() function, and I've tried
> COM1, /dev/com1/, /dev/tty00, /dev/ttyS0, and /dev/cua0--none of them
> work.

The first two, COM1 and /dev/com1, should have worked.  What exactly
do you mean by ``none of them work''?  Did the call to `open' fail?
If so, how exactly did you call `open' (a code fragment would be nice)
and what was the failure code (errno value)?

>     I need to use open() because my code uses tcgetattr(), tcsetattr(),
> and select().

`select' will work, once you open the port, but `tcgetattr' and
`tcsetattr' won't.  The DJGPP implementation of termios is minimal and
currently only works for terminal devices.

You can add the missing functionality by using the DJGPP filesystem
extension feature.  This allows you to install a user-defined handler
for low-level library functions, like _open, _read, ioctl, etc., and
intercept any calls that reference special files or file handles.
Your handler then should call the appropriate device-specific code,
e.g. by using the bcserio or dzcomm package, to produce the same
effect as the termios call does on Unix.

Note that if you use some interrupt-driven package for the actual
communications, like the two packages mentioned above, you will
probably have to handle the read and write operations in your
filesystem extension as well, since the interrupt handler will steal
the characters and prevent DOS/BIOS from seeing them.

The filesystem extensions feature is described in the library
reference; type "info libc alpha 'File System'" from the DOS prompt
(the quotes around File System are important!).

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019