Subject: write() to /dev/ttyb results in EIO
To: None <port-sparc@netbsd.org>
From: Christopher Forkin <chris@forkin.com>
List: port-sparc
Date: 02/05/2003 23:32:20
Hi guys,
I just must be missing something here, but can't seem to figure out
how to use termios.h correctly on NetBSD sparc. I have connected a modem
to the 2nd serial port on my sparcserver5 and can communicate with it
with tip without any issues at all. I have been sofar unsuccessfull
however in writing to it using the open() and write() system calls
(read() seems to work without a problem). Whenever I try to use write
I get errno=5 (EIO).
I have reduced the code as far as I could to the sample below and am
just surprised that this doesn't work on NetBSD (has no problems on
FreeBSD/386)? Terminal I/O is something new for me and I would appreciate
any help even if it means showing me where I have made a complete fool
of myself.
Chris.
-------------------<cut here>-------------------
#include <stdio.h>
#include <termios.h>
#include <fcntl.h>
#include <sys/errno.h>
#include <err.h>
#include <unistd.h>
int main(int argc, char **argv) {
int tty;
int ret;
struct termios term;
char buf[255];
ssize_t bytes;
if((tty=open(argv[1], O_RDWR|O_NOCTTY|O_NONBLOCK|O_APPEND))<0) {
err(1, "open(%s) failed", argv[1]);
}
if(tcgetattr(tty, &term)<0) {
err(2, "getattr() failed");
}
term.c_lflag &= ~ECHO; /* no echo */
term.c_cflag |= CS8; /* 8bit character size */
term.c_cflag &= ~CSTOP; /* 1 stop bit */
term.c_cflag &= ~PARENB; /* no parity */
term.c_cflag &= ~CLOCAL; /* no modem control */
if(cfsetspeed(&term, 9600)<0) {
err(3, "cfsetspeed() failed");
}
if(tcsetattr(tty, TCSANOW, &term)<0) {
err(4, "setattr() failed");
}
if((bytes=write(tty, "AT\r\n", 4))<0) {
err(5, "write() failed");
}
sleep(1);
if((bytes=read(tty, &buf, 255))<0) {
err(6, "read() failed");
}
buf[bytes]='\0';
printf(buf);
if((ret=close(tty))<0) {
err(7, "close() failed");
}
}
-------------------<cut here>-------------------
--
//------------------------------------------------------------//
// Email: chris@forkin.com //
// Postal: P.O.Box 106, Berowra Heights, NSW 2082, Australia //
//------------------------------------------------------------//