Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Oct 2002 15:03:20 -0500
From:      Martin McCormick <martin@dc.cis.okstate.edu>
To:        freebsd-questions@freebsd.org
Subject:   Serial Data Acquisition Problem
Message-ID:  <200210222003.g9MK3KG47670@dc.cis.okstate.edu>

next in thread | raw e-mail | index | archive | help
	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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200210222003.g9MK3KG47670>