开发者

Can't detect the first data sent in the serial port

开发者 https://www.devze.com 2023-01-04 08:55 出处:网络
I am using C language and Linux as my programming platform. And I have problems in setting up the serial port(/dev/ttyS0). In my small program, I 开发者_如何学Goset my serial port using tcgetattr and

I am using C language and Linux as my programming platform. And I have problems in setting up the serial port(/dev/ttyS0). In my small program, I 开发者_如何学Goset my serial port using tcgetattr and tcsetattr

options.c_cflag |= B115200;
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag &= ~CRTSCTS;
options.c_cflag |= CS8;
options.c_cflag |= (CLOCAL | CREAD);
options.c_iflag &= ~(IXON | IXOFF | IXANY);

My problem is, my app doesn't get the first data that I sent. Did I missed some value?

Thanks.


Is it possible your app IS getting the first thing you send it, but it has junk at the beginning from connection/setup and is not being parsed properly?

You could try flushing the serial out just after init or sending CR/LF just after init to see if that clears things out before you send to your app.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号