QSocketNotifier丢数据

来源:互联网 发布:openwrt 进入webshell 编辑:程序博客网 时间:2024/05/18 03:00

1,遇到这个问题

用QSocketNotifier监测串口读取数据 http://bbs.embedsky.net/forum.php?mod=viewthread&tid=9066

相应的解决方法:没

QSocketNotifier监测串口问题http://www.qtcn.org/bbs/read-htm-tid-36369-displayMode-1-page-1.html#133140

相应的解决方法:

使用这个要遵循三步:
1、Disable the notifier.
2、Read data from the socket.
3、Re-enable the notifier if you are interested in more data


2,看看是不是我的校验的问题,置位校验都取消看看

果真如此:

i1:0

JIN_remoteDataIncoming

handleData:OK

read_buf:134521496

i1:1

JIN_remoteDataIncoming

handleData:OK

read_buf:134521496

i1:2

JIN_remoteDataIncoming

handleData:OK

read_buf:134521496

i1:3

JIN_remoteDataIncoming

handleData:OK

read_buf:134521496

i1:4

不过 还有一个问题就是,如果读多个数据怎么办?

①:http://blog.chinaunix.net/uid-24948299-id-2899775.html

void MainWindow::read_serial(){ QByteArray temp=myCom->readAll();//全部读取ui->textEdit->insertPlainText(temp);//显示读取到的数据}

②:还是回到上边的问题中,想办法Disable

m_notifier->setEnabled(false);//不使能

m_notifier->setEnabled(true);  //使能

结论:禁止是能禁止了,不过效果没有达到!还是一个数据就激活一次!

③:

void TMainForm::remoteDataIncoming(){char c;if (read(m_fd, &c, sizeof c) != 1) {QMessageBox::warning(this, tr("Error"), tr("Receive error!"));return;}m_receiveEdit->insert(QString(QChar(c)));}

仔细读这段代码时,并加上亲自实验,每次读一个字节是就最好的办法了,我可以让它们累加到数组中去!

原创粉丝点击