From owner-freebsd-questions Tue Oct 22 13: 3:33 2002 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 600D837B401 for ; Tue, 22 Oct 2002 13:03:31 -0700 (PDT) Received: from dc.cis.okstate.edu (dc.cis.okstate.edu [139.78.100.219]) by mx1.FreeBSD.org (Postfix) with ESMTP id E322F43E65 for ; Tue, 22 Oct 2002 13:03:30 -0700 (PDT) (envelope-from martin@dc.cis.okstate.edu) Received: from dc.cis.okstate.edu (localhost [127.0.0.1]) by dc.cis.okstate.edu (8.11.6/8.11.6) with ESMTP id g9MK3KG47670 for ; Tue, 22 Oct 2002 15:03:20 -0500 (CDT) (envelope-from martin@dc.cis.okstate.edu) Message-Id: <200210222003.g9MK3KG47670@dc.cis.okstate.edu> To: freebsd-questions@freebsd.org Subject: Serial Data Acquisition Problem Date: Tue, 22 Oct 2002 15:03:20 -0500 From: Martin McCormick 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 I have written a program to receive serial data and store it in a file. There is nothing particularly esoteric going on here, but I have done something wrong because my program almost works, but not quite. First, I tested the serial port and cable to rule out hardware issues. The port is /dev/ttyd0 and it works perfectly as a serial login port when I turn that feature on in /etc/ttys. When I test the program I wrote, I set that flag back to off, of course. The program runs as a daemon and opens the serial port after it goes daemon, but I think the problem is more likely the way I open the port. I am calling it as /dev/ttyd0. I have also tried /dev/cuaa0 and even /dev/ttyp0. No data are being received in the file and the serial port strangely begins to echo all input data to the output line as if it was a loopback connecter. If I kill the process, the port is properly deaf again since it isn't doing anything at all. Here is the code snippet that opens the file handle for reading. I use an external file containing the name but I know that works because I have used gdb to check that and also have seen it in an error message when it couldn't open it once. FILE *fp_inputstream; /*lots of other variables and code*/ if ((fp_inputstream = fopen(serialcomm,"r")) == NULL) { perror(serialcomm); exit(1); } while ((c = fgetc(fp_inputstream)) != EOF) { /*Read in another character.*/ /*This works with standard input and files.*/ } When I run the program, the devices attached to the first serial port show up as busy if you try to access them so that further proves I am opening the device name I am calling, but am I calling the right serial device for text data? In this case, the data are human-readable text with newlines and all. I did get this same algorithm to work on a Linux system. Thanks for any constructive ideas. Martin McCormick 405 744-7572 Stillwater, OK OSU Center for Computing and Information services Network Operations Group To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message