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

Re: Help serial port communication



"Jens B. Jorgensen" <jjorgens@bdsinc.com> writes:

> Carey Evans wrote:

[...]

> > I think it's generally necessary to do  O_RDWR|O_NONBLOCK  to open a
> > disconnected serial port, then set CLOCAL with termios, and finally
> > turn off O_NONBLOCK with fcntl.  Of course, for just setting the speed
> > it should be enough to change the open().
> 
> Oh really? You need O_NONBLOCK eh? Why don't you put your compiler where your speculation is and
> compile/run the attached program.

OK.  I had to make one small change because I don't have a ttyS0, but
I do have a modem on ttyS1.

% make testsp
cc     testsp.c   -o testsp
% strace ./testsp
execve("./testsp", ["./testsp"], [/* 31 vars */]) = 0
    ...
open("/dev/ttyS1", O_RDWR

It stops at this point, with "TR" lit on my modem.  If I happened to
have my modem set to auto-answer, and something connected, *then* the
open() would complete.

If I already had something on there that had set CLOCAL, like mgetty,
it would have run through.  BTW:

% strace ./testsp2
    ...
open("/dev/ttyS1", O_RDWR|O_NONBLOCK)   = 3
ioctl(3, TCGETS, {0x1002 /* B??? */ -opost -isig -icanon -echo ...}) = 0
ioctl(3, SNDCTL_TMR_START, {B9600 -opost -isig -icanon -echo ...}) = 0
close(3)                                = 0
_exit(0)                                = ?

-- 
	 Carey Evans  http://home.clear.net.nz/pages/c.evans/

	  GNU GPL: "The Source will be with you... always."


--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-user-request@lists.debian.org . 
Trouble?  e-mail to templin@bucknell.edu .


Reply to: