|
我使用GINKGO,USB-CAN适配器,在QT环境下进行2次开发
我是在一个线程死循环接收数据,主线程更新UI.
发了4000包的数据,只能更新100多包....
while(can_start) { int ReadDataNum; int DataNum = VCI_GetReceiveNum(VCI_USBCAN2, 0,0); uint32_t SA,PF,flge; uint16_t t,n; VCI_CAN_OBJ *pCAN_ReceiveData =(VCI_CAN_OBJ *)malloc(DataNum*sizeof(VCI_CAN_OBJ)); if((DataNum > 0)&&(pCAN_ReceiveData != NULL)) { ReadDataNum = VCI_Receive(VCI_USBCAN2, 0, 0, pCAN_ReceiveData, DataNum); for (int i = 0; i < ReadDataNum; i++) {
SA = pCAN_ReceiveData[i].ID & (0xff); PF = ( pCAN_ReceiveData[i].ID & (0x00ff0000))>>16; if( can_ps == SA) {
switch(PF) { case 0x56: if((pCAN_ReceiveData[i].Data[0])==0x55) {//收到头 flge=1; SD.readbuff[0]=pCAN_ReceiveData[i].Data[1]; SD.readbuff[1]=pCAN_ReceiveData[i].Data[2]; SD.readbuff[2]=pCAN_ReceiveData[i].Data[3]; SD.readbuff[3]=pCAN_ReceiveData[i].Data[4]; SD.readbuff[4]=pCAN_ReceiveData[i].Data[5]; SD.readbuff[5]=pCAN_ReceiveData[i].Data[6]; SD.readbuff[6]=pCAN_ReceiveData[i].Data[7]; } elseif(flge==1) {//收完第1包内容,开始接收第二包
SD.readbuff[7]=pCAN_ReceiveData[i].Data[0]; SD.readbuff[8]=pCAN_ReceiveData[i].Data[1]; SD.readbuff[9]=pCAN_ReceiveData[i].Data[2]; SD.readbuff[10]=pCAN_ReceiveData[i].Data[3]; SD.readbuff[11]=pCAN_ReceiveData[i].Data[4]; SD.readbuff[12]=pCAN_ReceiveData[i].Data[5]; SD.readbuff[13]=pCAN_ReceiveData[i].Data[6]; SD.readbuff[14]=pCAN_ReceiveData[i].Data[7]; flge=2;//第二包接收完成 }else if(flge==2) {//收完第2包内容,开始接收第3包 SD.readbuff[15]=pCAN_ReceiveData[i].Data[0]; SD.readbuff[16]=pCAN_ReceiveData[i].Data[1]; SD.readbuff[17]=pCAN_ReceiveData[i].Data[2]; SD.readbuff[18]=pCAN_ReceiveData[i].Data[3]; SD.readbuff[19]=pCAN_ReceiveData[i].Data[4]; SD.readbuff[20]=pCAN_ReceiveData[i].Data[5]; SD.readbuff[21]=pCAN_ReceiveData[i].Data[6]; SD.readbuff[22]=pCAN_ReceiveData[i].Data[7]; flge=3; }else if(flge==3) {//收完第3包内容,开始接收第4包
SD.readbuff[23]=pCAN_ReceiveData[i].Data[0]; SD.readbuff[24]=pCAN_ReceiveData[i].Data[1]; SD.readbuff[25]=pCAN_ReceiveData[i].Data[2]; SD.readbuff[26]=pCAN_ReceiveData[i].Data[3]; SD.readbuff[27]=pCAN_ReceiveData[i].Data[4]; SD.readbuff[28]=pCAN_ReceiveData[i].Data[5]; SD.readbuff[29]=pCAN_ReceiveData[i].Data[6]; SD.readbuff[30]=pCAN_ReceiveData[i].Data[7]; flge=4; }else if (flge==4) {//收完第4包内容,开始接收第5包
SD.readbuff[31]=pCAN_ReceiveData[i].Data[0]; SD.readbuff[32]=pCAN_ReceiveData[i].Data[1]; SD.readbuff[33]=pCAN_ReceiveData[i].Data[2]; SD.readbuff[34]=pCAN_ReceiveData[i].Data[3]; SD.readbuff[35]=pCAN_ReceiveData[i].Data[4]; SD.readbuff[36]=pCAN_ReceiveData[i].Data[5]; SD.readbuff[37]=pCAN_ReceiveData[i].Data[6]; SD.readbuff[38]=pCAN_ReceiveData[i].Data[7]; flge=5; }else if(flge==5) {//收完第5包内容,开始接收第6包 SD.readbuff[39]=pCAN_ReceiveData[i].Data[0]; SD.readbuff[40]=pCAN_ReceiveData[i].Data[1]; SD.readbuff[41]=pCAN_ReceiveData[i].Data[2]; SD.readbuff[42]=pCAN_ReceiveData[i].Data[3]; SD.readbuff[43]=pCAN_ReceiveData[i].Data[4]; flge=0; SD.flag=1; if((pCAN_ReceiveData[i].Data[7])==0xAA) {//收到尾 flge=0; SD.flag=1; emit Log1();//UI更新 //SD.readnum++;
} }
这是线程的程序
可以更新UI,但是不是全部都可以更新.求一个解决方法... |
|
|