Page 1 of 1

Serial device reads CR and overwrites data

Posted: Thu Jan 21, 2016 8:40 pm
by lightning200mph
First off I'm new to raspberrypi/linux etc, I've been working with arduino and trying to make my program faster with the Pi.

I'm working with UART device sending and receiving data. I can open the port, send data, receive data, and close the port without a problem. I'm having trouble with ignoring the CR. So I get data like this from the device:

AA BB CC \r>

But what is getting stored is:


Here is the code snippet I'm working with.

Code: Select all

#include <iostream>
#include <cstdio>
#include <cerrno>
#include <string>
#include <cstdlib>
#include <wiringPi.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>

int fd;
char rxData[256];

fd = open ("/dev/ttyAMA0", O_RDWR | O_NOCTTY | O_NDELAY);

tcgetattr(fd, &options);
options.c_iflag |= IGNCR;

write(fd, sendString , sizeof(sendString));
read (fd, rxData, sizeof(rxData));
cout << rxData << endl;

Any advice would be appreciated.

Re: Serial device reads CR and overwrites data

Posted: Fri Jan 22, 2016 1:26 pm
by StuartF
You will need to set the termios options.

Code: Select all

tcsetattr( fd, TCSANOW, &options );