コード例 #1
0
DCMotorCommand::DCMotorCommand(void)
{
	numMotors = 7;
	BoardNumVoltage = 0;
	Options = DEFAULTOPTION;
	voltageGain = UNI10VOLTS;
	minVoltage = 0.0;
	maxVoltage = 2.0;
	bIsAmplifiersOn = false;
	
	// Initializing VoltageOut modules
	for(int i = 0; i < numMotors; i++) {
		cbVOut(BoardNumVoltage, 2 * i, voltageGain, 0, Options);
	}

	// Configuring Digital Outputs
	cbDConfigPort(BoardNumVoltage, 1, DIGITALOUT);
	cbDOut(BoardNumVoltage, 1, 0);

}
コード例 #2
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");
}
コード例 #3
0
ファイル: DaqInScan02.C プロジェクト: mikanradojevic/sdkpub
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");
}
コード例 #4
0
ファイル: digCodeOrig.c プロジェクト: ryekelly/Ex
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    int i;
    int boardNum = 0;
    int ULStat;
    int lowPort,highPort,strobePort;
    LARGE_INTEGER frequency;        // ticks per second
    double* doubleData;
    mxChar * charData;
    double waitTimeMS1,waitTimeMS2;

    /* These variables set the lag between bit flips (ms) */
    /* 20-50 uS is the range needed for the Ripple system */
    /* faster than that will likely cause dropped codes */
    waitTimeMS1 = 0.050; /* between setting bits and the strobe */
    waitTimeMS2 = 0.050; /* between setting the strobe to 1 and back to 0 */

    // get ticks per second
    QueryPerformanceFrequency(&frequency);

    lowPort = FIRSTPORTA;
    highPort = FIRSTPORTB;
    strobePort = FIRSTPORTC;

    ULStat = cbDConfigPort (boardNum, lowPort, DIGITALOUT);
    ULStat = cbDConfigPort (boardNum, highPort, DIGITALOUT);
    ULStat = cbDConfigPort (boardNum, strobePort, DIGITALOUT);

    if (nrhs > 0)
    {
        switch (mxGetClassID(prhs[0]))
        {
        case mxDOUBLE_CLASS:
            doubleData = mxGetPr(prhs[0]);

            for (i = 0; i < mxGetNumberOfElements(prhs[0]); i++)
            {
                ULStat = cbDOut(boardNum, lowPort, ((int)doubleData[i]) % 256);
                ULStat = cbDOut(boardNum, highPort, ((int)doubleData[i]) / 256);
                waitMS(waitTimeMS1,frequency);
                ULStat = cbDOut(boardNum, strobePort,1);
                waitMS(waitTimeMS2,frequency);
                ULStat = cbDOut(boardNum, strobePort,0);
            }
            break;
        case mxCHAR_CLASS:
            charData = (mxChar*)mxGetData(prhs[0]);

            for (i = 0; i < mxGetNumberOfElements(prhs[0]); i++)
            {
                ULStat = cbDOut(boardNum, lowPort, charData[i]);
                waitMS(waitTimeMS1,frequency);
                ULStat = cbDOut(boardNum, strobePort, 1);
                waitMS(waitTimeMS2,frequency);
                ULStat = cbDOut(boardNum, strobePort, 0);
            }
            break;
        default:
            mexPrintf("Sorry, this data type cannot be transmitted.\n");
            mexEvalString("drawnow;");
        }
    }

    return;
}