From owner-freebsd-questions Wed Jan 15 23:44:56 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 056F137B401 for ; Wed, 15 Jan 2003 23:44:53 -0800 (PST) Received: from cwe.compwest.com.au (compwest.com.au [202.72.147.44]) by mx1.FreeBSD.org (Postfix) with ESMTP id 33E4943F18 for ; Wed, 15 Jan 2003 23:44:51 -0800 (PST) (envelope-from paul@compwest.com.au) Received: from wks (ant.parkview.compwest.com.au [202.72.147.43]) by cwe.compwest.com.au (8.11.6/8.11.6) with SMTP id h0G7gsr23814; Thu, 16 Jan 2003 15:42:54 +0800 (WST) (envelope-from paul@compwest.com.au) From: "Paul Hamilton" To: "Giorgos Keramidas" , "Paul Hamilton" Cc: Subject: RE: How do I monitor the serial CTS line via C programmatically? Date: Thu, 16 Jan 2003 15:44:01 +0800 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 In-Reply-To: <20030115112042.GA26041@gothmog.gr> 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 Thanks Giorgos! I needed to know the function used to access the Serial ports under FreeBSD. Your program compiles, but generates the following error msg when run: test_prog: ioctl: Inappropriate ioctl for device Thanks to the ioctl 'tip', I researched around, and found that the serial port needed opening, so this is the finished code (just in case someone else needs it): #include #include #include #include /*Originally it was termio.h*/ #include #include int main(void) { int bits; int last; int dcf_dev; if((dcf_dev = open("/dev/cuaa1", O_RDWR|O_NOCTTY)) < 0) { perror("open /dev/cuaa0"); return (-1); } if (ioctl(dcf_dev, TIOCMGET, &bits) == -1) err(1, "ioctl"); last = bits & TIOCM_CTS; printf("CTS %s.\n", last ? "on" : "off"); while (1) { if (ioctl(dcf_dev, 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); } Brilliant!! :-) Thanks for that! Cheers, Paul Hamilton -----Original Message----- From: owner-freebsd-questions@FreeBSD.ORG [mailto:owner-freebsd-questions@FreeBSD.ORG]On Behalf Of Giorgos Keramidas Sent: Wednesday, 15 January 2003 7:21 PM To: Paul Hamilton Cc: freebsd-questions@FreeBSD.ORG Subject: Re: How do I monitor the serial CTS line via C programmatically? 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 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message