From owner-freebsd-hackers Thu Jun 28 17:30:46 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 BFA5337B40B for ; Thu, 28 Jun 2001 17:30:38 -0700 (PDT) (envelope-from jcborkow@tcpns.com) Received: from localhost (jcborkow@localhost) by tcpns.com (8.11.4/8.11.4) with ESMTP id f5T0Ucg23360 for ; Thu, 28 Jun 2001 20:30:39 -0400 (EDT) Date: Thu, 28 Jun 2001 20:30:38 -0400 (EDT) From: Jason Borkowsky To: 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! 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 #include #include #include 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