delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2004/12/28/15:09:54

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
Date: Tue, 28 Dec 2004 22:06:42 +0200
From: "Eli Zaretskii" <eliz AT gnu DOT org>
Sender: halo1 AT zahav DOT net DOT il
To: djgpp AT delorie DOT com
Message-ID: <01c4ed18$Blat.v2.2.2$e56647a0@zahav.net.il>
X-Mailer: emacs 21.3.50 (via feedmail 8 I) and Blat ver 2.2.2
In-reply-to: <Xns95CDC7F0584F6serialport@62.81.237.233> (message from chus on
Tue, 28 Dec 2004 18:51:14 GMT)
Subject: Re: serial port interaction
References: <Xns95CDC7F0584F6serialport AT 62 DOT 81 DOT 237 DOT 233>
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> From: chus <chus73 AT undominio DOT es>
> Date: Tue, 28 Dec 2004 18:51:14 GMT
> 
> I am porting linux C codes to DJGPP/windows. Migration has not been very 
> difficult except for one of the modules that reads/writes from/to serial 
> port (/dev/ttyS* -> COM*). Linux version opens the port (fd = 
> open("/dev/ttyS0") and then use read() and write() to receive and send 
> data.
> 
> I rewrote open, send and receive functions using bioscom(...). Opening and 
> writing functions work fine, however reading justs gets the last character 
> received by the serial port.

Why did you need to go to bioscom?  The serial port device is already
open when the DJGPP program starts (and it's open correctly in binary
mode), and can be read and written with DOS functions as usual.  That
is, just omitting the `open' call from the original code and instead
assigning the value 3 to fd should have worked.

One possible caveat about reading the serial device is that you need
to read each character as soon as it is ready, since there's no
buffering at the UART level: each received character replaces the
previous one.  If your program gets to the next `read' call after a
significant delay, it could miss some characters.

Also note that Unix programs might fiddle with the serial device's
settings via the termios functions.  If that is the case with the
program you are porting, you will need to replace that code with
direct programming of the UART, since the DJGPP implementation of
termios supports only the console device.

If the above doesn't help, please post more specific questions.

- Raw text -


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