From owner-freebsd-questions Wed Jan 15 3:22:10 2003 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4E02437B401 for ; Wed, 15 Jan 2003 03:22:09 -0800 (PST) Received: from mailsrv.otenet.gr (mailsrv.otenet.gr [195.170.0.5]) by mx1.FreeBSD.org (Postfix) with ESMTP id 32B2943F3F for ; Wed, 15 Jan 2003 03:22:08 -0800 (PST) (envelope-from keramida@ceid.upatras.gr) Received: from gothmog.gr (patr530-a235.otenet.gr [212.205.215.235]) by mailsrv.otenet.gr (8.12.6/8.12.6) with ESMTP id h0FBLuqW020413; Wed, 15 Jan 2003 13:21:58 +0200 (EET) Received: from gothmog.gr (gothmog [127.0.0.1]) by gothmog.gr (8.12.6/8.12.6) with ESMTP id h0FBLu3p097339; Wed, 15 Jan 2003 13:21:56 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) Received: (from giorgos@localhost) by gothmog.gr (8.12.6/8.12.6/Submit) id h0FBKgHv094160; Wed, 15 Jan 2003 13:20:42 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) Date: Wed, 15 Jan 2003 13:20:42 +0200 From: Giorgos Keramidas To: Paul Hamilton Cc: freebsd-questions@FreeBSD.ORG Subject: Re: How do I monitor the serial CTS line via C programmatically? Message-ID: <20030115112042.GA26041@gothmog.gr> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On 2003-01-15 18:26, paul@computerwest.com.au (Paul Hamilton) wrote: > I have been trying to monitor the serial CTS line. I would like to > log the fact that the CTS has changed state (active/non-active). > > I have been trying to adapt some Linux programs, but am having > problems with adapting the POSIX TIOCMGET function. > > Is there a FreeBSD way? You'd have to poll using ioctl(fd, TIOCMGET, &int) and detect CTS changes by checking the TIOCM_CTS bit in the returned value. The following (untested) sample program should be easy to adapt to your needs. When TIOCM_CTS changes from on to off or vice versa, the program should print the change. #include #include #include int main(void) { int bits; int last; if (ioctl(0, TIOCMGET, &bits) == -1) err(1, "ioctl"); last = bits & TIOCM_CTS; printf("CTS %s.\n", last ? "on" : "off"); while (1) { if (ioctl(0, TIOCMGET, &bits) == -1) err(1, "ioctl"); if ((last ^ (bits & TIOCM_CTS)) != 0) { last = bits & TIOCM_CTS; printf("CTS %s.\n", last ? "on" : "off"); } usleep(100000); } return (0); } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message