我在接受串口数据时用 点击按钮,就开始接受数据,并画波形,我波形是用paintEvent drawLine
0来做的,运行程序时,一点接收数据 ,界面就冻住
connect(xb1,SIGNAL(clicked()),this,SLOT(receive()));
void MyMainWidget::receive()
{
int res;
struct termios tio,oldtio;
int fd;
fd=open(pComPort,O_RDWR | O_NDELAY | O_NOCTTY);
tcgetattr(fd,&oldtio);
bzero(&tio,sizeof(tio));
tio.c_cflag = BodeRate |CS8 |CREAD |CLOCAL;
//tio.c_cflag = B115200 |CS8 |CREAD |CLOCAL;
tio.c_lflag = ICANON;
tio.c_iflag = IGNPAR;
tio.c_oflag = 0;
tcflush(fd,TCIFLUSH);
tcsetattr(fd,TCSANOW,&tio);
int n;
int j;
n=0;
do
{
res = read(fd,buf,100);
delay(5000);
buf[res]=0;
printf("res=%d buf=%s\n",res,buf);
j=atoi(buf);
io[n]=j;
printf("io[%d]=%d\n",n,io[n]);
n++;
xb2 ->setText(buf);
update();
}while(n<100);
update();
Btl->setEnabled(true);
TypeCombo->setEnabled(true);
}
不知是不是没有使用到多线程的原因?