I have faced the following problem: I wish to read data comming to my serial port on linux. Data are send from an external device with standard serial settings. I'm sure that the external device sends them, that has been already checked.
However, on linux all i can read is an empty byte. What am I setting wrong?
My settings looks like that:
serial = open(_name, O_RDWR | O_NOCTTY | O_NDELAY);
fcntl(serial, F_SETFL,0);
tcgetattr(_serial, &_options);
options.c_ispeed = _baudRate;
options.c_ospeed = _baudRate;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
options.c_cflag &= ~PARENB;
options.c_iflag &= ~(INPCK|PARMRK|ISTRIP);
options.c_cflag &= ~CSTOPB;
options.c_cflag |= CREAD |CLOCAL ;
tcflush(serial, TCIFLUSH);
tcsetattr(serial, TCSANOW, &options);
my read function looks like that:
char byte = 'a';
int datasize = 0;
while (byte != '
') {
datasize = read(serial, &byte, sizeof(byte));
std::cout<< "Read:"<< byte <<"."; // this line always prints: "Read: ."
}
question from:
https://stackoverflow.com/questions/66061664/why-cannot-i-read-data-from-a-serial-port 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…