unix - UART 0x0D's becoming 0x0A's -
the following code configures 2 uart ports on beaglebone black.
// open given file read/write, don't become controlling terminal, don't block int filedescriptor = open(filename, o_rdwr | o_noctty | o_sync); if(filedescriptor == -1) { cerr << "open_port: unable open " << filename << " " << strerror(errno) << endl; return false; } struct termios tty; memset(&tty, 0, sizeof tty); if(tcgetattr(filedescriptor, &tty) != 0) { cerr << strerror(errno) << endl; return false; } // baud cfsetispeed(&tty, b115200); cfsetospeed(&tty, b115200); // 8-bit chars tty.c_cflag = (tty.c_cflag & ~csize) | cs8; // disable ignbrk mismatched speed tests; otherwise receive break // \000 chars tty.c_iflag &= ~ignbrk; // disable break processing tty.c_lflag = 0; // no signaling chars, no echo // no canonical processing tty.c_oflag = 0; // no remapping, no delays tty.c_cc[vmin] = 0; // read doesn't block tty.c_cc[vtime] = 5; // 0.5 seconds read timeout // shut off xon/xoff ctrl tty.c_iflag &= ~(ixon | ixoff | ixany); // ignore modem controls tty.c_cflag |= (clocal | cread); // enable reading tty.c_cflag &= ~(parenb | parodd); // shut off parity tty.c_cflag |= 0; tty.c_cflag &= ~cstopb; tty.c_cflag &= ~crtscts; if(tcsetattr(filedescriptor, tcsanow, &tty) != 0) { cerr << strerror(errno) << endl; return false; }
i'm able send data, reason 0x0d's sent received 0x0a's. i'm sure in port configuration doing this.
i notice these 3 flags on man page tcsetattr
:
inlcr translate nl cr on input. igncr ignore carriage return on input. icrnl translate carriage return newline on input (unless igncr set).
you might want try explicitly setting inlcr
, icrnl
0 ?
Comments
Post a Comment