Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.bhp.com.au!mel.dit.csiro.au!munnari.OZ.AU!news.ecn.uoknor.edu!news.uoknor.edu!news.nodak.edu!netnews1.nwnet.net!news.u.washington.edu!uw-beaver!uhog.mit.edu!news.mathworks.com!tank.news.pipex.net!pipex!demon!arg-home.net-tel.co.uk
From: Andrew Gordon <andrew.gordon@net-tel.co.uk>
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: Some kind of trouble with reading /dev/cuaa?
Date: Fri, 02 Feb 1996 00:00:06 GMT
Lines: 115
Message-ID: <823219206.15342@arg-home.net-tel.co.uk>
References: <4eqci1$n66@bilbo.nask.org.pl>
NNTP-Posting-Host: arg-home.net-tel.co.uk
X-NNTP-Posting-Host: arg-home.net-tel.co.uk
X-Mailer: Mozilla 1.1N (X11; I; BSD/386 uname failed)
MIME-Version: 1.0
To: jarekb@pap.waw.pl
X-URL: file:/home/arg/term.c
Content-Type: multipart/mixed;
boundary="-------------------------------9616503751178269702599720673"
This is a multi-part message in MIME format.
---------------------------------9616503751178269702599720673
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=us-ascii
jarekb@pap.waw.pl (Jaroslaw Bazydlo) wrote:
>A Few days I go I replaced a direct connection with a modem line and it
>stopped working ;-(. What I have to do first is to set 1200 8N1 parameters of
>my port. This is my script (a modified part of rc.serial):
I expect your problem relates to waiting for carrier detect or CTS, but I can't
readily tell from the info you've given. Try reading the termios man page, and
looking at the enclosed example code.
---------------------------------9616503751178269702599720673
Content-Transfer-Encoding: 7bit
Content-Type: text/plain
#include <stdio.h>
#include <sys/uio.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
/*
Simple dumb terminal example program
*/
int main(int argc, char **argv)
{
int serial_fd;
char *portname;
struct termios term;
struct termios saved_term;
fd_set fd_map;
if (argc > 1) portname = argv[1];
else portname = "/dev/cuaa0";
/* Open the port. NB. without O_NONBLOCK, this would wait until the */
/* modem raises carrier detect. */
serial_fd = open(portname, O_RDWR | O_NONBLOCK);
if (serial_fd < 0)
{
perror(portname);
exit(1);
}
printf("Serial port now open\n");
/* Adjust the port settings. This is done by reading the current */
/* setings into memory, making any desired change to that in-memory */
/* copy, then writing them back into the terminal device so that all */
/* the changes come into effect. See termios(4) man page for detail */
/* Read the current terminal settings into memory */
tcgetattr(serial_fd, &term);
/* Adjust the port speed */
cfsetspeed(&term, B1200);
/* Turn off canonical processing (line buffer, backspace etc) */
cfmakeraw(&term);
/* Turn of carrier detect (ie. make /dev/ttyd0 work like cuaa0 */
term.c_cflag |= CLOCAL | CREAD;
/* Turn off RTS/CTS flow control (probably off anyhow, but make sure) */
term.c_cflag &= ~(CCTS_OFLOW | CRTS_IFLOW);
/* Now write these changes out so they take effect. */
tcsetattr(serial_fd, TCSANOW, &term);
printf("Serial port now configured\n");
/* Similarly, disable line buffering of the keyboard */
/* but remember the old settings to restore on exit */
tcgetattr(STDIN_FILENO, &term);
saved_term = term;
cfmakeraw(&term);
tcsetattr(STDIN_FILENO, TCSANOW, &term);
/* Finished setting terminal, go into a loop reading bytes from */
/* either keyboard or serial line as appropriate */
FD_ZERO(&fd_map);
while (1)
{
unsigned char buf[100];
int i;
FD_SET(serial_fd, &fd_map);
FD_SET(STDIN_FILENO, &fd_map);
if ((i = select(FD_SETSIZE, &fd_map, NULL, NULL, NULL)) < 0)
{
/* select returns error */
perror("select");
exit(1);
}
/* Here with either the keyboard or the serial line ready to read */
if (FD_ISSET(serial_fd, &fd_map))
{
i = read(serial_fd, buf, sizeof(buf));
write(STDOUT_FILENO, buf, i);
}
if (FD_ISSET(STDIN_FILENO, &fd_map))
{
i = read(STDIN_FILENO, buf, sizeof(buf));
write(serial_fd, buf, i);
if (*buf == 3)
{
/* User typed ctrl-C. Put the keyboard back to normal and exit */
tcsetattr(STDIN_FILENO, TCSANOW, &saved_term);
exit(0);
}
}
}
}
---------------------------------9616503751178269702599720673--