/// HIFN Gets all data packets that are available from a Sink VChan. The function allocates dynamically a data packet array with nPackets elements of DataPacket_type* /// HIFN If there are no data packets in the Sink VChan, dataPackets = NULL, nPackets = 0 and the function returns immediately with 0 (success). /// HIFN If an error is encountered, the function returns a negative value with error information and sets dataPackets to NULL and nPackets to 0. /// HIRET 0 if successful, and negative error code otherwise. /// OUT dataPackets, nPackets int GetAllDataPackets (SinkVChan_type* sinkVChan, DataPacket_type*** dataPackets, size_t* nPackets, char** errorMsg) { INIT_ERR CmtTSQHandle sinkVChanTSQHndl = sinkVChan->tsqHndl; // init *dataPackets = NULL; *nPackets = 0; // get number of available packets CmtErrChk( CmtGetTSQAttribute(sinkVChanTSQHndl, ATTR_TSQ_ITEMS_IN_QUEUE, nPackets) ); if (!*nPackets) return 0; // no data packets, return with success // get data packets nullChk( *dataPackets = malloc (*nPackets * sizeof(DataPacket_type*)) ); CmtErrChk( CmtReadTSQData(sinkVChanTSQHndl, *dataPackets, *nPackets, 0, 0) ); return 0; CmtError: Cmt_ERR Error: // cleanup OKfree(*dataPackets); *nPackets = 0; RETURN_ERR }
/* Perform the Read data and Plot data actions */ void CVICALLBACK readDataAndPlot(CmtTSQHandle queueHandle, unsigned int event, int value, void *callbackData){ unsigned char data[READ_LENGTH]; int tsqRValue = value, tsqREvent = event; //Thread Safe Result Value. switch(tsqREvent){ case EVENT_TSQ_ITEMS_IN_QUEUE: /* Read data from the thread safe queue and plot on the graph */ while(tsqRValue >= READ_LENGTH){ CmtReadTSQData(tsqHdl, data, READ_LENGTH, TSQ_INFINITE_TIMEOUT, 0); /* Start to calculate the 陀螺仪的x,y,z 以及加计的x,y,z */ resultCounter = 0; //用来重新自增计数 resultData[x][resultCounter]中的采集次数 if(dataSrc <=1) getFinalRightData(&data[0]); else simulateData(); /* Plot the data. */ if(tabFlag==0){ //Child Panels Mode for(int i=0; i<validMonNum; i++){ if(1 == signalShowingStat[i]) PlotStripChart(CPanels[i], PGraphs[i], resultData[i], READ_LENGTH/24, 0, 0, VAL_DOUBLE); } }else{ //Tab pages mode int i = 0; GetActiveTabPage(panelHdl, tabCtrl, &i); if(1 == signalShowingStat[i]) PlotStripChart(TPanels[i], PGraphs[i], resultData[i], READ_LENGTH/24, 0, 0, VAL_DOUBLE); } tsqRValue -= READ_LENGTH; }//while(tsqR...) break; }//Switch() }
/// HIFN Attempts to get one data packet from a Sink VChan before the timeout period. /// HIFN On success, it return 0, otherwise a negative numbers. If an error is encountered, the function returns error information. /// OUT dataPackets, nPackets int GetDataPacket (SinkVChan_type* sinkVChan, DataPacket_type** dataPacketPtr, char** errorMsg) { #define GetDataPacket_Err_Timeout -1 INIT_ERR CmtTSQHandle sinkVChanTSQHndl = sinkVChan->tsqHndl; int itemsRead = 0; char* msgBuff = NULL; *dataPacketPtr = NULL; // get data packet CmtErrChk( itemsRead = CmtReadTSQData(sinkVChanTSQHndl, dataPacketPtr, 1, (int)sinkVChan->readTimeout, 0) ); // check if timeout occured if (!itemsRead) { nullChk( msgBuff = StrDup("Waiting for ") ); nullChk( AppendString(&msgBuff, sinkVChan->baseClass.name, -1) ); nullChk( AppendString(&msgBuff, " Sink VChan data timed out.", -1) ); SET_ERR(GetDataPacket_Err_Timeout, msgBuff); } return 0; CmtError: Cmt_ERR Error: // cleanup OKfree(msgBuff); RETURN_ERR }