Serial port programming Question (in C)

Adam Hawes adam at
Tue Jan 15 11:35:14 CST 2008


I have a serial port question that has me stumped.  I've built a hack into my 
code to work around (most of the time) it but I can't figure out the problem.

I open the serial port and receive data from a device that's transmitting 
strings.  The string ends with a CR (\r) character and never a newline (\n).  
After the string is a checksum byte.  The device is sending a CR only; 
minicom demonstrates that for me if I use that to connect to the port.

When I am reading from the port somewhere \r is turning to \n, which causes 
the checksum to fail.

I've looked at the raw data coming in from the lowest level read() call and I 
can see that there is \n instead of \r there.

The options I set on the serial port are taken from the serial port howto 


// Enable raw output and input
options.c_oflag &= ~OPOST;
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);

// store the serial options
if (tcsetattr(serialFd, TCSANOW, &options)) {
  perror("configure_port(): tcsetattr");
  return -1;


The ICANON option is cleared so I should be getting raw, untranslated data.  I 
am not seeing that.  

What am I missing?  I can't find anything helpful in the Googlebot other than 
what I have already done.


More information about the linuxsa mailing list