Date: Thu, 28 Jun 2001 20:30:38 -0400 (EDT) From: Jason Borkowsky <jcborkow@tcpns.com> To: freebsd-hackers@freebsd.org Subject: Re: Serial port control Message-ID: <Pine.BSF.4.21.0106282024030.23341-100000@bemused.tcpns.com> In-Reply-To: <20010628160723.C21188@peitho.fxp.org>
next in thread | previous in thread | raw e-mail | index | archive | help
> > I am looking to find a simple way to control a serial port through BSD > > (such as raising and lowering DTR for a specified duration). I thought I > > had it using ioctl() and wrote a simple program to test it, but it seems I > > don't have a full understanding of ioctl(). Does anyone know of any > > pre-written utilities I can use? Or where to get some really detailed > > information about ioctl()? Thanks! After several responses, I thought I had it. From a software point of view, my program, included below, works fine. But from a hardware point of view, the signals I am trying to lower, RTS and DTR, are staying high. Can anyone try to compile the below program and do a serial port test with an RS-232 tester and see if anyone actually sees RTS and DTR going low? Sorry for bothering everyone with this again, but this is driving me nuts and I can't figure out the problem now. Thanks! #include <stdio.h> #include <fcntl.h> #include <errno.h> #include <termios.h> main () { int fd; /* File descriptor for serial port */ int status; /* Serial port status bitmask */ int error = 0; fd = open("/dev/cuaa0", O_RDWR | O_NOCTTY | O_NDELAY); if (fd == -1) perror("open_port: Unable to open /dev/ttyf1 - "); else error = fcntl(fd, F_SETFL, 0); if (error == -1) perror("fcntl error - "); /* Get serial line status bitmask */ error = 0; error = ioctl(fd,TIOCMGET,&status); if (error == -1) perror("ioctl1 GET error - "); /* Signal Values * * 1 - DSR (Data Set Ready) * 2 - DTR (Data Terminal Ready) * 4 - RTS (Request to Send) * 8 - ST (Secondary Transmit) * 16 - SR (Secondary Receive) * 32 - CTS (Clear to Send) * 64 - DCD (Data Carrier Detect) * 128 - RNG (Ring) * 256 - DSR (Data Set Ready) */ printf ("Current Serial Settings:"); if (status >= TIOCM_DSR) { status -= TIOCM_DSR; printf (" DSR "); } if (status >= TIOCM_RNG) { status -= TIOCM_RNG; printf (" Ring "); } if (status >= TIOCM_CD) { status -= TIOCM_CD; printf (" DCD "); } if (status >= TIOCM_CTS) { status -= TIOCM_CTS; printf (" CTS "); } if (status >= TIOCM_SR) { status -= TIOCM_SR; printf (" SR "); } if (status >= TIOCM_ST) { status -= TIOCM_ST; printf (" ST "); } if (status >= TIOCM_RTS) { status -= TIOCM_RTS; printf (" RTS "); } if (status >= TIOCM_DTR) { status -= TIOCM_DTR; printf (" DTR "); } if (status >= TIOCM_LE) { status -= TIOCM_LE; printf (" DSR "); } printf("\n"); /* Lower DTR and RTS */ status = 1; error = 0; error = ioctl(fd,TIOCMSET,&status); if (error == -1) perror ("ioctl SET error - "); /* Hold the signals low, as they seem to reset when releasing the * file descriptor */ sleep(10); error = 0; error = ioctl(fd,TIOCMGET,&status); if (error == -1) perror ("ioctl GET error - "); printf ("Current Serial Settings:"); if (status >= TIOCM_DSR) { status -= TIOCM_DSR; printf (" DSR "); } if (status >= TIOCM_RNG) { status -= TIOCM_RNG; printf (" Ring "); } if (status >= TIOCM_CD) { status -= TIOCM_CD; printf (" DCD "); } if (status >= TIOCM_CTS) { status -= TIOCM_CTS; printf (" CTS "); } if (status >= TIOCM_SR) { status -= TIOCM_SR; printf (" SR "); } if (status >= TIOCM_ST) { status -= TIOCM_ST; printf (" ST "); } if (status >= TIOCM_RTS) { status -= TIOCM_RTS; printf (" RTS "); } if (status >= TIOCM_DTR) { status -= TIOCM_DTR; printf (" DTR "); } if (status >= TIOCM_LE) { status -= TIOCM_LE; printf (" DSR "); } printf("\n"); close(fd); } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0106282024030.23341-100000>