void main_form::remoteDataIncoming() //QSocketNotifier监测到出口有数据读就自动调用该函数(一般不会丢数据){ u_char a; read(m_fd,read_buf,33); for(a=0;a<33;a++) qDebug("%u",read_buf[a]);}
if((event->timerId()==m_timerId)&&(RADIO_STAR==0))//条件判断(如果是定时器1时间到 且 没有进行广播,就正常采样) { //定时器1 i++;if(i>=6)i=1; w_length=MONITOR_LENGTH;w_cid=MONITOR_CID;w_chksum=w_length+w_cid+addr[i]; u_char w_data_buf[3]={w_length,w_cid,w_chksum}; bzero(read_buf,sizeof(read_buf)); sendAddr(addr[i]); //usleep(1000); //bukequede sendData(w_data_buf); usleep(2000); remoteDataIncoming(0x02); qDebug("i:%d",i); }
这样好一点,主要是在sendData后延时一下……让单片机反应一下,应该是单片机的事,以前都是单片机的发送的灯都不亮,只要亮就能收到数的,这个应该是单片机的问题,不过也不能这么说,因为用小程序时就没有问题,到这就有问题了,是不是发的有问题呢,这个很难说了……
还是用Qt的事件结构吧,这样也可以,如果确定这样不行的话再改吧……又想起来了,小程序测试时没有进行清零,清零一下看看:
#include <stdio.h> /*标准输入输出定义*/ #include <stdlib.h> /*标准函数库定义*/ #include <unistd.h> /*Unix 标准函数定义*/ #include <sys/types.h> /*系统类型定义*/ #include <sys/stat.h> /*系统状态定义*/ #include <fcntl.h> /*文件控制定义*/ #include <termios.h> /*PPSIX 终端控制定义*/ #include <errno.h> /*错误号定义*/ #include <string.h> struct termios serialAttr; const char data[]={
0x02,0x01,0x05}; int spaceSerialPort(int m_fd) //空校验 { int fd=m_fd; serialAttr.c_cflag |= PARENB | PARODD | CMSPAR;//ou if(tcsetattr(fd, TCSANOW, &serialAttr) !=0) //配置立刻起作用 { perror("serial