void MainWindow::on_stopButton_clicked()
{
    int ULStat = cbStopBackground (0,AIFUNCTION);

    cbWinBufFree(MemHandle);
    exit(1); // exits background operation and exits gui application
}
void MeasurementThread::cleanup()
{
	/* Close visa session */
	viPrintf (vi, (ViString)"OUTP OFF\n");
	viClose (vi);
	viClose (defaultRM);
	if (_data != 0) cbWinBufFree(_data);
}
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 EITMeasurementThread::cleanup()
{
        /* Close visa session */
    viPrintf (viSwMat, (ViString)"*RST\n");
    viClose (viSwMat);

    viPrintf (viSiGen, (ViString)"OUTP OFF\n");
    viClose (viSiGen);

    viClose (defaultRM);

    if (_data != 0) cbWinBufFree(_data);
}
示例#6
0
void main()
    {
    /* Variable Declarations */
    int I, J, ULStat, BoardNum;
    int ChipNum, CounterNum;
    int FOutDivider, FOutSource, Compare1, Compare2, TimeOfDay;
    int GateControl, CounterEdge, CountSource, SpecialGate;
    int ReLoad, RecycleMode, BCDMode, CountDirection, OutputControl;
    int LoadValue;
    int RegName;
    int IntCount, NumCntrs;
    short Status;
    long CurCount, CurIndex, FirstPoint;
    short  CntrControl[MAXNUMCNTRS];
    char *StatusStr;
    WORD *DataBuffer;
    float    RevLevel = (float)CURRENTREVNUM;

  /* Declare UL Revision Level */
   ULStat = cbDeclareRevision(&RevLevel);

    /* 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 9513 Counter Functions.\n\n");
    printf ("Press any key to quit.\n\n");

    /* Initialize the board level features  */
    BoardNum = 0;           /* Number used by CB.CFG to describe this board */
    ChipNum = 1;            /* chip being init'ed (1 for CTR5, 1 or 2 for CTR10) */
    FOutDivider = 10;       /* sets up OSC OUT for 10Hz signal which can be */
    FOutSource = FREQ5;     /* used as an interrrupt source for this example */
    Compare1 = DISABLED;    /* Status of comparator 1 */
    Compare2 = DISABLED;    /* Status of comparator 2 */
    TimeOfDay = DISABLED;   /* Time of day control mode */
    ULStat = cbC9513Init (BoardNum, ChipNum, FOutDivider, FOutSource, Compare1,
                          Compare2, TimeOfDay);

    /* Set the configurable operations of counters 1 and 2 */
    CounterNum = 1;         /* Counter to be configured (0-5) */
    GateControl = NOGATE;   /* Gate control value */
    CounterEdge = POSITIVEEDGE;    /* Which edge to count */
    CountSource = FREQ3;    /* Signal source for counter */
    SpecialGate = DISABLED; /* Status of special gate */
    ReLoad = LOADREG;       /* Method of reloading the counter */
    RecycleMode = RECYCLE;  /* Recycle mode */
    BCDMode = DISABLED;     /* Counting mode, BCD or binary */
    CountDirection = COUNTUP;  /* Counting direction (up or down) */
    OutputControl = ALWAYSLOW; /* Output signal type and level */
    ULStat = cbC9513Config (BoardNum, CounterNum , GateControl, CounterEdge,
                            CountSource, SpecialGate, ReLoad, RecycleMode,
                            BCDMode, CountDirection, OutputControl);
    CounterNum = 2;
    CountSource = FREQ5;
    ULStat = cbC9513Config (BoardNum, CounterNum , GateControl, CounterEdge,
                            CountSource, SpecialGate, ReLoad, RecycleMode,
                            BCDMode, CountDirection, OutputControl);

    /* Load the 2 counters with starting values of zero with cbCLoad()
        Parameters:
            BoardNum    :the number used by CB.CFG to describe this board
            RegName     :the counter to be loading with the starting value
            LoadValue   :the starting value to place in the counter */
    LoadValue = 0;
    for (RegName=LOADREG1; RegName<=LOADREG2; RegName++)
        ULStat = cbCLoad (BoardNum, RegName, LoadValue);

    /* set the counters to store their values upon an interrupt
        Parameters:
            BoardNum    :the number used by CB.CFG to describe this board
            IntCount    :maximum number of interrupts
            CntrControl[]:array which indicates the channels to be used
            DataBuffer[] :array that receives the count values for enabled
                          channels each time an interrupt occurs */
    IntCount = 100;

   
	/*
		DataBuffer must be able to hold  NumCntrs*IntCount  values, even if
		we're only enabling a few counters. We'll allocate enough space for
		MAXNUMCNTRS in case NumCntrs has not been updated.
	*/
	DataBuffer = (WORD *)cbWinBufAlloc( MAXNUMCNTRS*IntCount );

	/* 	
		The actual number of counters onboard.  
		UPDATE THIS	VALUE TO REFLECT THE NUMBER OF COUNTERS FOR THE INSTALLED MODEL.
	*/	
	NumCntrs = 10;			
    for (I = 0; I < NumCntrs; I++)
        CntrControl[I] = DISABLED;

	for (J = 0; J< IntCount; J++)
		for (I = 0; I<NumCntrs; I++)
			DataBuffer[J*NumCntrs + I] = 0;
        

    /* enable the channels to be monitored */
    CntrControl[0] = ENABLED;
    CntrControl[1] = ENABLED;

    ULStat = cbCStoreOnInt (BoardNum, IntCount, CntrControl, DataBuffer);

    MoveCursor (1, 14);
    printf ("When an interrupt is generated, the table below will be updated.");

    MoveCursor (5, 15);
    printf ("Counter   Status      Value ");

    Status = RUNNING;
    while (!kbhit() && Status==RUNNING)
        {
		/* We'll display the latest counts retrieved and the current INT count*/
		/* 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 (CTRFUNCTION)*/
        cbGetStatus (BoardNum, &Status, &CurCount, &CurIndex,CTRFUNCTION);

        for (I = 0; I < 5; I++)
            {
            if (CntrControl[I] == DISABLED)
                StatusStr = "DISABLED";
            else
                StatusStr = "ENABLED";

            MoveCursor (5, 16 + I);
			
			FirstPoint=0;

			/* 
				The latest set of data in the data buffer is starts at
					FirstPoint = NumCntrs*CurIndex;
			*/
			if (CurIndex>0)
				{
				FirstPoint = NumCntrs*CurIndex;
				}	

			printf (" %2u       %8s    %5u\n", I, StatusStr, DataBuffer[FirstPoint + I]);
            }

        
        printf ("Number of interrupts so far=%-ld\n", CurCount);
        }

        /* the BACKGROUND operation must be explicitly stopped
        Parameters:
             BoardNum    :the number used by CB.CFG to describe this board 
             FunctionType: counter operation (CTRFUNCTION)*/  
    ULStat = cbStopBackground (BoardNum,CTRFUNCTION);

	cbWinBufFree((int)DataBuffer);

    MoveCursor (1, 22);
    printf ("\n");

    }
示例#7
0
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);
}
示例#8
0
void main ()
    {
    /* Variable Declarations */
    int Row, Col;
	int  BoardNum = 0;
	int Options;
    long PreTrigCount, TotalCount, Rate, ChanCount;
	short ChanArray[NUMCHANS];
	short ChanTypeArray[NUMCHANS];
    short GainArray[NUMCHANS];
    int ULStat = 0;
    short Status = IDLE;
    long CurCount;
    long CurIndex, DataIndex;
	int PortNum, Direction, CounterNum;
    WORD *ADData;
    float    RevLevel = (float)CURRENTREVNUM;

  /* Declare UL Revision Level */
   ULStat = cbDeclareRevision(&RevLevel);

    ADData = (WORD*)cbWinBufAlloc(NUMPOINTS * NUMCHANS);
    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 cbDaqInScan()\n\n");
    printf ("Data are being collected in the BACKGROUND, CONTINUOUSLY\n");


	/* load the arrays with values */
    ChanArray[0] = 0;
	ChanTypeArray[0] = ANALOG;
    GainArray[0] = BIP10VOLTS;

    ChanArray[1] = FIRSTPORTA;
	ChanTypeArray[1] = DIGITAL16;
    GainArray[1] = NOTUSED;

	ChanArray[2] = 0;
	ChanTypeArray[2] = CTR32LOW;
    GainArray[2] = NOTUSED;

	ChanArray[3] = 0;
	ChanTypeArray[3] = CTR32HIGH;
    GainArray[3] = NOTUSED;

	/* configure FIRSTPORTA and FIRSTPORTB for digital input */
	
	PortNum = FIRSTPORTA;
    Direction = DIGITALIN;
    ULStat = cbDConfigPort (BoardNum, PortNum, Direction);

	PortNum = FIRSTPORTB;
	ULStat = cbDConfigPort (BoardNum, PortNum, Direction);

	// configure counter 0
	CounterNum = ChanArray[2];
    ULStat = cbCConfigScan(BoardNum, CounterNum, ROLLOVER, CTR_DEBOUNCE_NONE, 0, CTR_RISING_EDGE, 0, CounterNum);

    /* Collect the values with cbDaqInScan() in BACKGROUND mode, CONTINUOUSLY
        Parameters:
            BoardNum    :the number used by CB.CFG to describe this board
            ChanArray[] :array of channel values
			ChanTypeArray[] : array of channel types
            GainArray[] :array of gain values
            ChanCount    :the number of channels
            Rate        :sample rate in samples per second
			PretrigCount:number of pre-trigger A/D samples to collect
            TotalCount  :the total number of A/D samples to collect
            ADData[]    :the array for the collected data values
            Options     :data collection options  */

    ChanCount = NUMCHANS;
	PreTrigCount =0;
	TotalCount = NUMPOINTS * NUMCHANS;
	Rate = 1000;								             /* sampling rate (samples per second) */
	Options = CONVERTDATA + BACKGROUND + CONTINUOUS;         /* data collection options */

	ULStat = cbDaqInScan(BoardNum, ChanArray, ChanTypeArray, GainArray, ChanCount, &Rate, &PreTrigCount, &TotalCount, ADData, Options);

    printf ("--------------------------------------------------------------------------------");
    printf ("| Your program could be doing something useful here while data are collected...|");
    printf ("--------------------------------------------------------------------------------");
    printf ("\nCollecting data...\n\n");
    printf ("Press any key to quit.\n\n");

    GetTextCursor (&Col, &Row);

	if(ULStat == NOERRORS)
		Status = RUNNING;

    /* During the BACKGROUND operation, check the status */
    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 (DAQIFUNCTION)*/
        ULStat = cbGetStatus (BoardNum, &Status, &CurCount, &CurIndex,DAQIFUNCTION);

        /* check the current status of the background operation */
        if (Status == RUNNING)
            {
			DataIndex = CurIndex -  CurIndex % NUMCHANS - NUMCHANS;
			if(DataIndex>0)
				{
					MoveCursor (Col, Row);
					printf ("Channel 0   Data point: %3ld   ", DataIndex);
					printf ("  Value: %d  \n",ADData[DataIndex]);
					DataIndex++;
					printf ("FIRSTPORTA  Data point: %3ld   ", DataIndex);
					printf ("  Value: %d  \n",ADData[DataIndex]);
					DataIndex++;
					printf ("Counter 0   Data point: %3ld   ", DataIndex);
					printf ("  Value: %u  ",ADData[DataIndex] + (ADData[DataIndex+1]<<16));   // 32-bit counter
				}
            }
        }
    printf ("\n");
    MoveCursor (Col, Row + 4);
    printf ("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 (DAQIFUNCTION)*/  
    ULStat = cbStopBackground (BoardNum,DAQIFUNCTION);

    cbWinBufFree((int)ADData);
    MoveCursor (1, 22);
    printf ("\n");
}
示例#9
0
void main ()
    {
    /* Variable Declarations */
    int Row, Col;
	int BoardNum = 0;
	int Options;
    long PreTrigCount, TotalCount, Rate, ChanCount;
	short ChanArray[NUMCHANS];
	short ChanTypeArray[NUMCHANS];
    short GainArray[NUMCHANS];
    int ULStat = 0;
    short Status = RUNNING;
    int TrigSource, TrigSense, TrigChan, ChanType, Gain, TrigEvent;
	float Level, Variance;
	
    long CurCount;
    long CurIndex, DataIndex;
	int PortNum, Direction;
    WORD *ADData;
    float    RevLevel = (float)CURRENTREVNUM;

  /* Declare UL Revision Level */
   ULStat = cbDeclareRevision(&RevLevel);

    ADData = (WORD*)cbWinBufAlloc(NUMPOINTS * NUMCHANS);
    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 cbDaqSetTrigger()\n\n");


	/* load the arrays with values */
    ChanArray[0] = 0;
	ChanTypeArray[0] = ANALOG;
    GainArray[0] = BIP10VOLTS;

    ChanArray[1] = FIRSTPORTA;
	ChanTypeArray[1] = DIGITAL8;
    GainArray[1] = NOTUSED;

	ChanArray[2] = 0;
	ChanTypeArray[2] = CTR16;
    GainArray[2] = NOTUSED;


	/* configure FIRSTPORTA for digital input */
	
	PortNum = FIRSTPORTA;
    Direction = DIGITALIN;
    ULStat = cbDConfigPort (BoardNum, PortNum, Direction);

	/* Set Triggers 
		Parameters:
			BoardNum    :the number used by CB.CFG to describe this board
			TrigSource	:trigger source
			TrigSense	:trigger sensitivity
			TrigChan	:trigger channel
			ChanType	:trigger channel type
			Gain		:trigger channel gain
			Level		:trigger level
			Variance	:trigger variance
			TrigEvent	:trigger event type */

	/* Start trigger settings.
	   AD conversions are enabled when analog channel 0 makes a transition from below 2 V to above.*/
	TrigSource = TRIG_ANALOG_SW;
	TrigSense = RISING_EDGE;
	TrigChan = ChanArray[0];
	ChanType = ChanTypeArray[0];
	Gain = GainArray[0];
	Level = 2.0;
	Variance = 0;
	TrigEvent = START_EVENT;

	/* Set start trigger */
	ULStat = cbDaqSetTrigger(BoardNum, TrigSource, TrigSense, TrigChan, ChanType , Gain, Level, Variance, TrigEvent);

	/* Stop trigger settings. 
	   AD conversions are terminated when counter 0 reaches 100 counts.*/
	TrigSource = TRIG_COUNTER;
	TrigSense = ABOVE_LEVEL;
	TrigChan = ChanArray[2];
	ChanType = ChanTypeArray[2];
	Gain = GainArray[2];
	Level = 100;
	Variance = 0;
	TrigEvent = STOP_EVENT;

	/* Set stop trigger */
	ULStat = cbDaqSetTrigger(BoardNum, TrigSource, TrigSense, TrigChan, ChanType , Gain, Level, Variance, TrigEvent);


    /* Collect the values with cbDaqInScan() in BACKGROUND mode, CONTINUOUSLY
        Parameters:
            BoardNum    :the number used by CB.CFG to describe this board
            ChanArray[] :array of channel values
			ChanTypeArray[] : array of channel types
            GainArray[] :array of gain values
            ChanCount    :the number of channels
            Rate        :sample rate in samples per second
			PretrigCount:number of pre-trigger A/D samples to collect
            TotalCount  :the total number of A/D samples to collect
            ADData[]    :the array for the collected data values
            Options     :data collection options  */
    
	ChanCount = NUMCHANS;
	PreTrigCount = 0;
	TotalCount = NUMPOINTS * NUMCHANS;
	Rate = 1000;								             /* sampling rate (samples per second) */
	Options = CONVERTDATA + BACKGROUND + CONTINUOUS + EXTTRIGGER;         /* data collection options */

	ULStat = cbDaqInScan(BoardNum, ChanArray, ChanTypeArray, GainArray, ChanCount, &Rate, &PreTrigCount, &TotalCount, ADData, Options);

	if (ULStat==NOERRORS)
		{

		printf ("\nTrigger signals are needed for this sample.\nSignals required: ACH0 - signal that transitions from below 2V to above.\nCNT0 should have a TTL signal applied.");
	    
		printf ("\n\nStart Trigger Source: Channel 0\n");
		printf ("Waiting for start trigger....\n\n");
		
		printf ("Press any key to quit.\n\n");
   
		GetTextCursor (&Col, &Row);

		/* During the BACKGROUND operation, check the status */
		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 (DAQIFUNCTION)*/
			ULStat = cbGetStatus (BoardNum, &Status, &CurCount, &CurIndex,DAQIFUNCTION);

			/* check the current status of the background operation */
		
			DataIndex = CurIndex;
			if(DataIndex>=0)
				{
					MoveCursor (Col, Row);
					printf ("Triggered!\n\n");
					printf ("\nCollecting data...\n\n");
					printf ("Channel 0   Data point: %3ld   ", DataIndex);
					printf ("  Value: %d  \n",ADData[DataIndex]);
					DataIndex++;
					printf ("FIRSTPORTA  Data point: %3ld   ", DataIndex);
					printf ("  Value: %d  \n",ADData[DataIndex]);
					DataIndex++;
					printf ("Counter 0   Data point: %3ld   ", DataIndex);
					printf ("  Value: %d  ",ADData[DataIndex]);
					
					printf ("\n\nStop Trigger Source: Counter 0 \n");
					if (Status==RUNNING)
						printf ("Waiting for stop trigger...\n");
					else
						printf ("\n\nTriggered!");
				}
			
/*			else
				{
					MoveCursor (Col, Row + 11);
					printf ("\nTriggered!");
				}*/
			
			}

		printf ("\n");
		MoveCursor (Col, Row + 13);
		printf ("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 (DAQIFUNCTION)*/  
    ULStat = cbStopBackground (BoardNum,DAQIFUNCTION);

    cbWinBufFree((int)ADData);
    MoveCursor (1, 22);
    printf ("\n");
}
示例#10
0
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 = 0;
    int Gain = BIP5VOLTS;
    short Status = RUNNING;
    long CurCount;
    long CurIndex;
    long Count = 100000;
    long Rate = 4000;
    HANDLE MemHandle = 0;
    WORD *ADData;
    DWORD *ADData32;
    unsigned Options;
    float revision = (float)CURRENTREVNUM;
    BOOL HighResAD = FALSE;
    int ADRes;
    SamplingThread  samplingThread;
    samplingThread.setInterval( .25 );

   /* 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 */
    samplingThread.setADData(ADData);
    /* 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 */

    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);
//        // check the current status of the background operation */

        if ((Status == RUNNING) && CurCount > 0)
        {
            emit dataPointChanged(CurIndex);
            if(HighResAD)
                emit longDataValueChanged(ADData32[CurIndex]);
            else
                emit shortDataValueChanged(ADData[CurIndex]);
        }
    }




    /* 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)*/
    ULStat = cbStopBackground (BoardNum,AIFUNCTION);

    cbWinBufFree(MemHandle);
}