遇到一个小bug记录下来。
在ce上dll里采集两次读写网卡间的时间间隔数据,
1 //头文件中的声明 2 #define _TEST_IN_COMM_CYCLE_ 3 #define MAXLENBUF 131071 4 5 //类定义中添加的部分 6 #ifdef _TEST_IN_COMM_CYCLE_ 7 bool dumpfileflag; 8 enum _IN_TEST_FLAG{_IN_MEASURE=1,_IN_DUMP=2,IN_NEXT_FILE=3}; 9 int dumpfileaxisflag;// 10 unsigned int databufcnt; 11 int vdatabuffer[MAXLENBUF+1]; 12 fstream commstream; 13 int filecnt; 14 LARGE_INTEGER litmpThreadProc; 15 LONGLONG QPart1ThreadProc,QPart2ThreadProc; 16 double dfMinus, dfFreq, dfTim; 17 18 #endif 19 20 //构造函数中的部分 21 #ifdef _TEST_IN_COMM_CYCLE_ 22 QueryPerformanceFrequency(&litmpThreadProc); 23 dfFreq = (double)litmpThreadProc.QuadPart; 24 QPart1ThreadProc=QPart2ThreadProc=0; 25 dumpfileflag=true; 26 dumpfileaxisflag=10; 27 databufcnt=0; 28 QPart1ThreadProc=0,QPart2ThreadProc=0; 29 memset(vdatabuffer,0,MAXLENBUF+1); 30 filecnt=0; 31 if(CreateDirectory(L"\硬盘\sampledata\",NULL)) 32 { 33 //创建文件夹 34 } 35 #endif 36 37 //每次读写网口时的数据采集 38 #ifdef _TEST_IN_COMM_CYCLE_ 39 QueryPerformanceCounter(&litmpThreadProc); 40 QPart1ThreadProc=litmpThreadProc.QuadPart; 41 //dumpfileaxisflag=1; 42 if (!dumpfileflag) 43 { 44 goto skipprint; 45 } 46 switch(dumpfileaxisflag) 47 { 48 case 1://a 测时间 49 if (databufcnt<MAXLENBUF) 50 { 51 //vdatabufferx[databufcnt]=fabs(MachInfo.VelocityCommandX); 52 vdatabuffer[databufcnt]=QPart1ThreadProc-QPart2ThreadProc; 53 databufcnt++; 54 } 55 if (databufcnt==MAXLENBUF) 56 { 57 dumpfileaxisflag=5; 58 databufcnt=0; 59 } 60 break; 61 case 5://dump file 62 for (int i=0;i<MAXLENBUF;i++) 63 { 64 //tempvaldb=vdatabuffer[i]/dfFreq*1000000; 65 //vdatabuffer[i]=0; 66 //commstream<<(tempvaldb>15.0?tempvaldb-15.0:tempvaldb)<<" "; 67 commstream<<(vdatabuffer[i]/dfFreq*1000000)<<" "; 68 } 69 dumpfileaxisflag=9; 70 break; 71 case 9: 72 commstream.close(); 73 dumpfileaxisflag=0; 74 //dumpfileflag=false; 75 dumpfileaxisflag=10; 76 break; 77 case 10: 78 { 79 TCHAR tmpstr[30]={0}; 80 swprintf(tmpstr,L"\硬盘\sampledata\cycle%d",filecnt); 81 filecnt++; 82 commstream.open(tmpstr,ios::out); 83 } 84 commstream.unsetf(ios::scientific); 85 commstream.setf(ios::fixed); 86 commstream.precision(20); 87 dumpfileflag=true; 88 dumpfileaxisflag=1; 89 default: 90 //databufcnt=0; 91 break; 92 } 93 skipprint: 94 #endif 95 NIC_TxData(pCtrlBuf,ctrlBufLen); 96 // WriteFile(hAdapter,pCtrlBuf ,ctrlBufLen, &ReturnedBytes, 0);//下发控制数据 97 do 98 { 99 // ReadFile(hAdapter, pRcvBuf, 1024, &ReturnedBytes, 0); 100 NIC_RxData(); 101 } while (pRcvBuf[12] != 0x83 || pRcvBuf[13] != 0x82); 102 103 #ifdef _TEST_IN_COMM_CYCLE_ 104 QueryPerformanceCounter(&litmpThreadProc); 105 QPart2ThreadProc=litmpThreadProc.QuadPart; 106 ctrlBufLen = 17; 107 #endif
先说现象,每次调用到读写函数就异常退出,加断点发现是在case 10这个地方屏蔽掉就没事了,想了下发现最初文件名没那么长,写的是tmpstr[20],再用这么长的文件名,明显放不下 给冲掉了 哦,改成30 就over了
调程序要仔细!