From owner-freebsd-hackers Thu Jun 28 14:58:41 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from tcpns.com (dsl-64-192-239-221.telocity.com [64.192.239.221]) by hub.freebsd.org (Postfix) with ESMTP id E926737B406 for ; Thu, 28 Jun 2001 14:58:32 -0700 (PDT) (envelope-from jcborkow@tcpns.com) Received: from localhost (jcborkow@localhost) by tcpns.com (8.11.4/8.11.4) with ESMTP id f5SLwSB22979; Thu, 28 Jun 2001 17:58:29 -0400 (EDT) Date: Thu, 28 Jun 2001 17:58:28 -0400 (EDT) From: Jason Borkowsky To: Chris Faulhaber Cc: freebsd-hackers@freebsd.org Subject: Re: Serial port control In-Reply-To: <20010628160723.C21188@peitho.fxp.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG > > 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! > > > > Many links at: http://www.stokely.com/unix.serial.port.resources/ > > in particular: http://www.easysw.com/~mike/serial/serial.html I thought I maybe had this under control, but not yet. I am trying to control the serial control lines on a FreeBSD 4.2 box, and wrote a simple program (included below). This program polls the serial controller for its current state, displays the state, and then attempts to set the state of two of the control lines (lower RTS and DTR). However, after telling ioctl() to lower RTS and DTR, and then polling the status again, RTS and DTR are still high. Does anyone know which serial control lines FreeBSD allows you to manipulate and why this isn't working? To compile the program, merely save it as text, gcc the text file, and run. Any insight is greatly appreciated! #include #include #include #include main () { int fd; /* File descriptor for serial port */ int status; /* Serial port status bitmask */ fd = open("/dev/cuaa0", O_RDWR | O_NOCTTY | O_NDELAY); if (fd == -1) perror("open_port: Unable to open /dev/ttyf1 - "); else fcntl(fd, F_SETFL, 0); /* Get serial line status bits */ ioctl(fd,TIOCMGET,&status); /* Signal Values, obtained from ttycom.h * * 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"); /* SET STATUS to 1 (DTR and RTS lowered). Previous status was 7 (DSR, DTR, * RTS high). */ status = 1; ioctl(fd,TIOCMSET,status); /* Check status after setting serial control bits */ ioctl(fd,TIOCMGET,&status); 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"); } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message