[wplug] Serial Comm.

Brian S. Woolstrum woolstrum at cmu.edu
Sat Jul 26 20:45:02 EDT 2003


On Fri, 25 Jul 2003, Weber, Larry A wrote:

> Date: Fri, 25 Jul 2003 14:28:03 -0400
> From: "Weber, Larry A" <laweber at switch.com>
> Reply-To: wplug at wplug.org
> To: "'wplug at wplug.org'" <wplug at wplug.org>
> Subject: [wplug] Serial Comm.
>
> Anyone doing serial communications with Linux & POSIX?
>
> I need to transmit raw 8-bit data bytes and the POSIX handlers are catching
> and stripping out several characters from my "messages", 0x0d (CR), 0x11 and
> 0x13 (Xon, Xoff).
>
> I can change the Xon and Xoff characters to another 8-bit value but that
> would only move the problem.  I have no idea how to get a 0x0d through the
> comm link.
>
> At this point I am not sure if the system refuses to Tx the characters or if
> the receiver is stripping them.  I will get ahold of an analyzer on Monday
> to find out which end is the problem.
>
> Any one know of a good ref book on serial comm. with Linux?  The paper on
> the web titled "Serial Programming Guide for POSIX Operating Systems" is of
> no help.  Perhaps a non-POSIX solution?
>
> -laweber
>
> _______________________________________________
> wplug mailing list
> wplug at wplug.org
> http://www.wplug.org/mailman/listinfo/wplug
>

Assuming you are using C or C++, it sounds like you might
not be putting things into raw mode with the "cfmakeraw"
function.  Here is some of my code from a C++ object, I
don't think there is anything C++ specific in this segment
so it should work for C as well.

You should also take a look through the
"Serial-Programming-HOWTO" from the Linux Documentation
Project.  Lots of good info, and examples.

{
struct termios ios;

strcpy(comm_port,pathname);
fd=open(comm_port,O_RDWR);
if (fd==-1)
	debug->msg(0,"%s Can't open %s: %s\n",__PRETTY_FUNCTION__,comm_port,strerror(errno));
else
	{
	if (!ios_saved)
		{
		tcgetattr(fd,&ios_save);
		ios_saved=1;
		}
	tcgetattr(fd,&ios);
	cfmakeraw(&ios);
	ios.c_cflag|=CRTSCTS; // enable RTS capability
	ios.c_cflag|=CREAD; // from serial_programming howto

	tcsetattr(fd,TCSANOW,&ios);
	}
return fd!=-1;
}


Brian S. Woolstrum
Principal System/Software Engineer
Carnegie Mellon University Libraries
4909 Frew Street, Hunt Library
Pittsburgh, PA  15213
412-268-2317 (phone)






More information about the wplug mailing list