bool MeasurementThread::measureStep(int ns, int fi) { // static char buf [1000] = {0}; //qDebug() << "MeasurementStep: ns = " << ns << ", fi = " << fi; if (fList.size() > 1 || ns == 0) { QString strFreq = QString ("FREQ %1\n").arg(fList[fi]); viPrintf (vi, strFreq.toAscii().data()); // allocate buffer } long DATA_BUFFER_SIZE = calculateBufferSize(fi); int e_code; e_code = cbALoadQueue (BOARD_NUM, _ChanArray, _GainArray, NUM_CHANNELS); if (e_code != 0) { bool response = createSweepErrorMsg(ns, fi, "Error in cbLoadQueue()"); cbWinBufFree(_data); return response; } long actualSamplingRate = sRList[fi]; // if (fList.size() > 1 || ns == 0) { // viPrintf(vi, (ViString)"FREQ?\n"); // /* Read results */ // viScanf (vi, (ViString)"%t", &buf); // } //qDebug() << "Starting Scan. Requested fs = " << actualSamplingRate; int startTime = LoggerTime::timer(); e_code = cbAInScan (BOARD_NUM, 0, 15, DATA_BUFFER_SIZE, &actualSamplingRate, _GainArray[0], _data, CONVERTDATA + DMAIO); int endTime = LoggerTime::timer(); //qDebug() << "Ending Scan. Actual fs = " << actualSamplingRate; if (e_code != 0) { bool response = createSweepErrorMsg(ns, fi, "Error in cbInScan()"); cbWinBufFree(_data); return response; } ImpedanceMeasurement m = iCal.processData((WORD*)_data, DATA_BUFFER_SIZE, fList[fi], actualSamplingRate); //qDebug() << "Finished Impedance Measurement"; m.t = (startTime + endTime)/2; pMLst->append(m); //qDebug() << "Appended Impedance Measurement"; return true; }
bool EITMeasurementThread::measureStep(int ci, int si) { bool swMatSuccess; int e_code; e_code = cbALoadQueue (BOARD_NUM, _ChanArray, _GainArray, NUM_CHANNELS); if (e_code != 0) { bool response = createSweepErrorMsg(ci, si, "Error in cbLoadQueue()"); cbWinBufFree(_data); return response; } long actualSamplingRate = fsamp; swMatSuccess = closeSwitch(si); if (!swMatSuccess) { bool response = createSweepErrorMsg(ci, si, "Switch matrix error!!!"); cbWinBufFree(_data); return response; } //qDebug() << "Starting Scan " << NUM_CHANNELS << " Chans, Buffer Size: " << DATA_BUF_SIZE // << ", Sampling Rate: " << fsamp; int startTime = LoggerTime::timer(); e_code = cbAInScan (BOARD_NUM, 0, 15, DATA_BUF_SIZE, &actualSamplingRate, _GainArray[0], _data, CONVERTDATA + DMAIO); int endTime = LoggerTime::timer(); swMatSuccess = openSwitch(si); if (!swMatSuccess) { bool response = createSweepErrorMsg(ci, si, "Switch matrix error!!!"); cbWinBufFree(_data); return response; } //qDebug() << "Ending Scan"; if (e_code != 0) { bool response = createSweepErrorMsg(ci, si, "Error in cbInScan()"); cbWinBufFree(_data); return response; } ImpedanceMeasurement m = iCal.processData((WORD*)_data, DATA_BUF_SIZE, fcarr, actualSamplingRate); m.t = (startTime + endTime)/2; pMLst->append(m); this->msleep(this->offTime); return true; }
void main () { /* Variable Declarations */ int Row, Col; int PrnNum=1000; int BoardNum = 0; int ULStat = 0; int LowChan = 0; int HighChan = 0; int Gain = BIP5VOLTS; short Status = 0; long CurCount; long CurIndex; int Count = 10000; long Rate = 3125; unsigned Options; WORD *ADData; float RevLevel = (float)CURRENTREVNUM; /* Declare UL Revision Level */ ULStat = cbDeclareRevision(&RevLevel); ADData = (WORD*)cbWinBufAlloc(10000); if (!ADData) /* Make sure it is a valid pointer */ { printf("\nout of memory\n"); exit(1); } /* Initiate error handling Parameters: PRINTALL :all warnings and errors encountered will be printed DONTSTOP :program will continue even if error occurs. Note that STOPALL and STOPFATAL are only effective in Windows applications, not Console applications. */ cbErrHandling (PRINTALL, DONTSTOP); /* set up the display screen */ ClearScreen(); printf ("Demonstration of cbAInScan() in BACKGROUND mode\n\n"); printf ("%d data points are being collected in the background. This program\n", Count); printf ("could be doing many other things right now, but it will display every\n"); printf ("1000th data value collected.\n\n"); printf ("10000 Points Being Collected:\n\n"); printf ("Press any key to quit.\n\n"); printf ("Point # Value\n"); printf ("------- ------\n"); GetTextCursor (&Col, &Row); /* Collect the values with cbAInScan() in BACKGROUND mode Parameters: BoardNum :the number used by CB.CFG to describe this board LowChan :low channel of the scan HighChan :high channel of the scan Count :the total number of A/D samples to collect Rate :sample rate in samples per second Gain :the gain for the board ADData[] :the array for the collected data values Options :data collection options */ Options = CONVERTDATA + BACKGROUND + SINGLEIO; ULStat = cbAInScan (BoardNum, LowChan, HighChan, Count, &Rate, Gain, ADData, Options); /* During the BACKGROUND operation, check the status, print every ten values */ Status = RUNNING; while (!kbhit() && Status==RUNNING) { /* Check the status of the current background operation Parameters: BoardNum :the number used by CB.CFG to describe this board Status :current status of the operation (IDLE or RUNNING) CurCount :current number of samples collected CurIndex :index to the last data value transferred FunctionType: A/D operation (AIFUNCTIOM)*/ ULStat = cbGetStatus (BoardNum, &Status, &CurCount, &CurIndex,AIFUNCTION); /* Check if there are data in the buffer */ if (CurCount > 0) { MoveCursor (Col + 25, Row - 4); printf ("%ld", CurCount); if (CurCount > PrnNum) /* display every 100th data point */ { if (CurCount > 0) { MoveCursor (Col, Row - 1 + (PrnNum/ 1000)); printf (" %4d %5u", PrnNum, ADData[PrnNum]); } PrnNum = PrnNum+1000; } } } MoveCursor (Col + 30, Row - 4); if (Status == IDLE) printf (" Data Collection finished."); else printf ("Data collection interrupted by user."); /* the BACKGROUND operation must be explicitly stopped Parameters: BoardNum :the number used by CB.CFG to describe this board FunctionType: A/D operation (AIFUNCTIOM)*/ ULStat = cbStopBackground (BoardNum,AIFUNCTION); MoveCursor (1, 22); printf ("\n"); GetTextCursor (&Col, &Row); cbWinBufFree((int)ADData); }
void main () { /* Variable Declarations */ int Row, Col, K; int BoardNum = 0; int ULStat = 0; int LowChan = 0; int HighChan = 0; int Gain = BIP5VOLTS; short Status = 0; long CurCount, LastCount; long CurIndex; long NumPoints = 10; long Count = 10; long Rate = 3125; WORD ADData[10]; unsigned Options; float revision = (float)CURRENTREVNUM; /* Declare Revision level of the Universal Library */ ULStat = cbDeclareRevision(&revision); /* Initiate error handling Parameters: PRINTALL :all warnings and errors encountered will be printed DONTSTOP :program will continue even if error occurs. Note that STOPALL and STOPFATAL are only effective in Windows applications, not Console applications. */ cbErrHandling (PRINTALL, DONTSTOP); /* set up the display screen */ ClearScreen(); printf ("Demonstration of cbAInScan() in BACKGROUND mode followed by data conversion\n\n"); printf ("Collecting %ld data points. Press any key to quit.\n\n", Count); printf ("Value: the 16-bit integer read from the board.\n"); printf ("Converted value: the 12-bit value after the 4 channel bits have been removed.\n\n"); GetTextCursor (&Col, &Row); printf ("Collecting data"); /* Collect the values with cbAInScan() in BACKGROUND mode Parameters: BoardNum :the number used by CB.CFG to describe this board LowChan :low channel of the scan HighChan :high channel of the scan Count :the total number of A/D samples to collect Rate :sample rate in samples per second Gain :the gain for the board ADData[] :the array for the collected data values Options :data collection options */ Options = NOCONVERTDATA + BACKGROUND; ULStat = cbAInScan (BoardNum, LowChan, HighChan, Count, &Rate, Gain, ADData, Options); /* During the BACKGROUND operation, check status */ Status = RUNNING; while (!kbhit() && Status==RUNNING) { /* Check the status of the current background operation Parameters: BoardNum :the number used by CB.CFG to describe this board Status :current status of the operation (IDLE or RUNNING) CurCount :current number of samples collected CurIndex :index to the last data value transferred FunctionType: A/D operation (AIFUNCTIOM)*/ ULStat = cbGetStatus (BoardNum, &Status, &CurCount, &CurIndex,AIFUNCTION); /* check if there is data in the buffer */ if (CurCount != LastCount) { printf ("."); LastCount = CurCount; } } if (Status == IDLE) printf (" Data Collection finished."); else printf (" Data collection terminated by the user."); /* the BACKGROUND operation must be explicitly stopped Parameters: BoardNum :the number used by CB.CFG to describe this board FunctionType: A/D operation (AIFUNCTIOM)*/ ULStat = cbStopBackground (BoardNum,AIFUNCTION); /* show the collected data, then show the converted data */ MoveCursor (Col, Row + 2); printf ("Point# Value \n"); printf ("------- -------"); /* show the 16-bit values that were collected */ for (K = 0; K < (int)Count; K++) { MoveCursor (Col, Row + 4 + K); printf (" %3u %5u", K, ADData[K]); } /* use cbAConvertData to convert the 16-bit values to 12-bit values Parameters: NumPoints :the number of data values to convert ADData[] :the array holding the 16-bit values, 12-bit values are returned in the same array NULL :channel tags not returned */ ULStat = cbAConvertData (BoardNum, NumPoints, ADData, NULL); /* display the converted data */ MoveCursor (Col + 22, Row + 2); printf ("Converted value\n"); MoveCursor (Col + 22, Row + 3); printf ("---------------"); for (K = 0; K < (int)NumPoints; K++) { MoveCursor (Col + 25, Row + 4 + K); printf (" %u", ADData[K]); } MoveCursor (Col, Row + 15); printf ("Data conversion completed with cbConvertData."); printf ("\n"); }
LONG FAR PASCAL MainMessageHandler(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) { HDC hDC; /* handle for the display device */ PAINTSTRUCT ps; /* holds PAINT information */ TEXTMETRIC tm; /* holds TEXT information */ static unsigned short *ADValues; /* Win32 pointer */ static HGLOBAL MemHandle32; static short CurStatus; static HRGN hRgn; /* Rectangle region Handles */ static int CharWidth, CharHeight; static HGLOBAL MemHandle; int x, y, i; long Count, Rate; char OutString[80], *str; float Voltage; unsigned short CurValue; switch (Message) /* Windows Message Loop */ { case WM_CREATE: hDC = GetDC(hWndMain); /* Get the device context for window */ GetTextMetrics(hDC, &tm); /* From context, get size of font */ CharWidth = tm.tmAveCharWidth; CharHeight = tm.tmHeight + tm.tmExternalLeading; ReleaseDC(hWndMain, hDC); hRgn = CreateRectRgn(0,0, CharWidth*30, CharHeight*20); /* Allocate a Windows buffer */ MemHandle = cbWinBufAlloc ((long)BUF_SIZE); /* WIN32: This code is added to be able access more than */ /* 32K words of data. */ /* WIN32: allocate a local WIN32 buffer to hold A/D Data */ MemHandle32 = GlobalAlloc(GMEM_FIXED | GMEM_DDESHARE, BUF_SIZE *sizeof(short)); /* Get a 32-bit pointer to the WIN32 buffer */ ADValues = (unsigned short *)GlobalLock(MemHandle32); /* Start up A/D scan */ Count = BUF_SIZE; Rate = BUF_SIZE / NUM_SECS; cbAInScan (BOARD_NUM, 0, 0, Count, &Rate, ADRANGE, MemHandle, CONVERTDATA); break; case WM_PAINT: /* Repaint client area of window */ hDC = BeginPaint(hWndMain, &ps); x = CharWidth * 2; /* Position cursor within window */ y = CharHeight; /* One line down and 2 chars in */ str = " A/D Info"; /* Print title */ TextOut(hDC, x, y, str, strlen (str)); Count = BUF_SIZE; /* Copy Data from memory to 32-bit memory buffer */ cbWinBufToArray( MemHandle, &ADValues[0], 0, Count ); for (i=0;i<=4;i++) { CurValue = ADValues[i]; y += CharHeight*2; /* Print raw data value */ sprintf (OutString,"Raw A/D value(%d) = %u ", i, CurValue); TextOut(hDC, x, y, OutString, strlen (OutString)); y += CharHeight; /* Convert raw A/D to volts and print */ cbToEngUnits(BOARD_NUM,ADRANGE,CurValue,&Voltage); sprintf (OutString,"Voltage = %.2f ", Voltage); TextOut(hDC, x, y, OutString, strlen (OutString)); } SetTextAlign(hDC, TA_LEFT | TA_TOP); EndPaint(hWndMain, &ps); break; case WM_CLOSE: /* Close the window */ DestroyWindow(hWnd); if (hWnd == hWndMain) PostQuitMessage(0); /* Send message to Quit application */ if (MemHandle) cbWinBufFree (MemHandle); /* Free allocated memory */ if ( MemHandle32 ) GlobalFree( MemHandle32 ); break; default: return (DefWindowProc(hWnd, Message, wParam, lParam)); } return (0l); }
void MainWindow::on_startButton_clicked() { /* Variable Declarations */ int BoardNum = 0; int ULStat = 0; int LowChan = 0; int HighChan = 2; int Gain = BIP10VOLTS; short Status = RUNNING; long CurCount; long CurIndex; long Rate = 100; Count = (HighChan+1)*1000; channels = HighChan-LowChan+1; unsigned Options; float revision = (float)CURRENTREVNUM; BOOL HighResAD = FALSE; int ADRes; SamplingThread samplingThread; samplingThread.setInterval( 0.1 ); /* Declare Revision level of the Universal Library */ ULStat = cbDeclareRevision(&revision); /* Initiate error handling Parameters: PRINTALL :all warnings and errors encountered will be printed DONTSTOP :program will continue even if error occurs. Note that STOPALL and STOPFATAL are only effective in Windows applications, not Console applications. */ cbErrHandling (PRINTALL, DONTSTOP); /* Get the resolution of A/D */ cbGetConfig(BOARDINFO, BoardNum, 0, BIADRES, &ADRes); /* check If the resolution of A/D is higher than 16 bit. If it is, then the A/D is high resolution. */ if(ADRes > 16) HighResAD = TRUE; /* set aside memory to hold data */ if(HighResAD) { MemHandle = cbWinBufAlloc32(Count); ADData32 = (DWORD*) MemHandle; } else { MemHandle = cbWinBufAlloc(Count); ADData = (WORD*) MemHandle; } /* Make sure it is a valid pointer */ if (!MemHandle) exit(1); /* out of memory */ /* set up the display screen */ /* Demonstration of cbAInScan() */ /* Data are being collected in the BACKGROUND, CONTINUOUSLY */ /* Collect the values with cbAInScan() in BACKGROUND mode, CONTINUOUSLY Parameters: BoardNum :the number used by CB.CFG to describe this board LowChan :low channel of the scan HighChan :high channel of the scan Count :the total number of A/D samples to collect Rate :sample rate in samples per second Gain :the gain for the board ADData[] :the array for the collected data values Options :data collection options */ Options = CONVERTDATA + BACKGROUND + CONTINUOUS; ULStat = cbAInScan (BoardNum, LowChan, HighChan, Count, &Rate, Gain, MemHandle, Options); samplingThread.start(); d_plot->start(); /* Your program could be doing something useful here while data are collected */ /* During the BACKGROUND operation, check the status */ //float EngUnits; //QwtSystemClock checktimer; //checktimer.start(); //StoredLocation=0; //float v; while (Status==RUNNING) { qApp->processEvents(); // // Check the status of the current background operation // /*Parameters: // BoardNum :the number used by CB.CFG to describe this board // Status :current status of the operation (IDLE or RUNNING) // CurCount :current number of samples collected // CurIndex :index to the last data value transferred // FunctionType: A/D operation (AIFUNCTIOM)*/ // ULStat = cbGetStatus (BoardNum, &Status, &CurCount, &CurIndex,AIFUNCTION); // if (CurIndex==StoredLocation+1) // { // double elapsed=checktimer.elapsed(); // elapsed=elapsed/1000; // int ENG = cbToEngUnits(BoardNum,BIP5VOLTS,ADData[CurIndex],&v); // double v_double=(double)v; // const QPointF s(elapsed, 1.0); // SignalData::instance().append( s ); // StoredLocation=CurIndex; // //printf("IIndex:%d\n",CurIndex); // checktimer.restart(); // } // //printf("OIndex:%d",CurIndex); //// // check the current status of the background operation */ if ((Status == RUNNING) && CurCount > 0) { // int ENG = cbToEngUnits(BoardNum,BIP5VOLTS,ADData[CurIndex],&EngUnits); // double v_double=static_cast<double>(EngUnits); // printf (" Value: %d ",v_double); // emit dataValueChanged(*EngUnits); } } /* Data collection terminated */ /* The BACKGROUND operation must be explicitly stopped Parameters: BoardNum :the number used by CB.CFG to describe this board FunctionType: A/D operation (AIFUNCTIOM)*/ }