Example #1
0
void main ()
{
    /* Variable Declarations */
    int BoardNum = 0;
    int UDStat = 0;

    /* 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 screen */
    ClearScreen();
    printf ("Demonstration of cbFlashLED()\n");
    printf ("Press any key to quit.\n\n");


    /* collect the sample from the channel until a key is pressed */
    while (!kbhit() && UDStat==NOERRORS)
    {
        /*
        cbFlashLED()
        Parameters:
            BoardNum    :number used by CB.CFG to describe this board
        */
        UDStat = cbFlashLED(BoardNum);
    }
}
bool MeasurementThread::initAcquisitionCard ()
{
	float RevLevel = (float)CURRENTREVNUM;
	cbDeclareRevision(&RevLevel);
	cbErrHandling (PRINTALL, DONTSTOP);
	// calculate maximum buffer size and allocate it
	long DATA_BUF_SIZE = 0;
	for (int i = 0; i < fList.size(); i++)
	{
		long s = calculateBufferSize(i);
		if (s > DATA_BUF_SIZE) DATA_BUF_SIZE = s;
	}
	_data = cbWinBufAlloc (DATA_BUF_SIZE);
	if (_data == 0)
	{
		bool response = createSweepErrorMsg(0, 0, "Cannot allocate memory");
		return response;
	}
	// setup channels
	for (int i = 0; i < cInfo.size(); ++i)
	{
		_ChanArray[i] = cInfo.value(i).ChannelNumber;
		_ChanTypeArray[i] = ANALOG;
                _GainArray[i] = Global::vMaxToGain(cInfo.value(i).Units);

	}
	return true;
}
Example #3
0
void main ()
    {
    /* Variable Declarations */
    int Row,Col;
        int Row2,Col2;
    int BoardNum = 0;
    int UDStat = 0;
    int Chan;
    int Gain = BIP5VOLTS;
    WORD DataValue = 0;
        float    EngUnits;
        float    RevLevel = (float)CURRENTREVNUM;

  /* Declare UL Revision Level */
   UDStat = 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 screen */
    ClearScreen();
    printf ("Demonstration of cbAIn()\n");
    printf ("Press any key to quit.\n\n");

    /* get the A/D channel to sample */
    printf ("Enter the channel to display: ");
    scanf("%i", &Chan);

        printf ("\n\nThe raw data value on Channel %u is: ", Chan);
    GetTextCursor (&Col, &Row);

        printf ("\nThe voltage on Channel %u is:......... ", Chan);
        GetTextCursor (&Col2, &Row2);

    /* collect the sample from the channel until a key is pressed */
    while (!kbhit())
        {
        /*Parameters:
            BoardNum    :number used by CB.CFG to describe this board
            Chan        :input channel number
            Gain        :gain for the board in BoardNum
            DataValue   :value collected from Chan */

        UDStat = cbAIn (BoardNum, Chan, Gain, &DataValue);
        UDStat = cbToEngUnits (BoardNum, Gain, DataValue, &EngUnits);

        MoveCursor(Col, Row);
                printf ("%6u ", DataValue);
                MoveCursor(Col2, Row2);
                printf ("%.2f ", EngUnits);
        }
    }
Example #4
0
void main ()
{
	/* Variable Declarations */
	int Row, Col;
	int BoardNum = 0;
	int ULStat = 0;
	int Chan;
	double frequency;
	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 cbTimerStart() and cbTimerStop()\n\n");
	GetTextCursor (&Col, &Row);

	Chan = 0;
	MoveCursor (0, 7);
	printf ("Enter a frequency between 16 and 1000000 Hz: ");
	MoveCursor (50, 7);
	scanf ("%lf", &frequency);
	ULStat = cbTimerOutStart (BoardNum, Chan, &frequency);
	if(ULStat == NOERRORS)
	{
		printf ("\n  Timer 0 was set to output %.2lf Hz.\n\n", frequency);
		printf ("Press any key to stop the timer:\n ");
		while (!kbhit()){}
		cbTimerOutStop(BoardNum, Chan);
	}
	MoveCursor (1, 20);
	printf ("\n");
}
bool EITMeasurementThread::initAcquisitionCard ()
{
    float RevLevel = (float)CURRENTREVNUM;
    cbDeclareRevision(&RevLevel);
    cbErrHandling (PRINTALL, DONTSTOP);

    _data = cbWinBufAlloc (DATA_BUF_SIZE);
    if (_data == 0)
    {
        bool response = createSweepErrorMsg(0, 0, "Cannot allocate memory");
        return response;
    }
    // setup channels
    for (int i = 0; i < NUM_CHANNELS; ++i)
    {
        _ChanArray[i] = i;
        _ChanTypeArray[i] = ANALOG;
        _GainArray[i] = Global::vMaxToGain(exp->V_MAX);
        //qDebug() << "GainArray[" << i << "] = " << _GainArray[i];
    }
    return true;
}
Example #6
0
void main ()
    {
    /* Variable Declarations */
        int ch;
    int Row, Col;
    int BoardNum = 0;
    int ULStat = 0;
    int Gain = BIP10VOLTS;
	int Options = DEFAULTOPTION;
    int Chan;
    float DataValue;
	int UDStat = 0;
	float min, max;
    
    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 cbVOut()\n\n");

	/* get the D/A channel to sample */
    printf ("Enter the channel to display: ");
    scanf("%i", &Chan);
    

	printf ("\n\nNote: Please make certain that the board you are using supports\n");
    printf ("      the gain you are choosing and if it is not a programmable\n");
    printf ("      gain that the switches on the board are set correctly.\n\n");
    GetTextCursor (&Col, &Row);

	while (Gain > 0 && !kbhit())
        {   
		do
			{ /* select gain */
			MoveCursor(Col,Row);
			printf("Please select one of the following ranges(1 to 4):\n\n");
			printf("                           10 VOLTS UNIPOLAR --> 1\n");
			printf("                           10 VOLTS BIPOLAR ---> 2\n");
			printf("                            5 VOLTS UNIPOLAR --> 3\n");
			printf("                            5 VOLTS BIPOLAR ---> 4\n");
			printf("                                       Quit ---> 0\n\n");
						printf("                                Your Choice ---> ");
			scanf ("%i",&Gain);
			} while ((Gain < 0) || (Gain > 4));

			/* Set Gain, MaxVal, and MinVal */
			switch (Gain)
				{
				case 0:
					exit(1);
				case 1:
					Gain = UNI10VOLTS;
					min=0.0;
					max=10.0;
					break;
				case 2:
					Gain = BIP10VOLTS;
					min=-10.0;
					max=10.0;
					break;
				case 3:
					Gain = UNI5VOLTS;
					min=0.0;
					max=5.0;
					break;
				case 4:
					Gain = BIP5VOLTS;
					min=-5.0;
					max=5.0;
					break;
				default:
					break;
				}

		UDStat = NOERRORS;

		while (UDStat == NOERRORS)
			{
			printf ("\n\nEnter a voltage between %.1f and +%.1f: ", min, max);
			scanf ("%f", &DataValue);
        
			ULStat = cbVOut (BoardNum, Chan, Gain, DataValue, Options);
			if(UDStat == NOERRORS)
				{
					printf ("\n  %.2f volts has been sent to D/A %d.\n\n", DataValue, Chan);
					printf ("Press Q to quit , any other key to continue:\n ");
					while (!kbhit()){}
					ch=getch();
					if (ch=='q' || ch=='Q')
						exit(1);
				}
			}
		}
	}
Example #7
0
void main ()
    {
    /* Variable Declarations */
    int Row, Col;
    int BoardNum = 0;
    int NumChan = 2;
    int ULStat = 0;
    int LowChan, HighChan;
    int Options;
    int Gain = BIP5VOLTS;
    double DAData[NUMCHANS * NUMPOINTS];
    long Count, Rate;
	long CurCount, CurIndex;
	short Status = IDLE;
    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 cbAOutScan() with SCALEDATA option\n\n");
    printf ("Press any key to quit.\n\n\n");
    GetTextCursor (&Col, &Row);

	/* load the output array with values */

	// output (low)
	DAData[0] = 0.0;        
	DAData[1] = 0.0;

	// output (high))
	DAData[2] = 5.0;
	DAData[3] = 5.0;

	LowChan = 0;
    HighChan = 1;

    /* send the output values to the D/A range using cbAOutScan() */
    /* Parameters:
            BoardNum    :the number used by CB.CFG to describe this board
            LowChan     :the lower channel of the scan
            HighChan    :the upper channel of the scan
            Count       :the number of D/A values to send
            Rate        :send rate in values/second
            Gain        :the gain of the D/A
            ADData[]    :array of values to send to the scanned channels
            Options     :data send options  */
    Count = NUMPOINTS * NUMCHANS;
    Rate = 1000;
    Options = BACKGROUND | CONTINUOUS | SCALEDATA;
    ULStat = cbAOutScan (BoardNum, LowChan, HighChan, Count, &Rate, Gain, DAData,
                         Options);

    /* show the results */
    printf ("Here are the output values \n\n");

	printf ("Output(low):   %.8f       %.8f   \n",DAData[0],DAData[1]);
	printf ("Output(high):  %.8f       %.8f   \n\n",DAData[2],DAData[3]);

	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 (AOFUNCTION)*/
        ULStat = cbGetStatus (BoardNum, &Status, &CurCount, &CurIndex,AOFUNCTION);
		printf ("Current Count: %u \n", CurCount);
		printf ("Current Index: %d \n", CurIndex);
		printf ("\nPress any key to quit.\n");
		MoveCursor (Col, Row);
		}
	MoveCursor (Col, Row + 4);
	printf ("\nData output terminated.");

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

}
Example #8
0
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");
}
Example #9
0
MccUSBDAQDevice::MccUSBDAQDevice(ORBManager*    orb_manager, 
							std::string    DeviceName, 
							std::string    Address, 
							unsigned short ModuleNumber,
							int boardNum_, int numADChans_) : 
STI_Device(orb_manager, DeviceName, Address, ModuleNumber), boardNum(boardNum_), numADChans(numADChans_)
{
	//constants for the usb daq physical device
    UDStat = 0;

//    DataValue = 0;
	Options = DEFAULTOPTION;
    // cbw software revision number
    RevLevel = (float)CURRENTREVNUM;

	if (driverMutex != 0)
	{
		driverMutex->lock();
		// Declare UL Revision Level 
		UDStat = 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 (DONTPRINT, DONTSTOP); //must come before evaluating ranges

		//Set whether single-ended or differential.
		int errorCode = cbSetConfig(BOARDINFO, boardNum, 0, BINUMADCHANS, numADChans);
		//Check setting
		errorCode = cbGetConfig (BOARDINFO, boardNum, 0, BINUMADCHANS, &numADChans);

		//numADChans == 0 occurs when the usb daq is not connected. 
		if (numADChans == 0) {
			initialized = false;
			return;
		}

		//Get the number of DA outs
		cbGetConfig (BOARDINFO, boardNum, 0, BINUMDACHANS, &numDAChans);

		driverMutex->unlock();
	}

	if (numDAChans == 0) {
		initialized = false;
		return;
	}

	getChannelInfo();

	if (!availableADInRanges.empty())
		ADInRange = availableADInRanges.begin()->first;
	else
		ADInRange = BIP10VOLTS; //set it to something to avoid complaints. Will be ignored
	if (!availableDAOutRanges.empty())
		DAOutRange = availableDAOutRanges.begin()->first;
	else
		DAOutRange = UNI5VOLTS; //set it to something to avoid complaints. Will be ignored

}
Example #10
0
void main ()
   {
   /* Variable Declarations */
	int			ULStat;
	int			TimeFormat;
	int			TimeZone;
	int			Units;
	int			FileNumber;
	int			Version;
	int			Size;
	int			SampleInterval;
	int			SampleCount;
	int			StartDate;
	int			StartTime;
	int			AICount;
	int			CJCCount;
	int			DIOCount;
	int			StartSample = 0;
	int*		Dates = NULL;
	int*		Times = NULL;
	float*		Analog = NULL;
	int*		Dio = NULL;
	float*		Cjc = NULL;
	char*		postfix;
	char*		SourceDirectory;
	char		AbsolutePath[MAX_PATH];
	char		Filename[MAX_PATH];

    float		RevLevel = (float)CURRENTREVNUM;
	int			i, j;
	int			index;



  /* 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 cbLogReadFile()\n\n");

	/* Get the path to the binary log files */
	SourceDirectory = "..\\..";

	/* Set the preferences 
		Parameters
			TimeFormat	:specifies times are 12 or 24 hour format
			TimeZone	:specifies local time of GMT
			Units		:specifies Fahrenheit, Celsius, or Kelvin
	*/
	TimeFormat = TIMEFORMAT_12HOUR;
	TimeZone = TIMEZONE_LOCAL;
	Units = FAHRENHEIT;
	cbLogSetPreferences(TimeFormat, TimeZone, Units);


    /* Get the name of the first binary log file in the source directory()
        Parameters:
            FileNumber  :the nth file in the directory; or GETFIRST or GETNEXT
            Path[]      :full path to directory containing binary log files
            Filename[]  :receives the full path to the binary log file
	*/
	FileNumber = GETFIRST;
	ULStat = cbLogGetFileName(FileNumber, SourceDirectory, Filename);


	if (ULStat == NOERRORS)
	{
		_fullpath(AbsolutePath, Filename, MAX_PATH);

		/* Get the file information for first binary log file in the directory
			Parameters:
				FileName        :the filename to retrieve information from
				Version         :receives the version information
				Size			:receives the file size information
		*/
		printf ("Calling cbLogGetFileInfo() to get file info for file:  %s\n\n", AbsolutePath);
		ULStat = cbLogGetFileInfo(Filename, &Version, &Size);


		/* Get the sample information for first binary log file in the directory
			Parameters:
				FileName        :the filename to retrieve information from
				SampleInterval  :receives the time between samples
				SampleCount		:receives the number of samples in the file
				StartDate		:receives the start date
				StartTime       :recveives the start time
		*/
		if (ULStat == NOERRORS)
		{
			printf ("Calling cbLogGetSampleInfo() to get sample info for file:  %s\n\n", AbsolutePath);
			ULStat = cbLogGetSampleInfo(Filename, &SampleInterval, &SampleCount, &StartDate, &StartTime);
		}


		/* Get the AI channel count for first binary log file in the directory
			Parameters:
				FileName        :the filename to retrieve information from
				AICount			:receives the number of AI Channels
		*/
		if (ULStat == NOERRORS)
		{
			printf ("Calling cbLogGetAIChannelCount() to get the number of channels logged to the file:  %s\n\n", AbsolutePath);
			ULStat = cbLogGetAIChannelCount(Filename, &AICount);
		}


		/* Get the CJC information for first binary log file in the directory
			Parameters:
				FileName        :the filename to retrieve information from
				CJCCount		:receives the number of CJC Channels
		*/
		if (ULStat == NOERRORS)
		{
			printf ("Calling cbLogGetCJCInfo() to get CJC info for file:  %s\n\n", AbsolutePath);
			ULStat = cbLogGetCJCInfo(Filename, &CJCCount);
		}


		/* Get the DIO information for first binary log file in the directory
			Parameters:
				FileName        :the filename to retrieve information from
				DIOCount		:receives the number of DIO Channels
		*/
		if (ULStat == NOERRORS)
		{
			printf ("Calling cbLogGetDIOInfo() to get DIO info for file:  %s\n\n", AbsolutePath);
			ULStat = cbLogGetDIOInfo(Filename, &DIOCount);
		}


		if (ULStat == NOERRORS)
		{
			/* Allocate the Date and Time arrays and read the data */
			/* Get the date/time information for first binary log file in the directory
				Parameters:
					FileName        :the filename to retrieve information from
					StartSample		:first sample to read
					SampleCount		:number of samples to read
					Dates			:receives the sample dates
					Times			:receives the sample times
			*/
			printf ("Calling cbLogReadTimeTags() to read the TIMESTAMP information from the file:  %s\n\n", AbsolutePath);
			Dates = malloc(SampleCount * sizeof(int));
			Times = malloc(SampleCount * sizeof(int));
			ULStat = cbLogReadTimeTags(Filename, StartSample, SampleCount, Dates, Times);


			/* Allocate the Analog array and read the data*/
			/* Get the Analog information for first binary log file in the directory
				Parameters:
					FileName        :the filename to retrieve information from
					StartSample		:first sample to read
					SampleCount		:number of samples to read
					Analog			:receives the analog data
			*/
			if ( AICount && (ULStat == NOERRORS) )
			{
				printf ("Calling cbLogReadAIChannels() to read the ANALOG data from the file:  %s\n\n", AbsolutePath);
				Analog = malloc(SampleCount * AICount * sizeof(float));
				ULStat = cbLogReadAIChannels(Filename, StartSample, SampleCount, Analog);
			}


			/* Allocate the Dio array and read the data */
			/* Get the DIO information for first binary log file in the directory
				Parameters:
					FileName        :the filename to retrieve information from
					StartSample		:first sample to read
					SampleCount		:number of samples to read
					Dio				:receives the dio data
			*/
			if ( DIOCount && (ULStat == NOERRORS) )
			{
				printf ("Calling cbLogReadAIChannels() to read the DIO data from the file:  %s\n\n", AbsolutePath);
				Dio = malloc(SampleCount * DIOCount * sizeof(int));
				ULStat = cbLogReadDIOChannels(Filename, StartSample, SampleCount, Dio);
			}


			/* Allocate the Cjc array and read the data */
			/* Get the CJC information for first binary log file in the directory
				Parameters:
					FileName        :the filename to retrieve information from
					StartSample		:first sample to read
					SampleCount		:number of samples to read
					Cjc				:receives the cjc data
			*/
			if ( CJCCount && (ULStat == NOERRORS) )
			{
				printf ("Calling cbLogReadAIChannels() to read the CJC data from the file:  %s\n\n", AbsolutePath);
				Cjc = malloc(SampleCount * CJCCount * sizeof(float));
				ULStat = cbLogReadCJCChannels(Filename, StartSample, SampleCount, Cjc);
			}


			if (ULStat == NOERRORS)
			{
				// display the contents of the log file
				for (i=0; i<SampleCount; i++)
				{
					index = i;
					switch (StartTime >> 24)
					{
						case 0:
							postfix = "AM";
							break;
						case 1:
							postfix = "PM";
							break;
						case 0xff:
						default:
							postfix = "";
					}

					printf("%d/%d/%d  ", (Dates[index] >> 8) & 0xff,		// month 
										Dates[index] & 0xff,				// day
										(Dates[index] >> 16) & 0xffff);		// year

					printf("%d:%d:%d %s  ", (Times[index] >> 16) & 0xff,	// hours
										(Times[index] >> 8) & 0xff,			// minutes
										Times[index] & 0xff,				// seconds
										postfix);

					if (Analog)
					{
						index = i * AICount;
						for (j=0; j<AICount; j++)
						{
							printf("%f\t", Analog[index++]);
						}
					}

					if (Cjc)
					{
						index = i * CJCCount;
						for (j=0; j<CJCCount; j++)
						{
							printf("%f\t", Cjc[index++]);
						}
					}

					if (Dio)
					{
						index = i * DIOCount;
						for (j=0; j<DIOCount; j++)
						{
							printf("%d  ", Dio[index++]);
						}
					}
				printf("\n");
				}
			}


			free(Dates);
			free(Times);

			if (Analog)
				free(Analog);

			if (Dio)
				free(Dio);

			if (Cjc)
				free(Cjc);
		}
Example #11
0
void main ()
    {
    /* Variable Declarations */
    int ch;
    int Row, Col;
    int BdNum = 0;
    int DevNum = 0;
    int ConfigVal = 0;
    int ULStat = 0;
    int Gain = BIP10VOLTS;
    int chan, ExitFlag;
    WORD DataValue;
    float volts;

    /* 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);

    

    // Initialize output to ground.
    // Note that the default behavior is to update D/A's immediately
    //  upon cbAOut or cbAOutScan.
    volts = 0.0;
    chan = 0;
    ULStat = cbFromEngUnits(BdNum, Gain, volts, &DataValue);
    ULStat = cbAOut (BdNum, chan, Gain, DataValue);

     
   // Set DAC Update mode to hold off updating D/A's until issued Update Command
   // Parameters
   //   BOARDINFO    : General information about the board
   //   BdNum        : Number used by CB.CFG to describe this board
   //   DevNum       : Selects device; in this case, selects D/A channel to configure
   //                  Note that -1 selects all D/A channels
   //   BIDACUPDATEMODE : Selects update mode for D/A, whether immediately (via cbAOut
   //                    or cbAOutScan) or upon issuing BIDACUPDATECMD
   //   UPDATEONCOMMAND : Delay D/A output updates from cbAOut or cbAOutScan until
   //                     BIDACUPDATECMD is issued.
    DevNum = ALLDEVICES;
    ULStat = cbSetConfig(BOARDINFO, BdNum, DevNum, BIDACUPDATEMODE, UPDATEONCOMMAND);

    ExitFlag = FALSE;
   
   while (!ExitFlag)
      {
      // Set up the display screen 
      ClearScreen();
      printf ("Demonstration of DAC Update Modes with cbAOut()\n\n");
      GetTextCursor (&Col, &Row);
      MoveCursor (0, 3);

      printf ("Enter a voltage between -10.0 and +10.0: ");
      MoveCursor (41, 3);

      if (0==scanf ("%f", &volts))
      {
         printf("Error : Invalid entry.");
         break;
      }
        
      ULStat = cbFromEngUnits(BdNum, Gain, volts, &DataValue);
      ULStat = cbAOut (BdNum, chan, Gain, DataValue);
     
      printf ("\n  %.2f volts has been sent to D/A 0.\n\n", volts);
       

      printf ("Press U to update D/A output, Q to quit, \n or any other key to continue:\n ");
      while (!kbhit()){}
   
      ch=getch();
      if (ch=='q' || ch=='Q')
         ExitFlag=TRUE;
      else if (ch=='u' || ch=='U')
         {
         // Issue command to update all the D/A's with the last value written
         //   to them via cbAOut or cbAOutScan
         //
         // Parameters
         //   BOARDINFO   : General information about the board
         //   BdNum       : Number used by CB.CFG to describe this board
         //   DevNum      : Not used for BIDACUPDATECMD
         //   BIDACUPDATECMD : Update D/A outputs with last value written
         //   ConfigVal   : Note used for BIDACUPDATECMD 
         DevNum = NOT_USED;
         ConfigVal = NOT_USED;
         ULStat = cbSetConfig(BOARDINFO, BdNum, DevNum, BIDACUPDATECMD, ConfigVal);
         printf("\nD/A output 0 has been updated.    ");
         }
      else
         printf("\nD/A output 0 has not been updated!");
      }

    printf ("\n");
}
Example #12
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");
}
Example #13
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");
}
Example #14
0
void main ()
   {
   /* Variable Declarations */
   int Row, Col, I, J;
   int BoardNum = 0;
   int ULStat = 0;
   int FirstCtr = 0;
   int LastCtr = 1;
   long Count = 20;
   long Rate = 10;
   DWORD CounterData[20];
   unsigned Options;
   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 cbCInScan() in FOREGROUND mode\n\n");

    /* Collect the values with cbCInScan()
        Parameters:
            BoardNum    :the number used by CB.CFG to describe this board
            FirstCtr    :first counter of the scan
            LastCtr     :last of the scan
            Count       :the total number of counter samples to collect
            Rate        :sample rate in samples per second
            DataBuffer[]:the array for the collected data values
            Options     :data collection options */

    Options = DEFAULTIO | CTR32BIT;
    ULStat = cbCInScan (BoardNum, FirstCtr, LastCtr, Count, &Rate,
                                            CounterData, Options);

    ClearScreen();
    printf ("Demonstration of cbCInScan() in FOREGROUND mode\n\n");

    /* display the data */
    for (J = 0; J < 2; J++)       /* loop through the channels */
        {
        printf ("\nThe first 5 values on Channel %u are ", J);
        GetTextCursor (&Col, &Row);

        for (I = 0; I < 5; I++)   /* loop through the values & print */
            {
            MoveCursor (Col, Row + I);
            printf ("%4u", CounterData[ I * 2 + J]);
            }
        printf ("\n");
        }
}
Example #15
0
void main ()
{
    int i, x, StartY, ULStat, FirstPoint, BlockNum, BoardNum;
    long Count;
    WORD DataBuffer1[NUMPOINTS];
    WORD DataBuffer2[NUMPOINTS];
    float    RevLevel = (float)CURRENTREVNUM;

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

    /*  Initiate error handling to automatically trap and report errors
        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 cbMemRead() and cbMemWrite()\n");
    printf ("\n");
    printf ("This program writes 500 values to the memory board by writing\n");
    printf ("5 blocks of 100 values to consecutive locations in the memory board.\n");
    printf ("\n");
    printf ("The values that are written correspond to the memory board address that\n");
    printf ("they are stored at.  So for example the value 203 is stored at address 203\n");
    printf ("in memory.\n");
    printf ("\n");
    printf ("It then reads the data back and displays it.\n");

    Count = NUMPOINTS;
    FirstPoint = 0;                     /* Set address of first point to write */
    for (BlockNum=0; BlockNum<NUMBLOCKS; BlockNum++)
        {
        /* Fill up the array with ascending data */
        for (i=0; i<NUMPOINTS; i++)
            {
            DataBuffer1[i] = (WORD)(BlockNum * NUMPOINTS + i);
            DataBuffer2[i] = 0;
            }

        /* Write the block to the memory board
              MEMBOARD - Board number of the memory board
              DataBuffer1 - Array of data to be written
              FirstPoint - Address to write first point (or NEXTONE)
              NUMPOINTS - Number of points to write */
              BoardNum = MEMBOARD;
        ULStat = cbMemWrite (BoardNum, DataBuffer1, FirstPoint, Count);
        FirstPoint = FROMHERE;
        }

    printf ("\n");
    printf ("Address=   0        100       200       300       400\n");
    printf ("         ------    ------    ------    ------    ------\n");
    GetTextCursor (&x, &StartY);
    FirstPoint = 0;                     /* Set address of first point to read */
    for (BlockNum=0; BlockNum<NUMBLOCKS; BlockNum++)
        {
        /* Read a block of data from  the memory board
              MEMBOARD - Board number of the memory board
              DataBuffer2 - Array of data to read data into
              FirstPoint - Address to read first point (or FROMHERE)
              NUMPOINTS - Number of points to read */
        ULStat = cbMemRead (BoardNum, DataBuffer2, FirstPoint, Count);
        FirstPoint = FROMHERE;

        /* Print the data */
        for (i=0; i<5; i++)
            {
            MoveCursor (BlockNum*10+10, StartY+i);
            printf ("%u\n", DataBuffer2[i]);
            }
        }
}
Example #16
0
void main ()
   {
   /* Variable Declarations */
   int I;
   int BoardNum = 0;
   int ULStat = 0;
   int FirstCtr = 0;
   int LastCtr = 0;
   int CounterNum, MapChannel;
   int Mode,DebounceTime, DebounceMode, EdgeDetection, TickSize;

   long Count = 50;
   long Rate = 10;
   DWORD CounterData[50];
   unsigned Options;

   /* 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 cbCInScan() in FOREGROUND mode\n\n");

	/*Setup Counters
		 Parameters:
         BoardNum       :the number used by CB.CFG to describe this board
			CounterNum     :counter to set up
			Mode           :counter mode
			DebounceTime   :debounce time
			DebounceMode   :debounce mode
			EdgeDetection  :determines whether the rising edge or falling edge is to be detected
			TickSize       :reserved.
			MapChannel     :mapped channel*/


	//Setup Counter 0 (Phase A signal)

	CounterNum = 0;
	Mode = ENCODER | ENCODER_MODE_X1 | CLEAR_ON_Z_ON;
	DebounceTime = CTR_DEBOUNCE_NONE;
	DebounceMode = 0;
	EdgeDetection = CTR_RISING_EDGE;
	TickSize = 0;
	MapChannel = 2;

	ULStat = cbCConfigScan(BoardNum, CounterNum, Mode, DebounceTime, DebounceMode, EdgeDetection, TickSize, MapChannel);


    /* Collect the values with cbCInScan()
        Parameters:
            BoardNum    :the number used by CB.CFG to describe this board
            FirstCtr    :first counter of the scan
            LastCtr     :last counter of the scan
            Count       :the total number of counter samples to collect
            Rate        :sample rate in samples per second
            DataBuffer[]:the array for the collected data values
            Options     :data collection options */

    Options = CTR32BIT;
    ULStat = cbCInScan (BoardNum, FirstCtr, LastCtr, Count, &Rate,
                                            CounterData, Options);

	ClearScreen();
    printf ("Demonstration of cbCInScan() in FOREGROUND mode\n\n");
	 printf (" Counter Data\n\n");
    /* display the data */
    for (I = 0; I < Count; I++)       /* loop through the channels */
        {
        printf("%8u\n", CounterData[I]);
        }
        
}
Example #17
0
void main ()
{
    /* Variable Declarations */
    int BoardNum = 0;
    int ULStat = 0;
    short LowChan = 0;
    short HighChan = 0;
    int Gain = BIP5VOLTS;
    long Count,TotalCount;
    long PreTrigCount;
    long NumPoints = 128000;
    long Rate;
    int Options;
    char *FileName;
    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 cbFileAInScan()\n");

    /* set up the collection parameters */
    Count = NumPoints;
    FileName = "DEMO.DAT";
    Rate = 50000;                     /* sampling rate (samples per second) */
    LowChan = 0;
    HighChan = 1;
    Options = TIMED + NODTCONNECT;
    Gain = BIP5VOLTS;

    printf ("Collecting %4ld data points...\n\n", NumPoints);
    printf ("Rate     = %ld Hz\n", Rate);
    printf ("LowChan  = %u\n", LowChan);
    printf ("HighChan = %u\n", HighChan);
    printf ("Options  = %u\n", Options);
    printf ("Gain     = %u\n", Gain);
    printf ("FileName = %s\n", FileName);
    printf ("Count    = %ld\n", Count);

    /* Collect the values with cbFileAInScan()
      Parameters:
        BoardNum   :the number used by CB.CFG to describe this board
          LowChan    :first A/D channel of the scan
          HighChan   :last A/D 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
          FileName   :the filename for the collected data values
          Options    :data collection options  */
    ULStat = cbFileAInScan (BoardNum, LowChan, HighChan, Count, &Rate, Gain, FileName, Options);

    printf ("\n%4ld data points were placed in the file: %s.\n\n", Count, FileName);
    ULStat = cbFileGetInfo (FileName, &LowChan, &HighChan, &PreTrigCount, &TotalCount, &Rate, &Gain);

    printf ("Rate     = %ld Hz\n", Rate);
    printf ("LowChan  = %u\n", LowChan);
    printf ("HighChan = %u\n", HighChan);
    printf ("Options  = %u\n", Options);
    printf ("Gain     = %u\n", Gain);
    printf ("FileName = %s\n", FileName);
    printf ("Count    = %ld\n", TotalCount);
}
Example #18
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);
}
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)*/

}
Example #20
0
void main ()
    {
    /* Variable Declarations */
    int I;
    int ULStat;
    int BoardNum = 0;
    long TotalCount = 128000;
    long PreTrigCount = 2000;
    long Rate=50000;
    long FirstPoint, NumPoints;
    short HighChan, LowChan;
    int Options, Gain;
    char *FileName;

    WORD DataBuffer[10];
    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 File Operations \n");
    printf ("using cbFilePretrig%() and cbFileGetInfo%().\n\n");

    printf ("The trigger input line (D0) must be held low before this demo is started.\n\n");
    while (!kbhit())
        {;}

    printf ("\n\nRelease D0 when ready:\n\n");

    FileName = "DEMO.DAT";
    LowChan = 0;
    HighChan = 1;
    Options = 0;
    Gain = BIP5VOLTS;

    printf ("Collecting %4ld data points...", TotalCount);

    /* Collect the values with cbFileAInScan()
       Parameters:
            BoardNum     :the number used by CB.CFG to describe this board
            LowChan      :first A/D channel of the scan
            HighChan     :last A/D channel of the scan
            PreTrigCount :the total number of A/D samples to collect
            TotalCount   :the total number of samples to store to file
            Rate         :sample rate in samples per second
            Gain         :the gain for the board
            FileName   :the filename for the collected data values
            Options    :data collection options */

    ULStat = cbFilePretrig(BoardNum, LowChan, HighChan, &PreTrigCount, &TotalCount, &Rate, Gain, FileName, Options);

    printf ("which were placed in the file: %s.\n", FileName);

    /* show the information in the file header with cbFileGetInfo()
       Parameters:
          FileName      :the filename containing the data
          LowChan       :first A/D channel of the scan
          HighChan      :last A/D channel of the scan
          PreTrigCount  :the number of pretrigger samples in the file
          TotalCount    :the total number of A/D samples in the file
          Rate          :sample rate in samples per second
          Gain          :the gain at which the samples were collected */

    ULStat = cbFileGetInfo (FileName, &LowChan, &HighChan, &PreTrigCount, &TotalCount, &Rate, &Gain);

    printf ("\nThe information in the file header is:\n");
    printf ("     Streamer File Name        =  %s\n", FileName);
    printf ("     Low Channel               =     %1u\n", LowChan);
    printf ("     High Channel              =     %1u\n", HighChan);
    printf ("     No. of Pretrigger samples =  %4ld\n", PreTrigCount);
    printf ("     No. of Samples            =  %4ld\n", TotalCount);
    printf ("     Collection Rate (Hz)      =  %4ld\n", Rate);
    printf ("     Gain                      =   %3u\n", Gain);


    /* show the data using cbFileRead()
       Parameters:
          FileName      :the filename containing the data
          NumPoints     :the number of data values to read from the file
          FirstPoint    :index of the first data value to read
          DataBuffer[]   :array to read data into  */

    NumPoints = 10;     /* read 10 points in the file */
    FirstPoint = PreTrigCount-4;     /* start at the trigger - 4 */
    ULStat = cbFileRead (FileName, FirstPoint, &NumPoints, DataBuffer);

    /* display the data values read from the file */
    printf ("\nThe five points before and after the trigger are:\n");
    for (I = 0; I < (int)NumPoints; I++)
        printf ("     %2u) %4u  \n", I, DataBuffer[I]);
}
Example #21
0
void main ()
    {
    /* Variable Declarations */
    char TrigKind;
    int Row, Col;
    int BoardNum = 0;
    int ULStat = 0;
    int Chan, Gain;
    WORD DataValue;
    int TrigType;
    WORD TrigValue;
    float EngUnits;
    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 cbATrig()\n\n");
    GetTextCursor (&Col, &Row);

    MoveCursor (Col, Row + 1);
    printf ("Enter the channel to display:      ");
    MoveCursor (Col + 31, Row + 1);
    scanf ("%i", &Chan);
    MoveCursor (Col, Row + 3);
    printf ("Enter the threshold value (-5 to +5V):     ");
    MoveCursor (Col + 39, Row + 3);
    scanf ("%f", &EngUnits);

   /* convert voltage to counts */
   Gain = BIP5VOLTS;
   

   TrigValue = GetTrigCounts(BoardNum, Gain, EngUnits);

    /* if the value is not at the extremes, ask which side to trigger */
    MoveCursor (Col, Row + 5);
    printf ("Should the data value be ABOVE or BELOW this threshold (A/B): ");
    TrigKind = (char)getch();
    MoveCursor (Col + 62, Row + 5);
    printf ("%c", TrigKind);

    switch (TrigKind)
        {
        case 'A':
        case 'a':
            TrigType = TRIGABOVE;
            break;
        case 'B':
        case 'b':
            TrigType = TRIGBELOW;
            break;
        default:
            break;
        }

    /* monitor the channel with cbATrig()
        Parameters:
            BoardNum    :the number used by CB.CFG to describe this board
            Chan        :the input channel number
            TrigType    :specifies whether the trigger is to be above or
                         below TrigValue
            TrigValue   :the threshold value that will cause the trigger
            Gain        :the gain value
            DataValue   :the input value read from Chan */

    MoveCursor (Col , Row + 7);
    printf ("Waiting for the trigger value...");

    ULStat = cbATrig (BoardNum, Chan, TrigType, TrigValue, Gain, &DataValue);

    MoveCursor (Col, Row + 9);
    printf ("The value that caused the trigger was %u ", DataValue);

    MoveCursor (1, 20);
    printf ("\n");
}
Example #22
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");

    }
Example #23
0
void main ()
{
    /* Variable Declarations */
    int Row,Col;
    int BoardNum = 0;
    int ULStat = 0;
    int Chan;
    int Gain = BIPPT625VOLTS;
    WORD DataValue = 0;
    float EngUnits;
    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 screen */
    ClearScreen();
    printf ("Demonstration of voltage conversions.\n\n");

    /* get the A/D channel to sample */
    printf ("Enter the channel to display: ");
    scanf("%d", &Chan);

    printf ("\n\nNote: Please make certain that the board you are using supports\n");
    printf ("      the gain you are choosing and if it is not a programmable\n");
    printf ("      gain that the switches on the board are set correctly.\n\n");
    GetTextCursor (&Col, &Row);

    /* collect the sample with cbAIn() */
    while (Gain > 0)
    {
        do
        {   /* select gain */
            MoveCursor(12,10);
            printf("Please select one of the following ranges(1 to 4):\n\n");
            printf("                           10 VOLTS UNIPOLAR --> 1\n");
            printf("                           10 VOLTS BIPOLAR ---> 2\n");
            printf("                            5 VOLTS UNIPOLAR --> 3\n");
            printf("                            5 VOLTS BIPOLAR ---> 4\n");
            printf("                                       Quit ---> 0\n\n");
            printf("                                Your Choice ---> ");
            scanf ("%i",&Gain);
        } while ((Gain < 0) || (Gain > 4));

        /* Set Gain, MaxVal, and MinVal */
        switch (Gain)
        {
        case 0:
            exit(1);
        case 1:
            Gain = UNI10VOLTS;
            break;
        case 2:
            Gain = BIP10VOLTS;
            break;
        case 3:
            Gain = UNI5VOLTS;
            break;
        case 4:
            Gain = BIP5VOLTS;
            break;
        default:
            break;
        }

        /*Parameters:
            BoardNum    :number used by CB.CFG to describe this board
            Chan        :input channel number
            Gain        :gain for the board in BoardNum
            DataValue   :value collected from Chan */

        if (Gain >= 0)
        {
            ULStat = cbAIn (BoardNum, Chan, Gain, &DataValue);
            ULStat = cbToEngUnits(BoardNum, Gain, DataValue, &EngUnits);

            printf ("\nThe voltage on channel %d is %.2f ", Chan, EngUnits);
        }
        Gain = BIPPT625VOLTS;
    }
}
Example #24
0
void main ()
{
    /* Variable Declarations */
    int Row, Col;
    int BoardNum = 0;
    int ULStat = 0;
    int CounterNum;
    int RegName;
    int Config;
    int LoadValue;
    WORD Count;
    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 8254 Counter Functions.\n\n");
    printf ("NOTE: There must be a TTL freq. at cntr. 1 input.\n\n");
    printf ("Press any key to quit.\n\n\n");

    /* configure the counter for desired operation
        Parameters:
            BoardNum    :the number used by CB.CFG to describe this board
            CounterNum  :the counter to be setup
            Config      :the operation mode of counter to be configured */
    CounterNum = 1;
    Config = HIGHONLASTCOUNT;
    ULStat = cbC8254Config (BoardNum, CounterNum , Config);

    /* Send a starting value to the counter 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 = 1000;
    RegName = LOADREG1;
    ULStat = cbCLoad (BoardNum, RegName, LoadValue);

    /* use a loop to keep checking the counter value with cbCIn() */
    GetTextCursor (&Col, &Row);

    while (!kbhit())
    {
        /* Parameters:
            BoardNum    :the number used by CB.CFG to describe this board
            CounterNum  :the counter to be setup
            Count       :the count value in the counter */
        ULStat = cbCIn (BoardNum, CounterNum, &Count);

        MoveCursor (Col, Row + 1);
        printf ("The value of Counter %u is %u     ", CounterNum, Count);
    }

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

}
Example #25
0
int PASCAL
WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR CmdLine, int nCmdShow)
{
    MSG       msg;                      /* MSG structure to pass to windows proc */
    WNDCLASS  wndclass;
    char      *AppName;                 /* Name for the window */

    cbErrHandling (PRINTALL, STOPALL);  /* Set library's error handling */

    CmdLine = NULL;                     /* Not used */
    AppName = "WINCDEMO";               /* The name of this application */
    if(!hPrevInstance)
        {
        wndclass.style      = CS_HREDRAW | CS_VREDRAW;
        wndclass.lpfnWndProc= MainMessageHandler;
        wndclass.cbClsExtra = 0;
        wndclass.cbWndExtra = 0;
        wndclass.hInstance  = hInstance;
        wndclass.hIcon      = LoadIcon (hInstance, AppName);
        wndclass.hCursor    = LoadCursor (NULL, IDC_ARROW);
        wndclass.hbrBackground  = GetStockObject (WHITE_BRUSH);
        wndclass.lpszMenuName   = AppName;
        wndclass.lpszClassName  = AppName;
        RegisterClass (&wndclass);
        }

    /* create application's Main window                                    */
    hWndMain = CreateWindow (AppName,                  /* Window class name          */
                             "AInScan Foreground",
                             WS_OVERLAPPEDWINDOW,
                             CW_USEDEFAULT,           /* Use default X, Y            */
                             CW_USEDEFAULT,           /* Use default X, Y            */
                             GetSystemMetrics(SM_CXSIZE) * 12,   /* x - fit text      */
                             GetSystemMetrics(SM_CYSIZE) * 20,  /* y - fit text      */
                             NULL,                    /* Parent window's handle      */
                             NULL,                    /* Default to Class Menu       */
                             hInstance,               /* Instance of window          */
                             NULL);                   /* Create struct for WM_CREATE */


    if (hWndMain == NULL)
        {
        MessageBox(NULL, "Could not create window in WinMain", NULL, MB_ICONEXCLAMATION);
        return (1);
        }

    ShowWindow(hWndMain, nCmdShow);     /* Display main window      */
    UpdateWindow(hWndMain);

    /* Start a 500ms timer to update display */
//    if(!SetTimer(hWndMain, TIMER_NUM, 500, NULL))
//        {
//        MessageBox(NULL, "Error starting Windows timer", NULL, MB_OK |
//                   MB_ICONEXCLAMATION);
 //       return (1);
 //       }                          
        
    while(GetMessage(&msg, NULL, 0, 0)) /* Main message loop */
        {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
        }

    UnregisterClass (AppName, hInstance);
    return (msg.wParam);
}