I have been having some problem with the serial communication in ubuntu. I am writing C++ code to connect to my zigbee node but the problem is not the zigbee configuration. Since GTKTERM (an ordinary serial terminal for ubuntu) reads in the data correct.
Configurations for my serial connection are simple:
8N1 9600 baud no CTSRTS, no software flow control. There must be some small error in my settings since most of the characters are correct but some are wrong: 91 becomes 11 (10010001 -> 00010001, so only 1 bit off).
This is the code for setting up the connection:
int fd = open(adres , O_RDWR | O_NOCTTY | O_NDELAY);
struct termios options;
tcgetattr(fd, &options);
cfsetispeed(&options, B9600);
options.c_cflag |= (CLOCAL | CREAD);
// no parity 8N1
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
tcsetattr(fd, TCSANOW, &options);
I also noticed that when you change these configurations and change you program and run it again that these configurations are not set to a default. So unless you change them they will be the same between independent executions of a program. Maybe someone has a list of all the defaults so I can always restore default values on start-up. (I got a second program using fopen() to read from the serial communication stream and this program only 'works' when I first run this code to set the right configurations)
Any idea what's going wrong here? I've read this: http://www.easysw.com/~mike/serial/serial.html but can't figure it out.
Flags I also tried are the following:
options.c_cflag |= CRTSCTS; // hardware flow control
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); //raw input mode
options.c_oflag &= ~OPOST; // raw output mode
options.c_iflag |= (INPCK | ISTRIP); // parity check
options.c_iflag &= ~(IXON | IXOFF | IXANY); //disable flow control
Without a good result. If you want more info just ask.