我在开发板上qt程序,开发板跟PC机的虚拟机通过USB转串口线连接,上面运行的是Ubuntu12.04系统,我在PC上发送字符串,然后在开发板上接收,接收的数据单个单个字符接收,为什么不是一整个字符串接收呢?并且接收不到第一个字符,而且差不多接收10秒之后就不在接收数据了!!!!。请各位大神赐教!!!
int fd,num,rtn;
struct termios options;
fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd < 0) {
printf ("open ttyUSB0 failt!\n");
return 0;
}
tcgetattr(fd, &options);
cfsetispeed(&options, B9600);
cfsetospeed(&options, B9600);
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
options.c_cc[VTIME] = 15;
options.c_cc[VMIN] = 1;
tcsetattr(fd, TCSANOW, &options);
char *buf = "abcdefgh\n";
while(1) {
num = write(fd, buf, 9);
printf("write num:%d---\n",num);
sleep(5);
}
close(fd);
return 0;
这是我写的代码。