Subject: Re: Serial port programming problem/question
To: Leif Lindholm <leif@smurfnet.nu>
From: Herb Peyerl <hpeyerl@beer.org>
List: netbsd-users
Date: 01/07/2005 08:02:41
On Jan 7, 2005, at 7:31 AM, Leif Lindholm wrote:
> My first problem is that the open("/dev/tty00") call never returns
> unless I use O_NONBLOCK.
> My second is that if I use O_NONBLOCK, the select() call always return
> and the FD_ISSET() shows that there is data available - but the read()
> doesn't return any data.
>
> I get the output just fine when using minicom/kermit on the NetBSD, so
> there shoudn't be anything else blocking the port.
>
> Which serial device should I be using - tty00 or dty00 (or some other)?
>
> Does anyone have some sample code I could use for reference?
>
> Am I missing something obvious?

Yes. You have a cabling problem.

Opening a serial device will normally block unless certain hardware 
handshaking signals are asserted.  The culprit is usually DCD.  You can 
override this behavior using 'ttyflags'.  I'm not familiar with more 
recent changes in the naming convention of certain rs232 devices in 
/dev so their behavior may be different in this regard but reading 
dty(4) seems to provide some of the information you're looking for.

It should also be noted that there are many different things that are 
sold as "null modem" cables/adapters... I once collected and enumerated 
12 different combinations of pinouts that were all sold as "null modem" 
cables/adapters.  So if what you're trying to do is connect 2 PC's, 
then you should be wary of your null-modem cable.    Personally, I keep 
a stash of old "Laplink" cables handy.  They seem to have the correct 
pinout and they're extra handy because they generally have both a DB9F 
and a DB25F on both ends.

Solve the problem at the electrical level unless you're only working on 
a quick hack.  All those signals on the RS232 port are there for a 
reason.  Learn to use them correctly.