示例#1
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);
        }
    }
示例#2
0
void usb1208ls_ReadAnalogueOut (acqchanPtr acqchan)
{
    portPtr up = acqchan->upLvl;
    MCCdevPtr dev = acqchan->dev;
    sourcePtr src = up->port.analogueIOport.IO.source;
    float temp;
    unsigned short reading;
    cbFromEngUnits(dev->BoardNum, up->port.analogueIOport.range, src->biaslevel, &reading);
    cbToEngUnits (dev->BoardNum, up->port.analogueIOport.range, reading, &temp);
    acqchan->reading = (double)temp * 4;   // due to bug in MCC!!!
    acqchan->newreading = TRUE;
}
示例#3
0
void usb1208ls_ReadFeedback (acqchanPtr acqchan)
{
    MCCdevPtr dev = acqchan->dev;
    float temp;
    unsigned short reading;
    cbAIn (dev->BoardNum,   0, //channel
                BIP10VOLTS, 
                &reading);
    cbToEngUnits (dev->BoardNum, BIP10VOLTS, reading, &temp);
//  acqchan->reading = src->biaslevel ;
    
    acqchan->reading = (double)temp;
    acqchan->newreading = TRUE;
/*
    acqchan->reading HAS to be the same units and magnitude as the source->biaslevel, or it has to be converted
//*/
}
示例#4
0
/***************************************************************************
*
* Name:     GetTrigCount   
* Arguments: bd - board or device number
*            val - trigger value in engineering units
*            gain - range 
* Returns:   ---
*
* Converts the trigger value in engineerin units to binary counts
*
***************************************************************************/
WORD GetTrigCounts(int bd, int gain, float val)
{
   WORD counts=0;
   float fcounts = 0.0f;
   int FSCounts=0;
   float FSEngUnits=0.0f;
   int ulstat = NOERRORS;

   //test if gain is bipolar or unipolar
   ulstat = cbToEngUnits(bd, gain, FSCounts, &FSEngUnits);
   if (FSEngUnits < 0.0f)
      {
      //'gain' is bipolar
      //now, test bitness
      FSCounts = 0x0fff;  //max 12-bit value
      ulstat = cbToEngUnits(bd, gain, FSCounts, &FSEngUnits);
      if (FSEngUnits<0.0f)
         {
         //must be 16-bit A/D...
         FSCounts = 0xffff;
         ulstat = cbToEngUnits(bd, gain, FSCounts, &FSEngUnits);
         }

      fcounts = (FSCounts/2.0f)*(1.0 + val/FSEngUnits);
      counts = fcounts;
      }
   else
      {
      //'gain' is unipolar
      // now, test bitness...
      FSCounts = 0x0fff; //max 12-bit value
      ulstat = cbToEngUnits(bd, gain, FSCounts, &FSEngUnits);
      ulstat = cbToEngUnits(bd, gain, FSCounts+0x1000, &fcounts);
      if (fcounts >= 2.0f*FSEngUnits)
         {
         //must be 16-bit A/D...
         FSCounts = 0xffff; //max 16-bit value
         ulstat = cbToEngUnits(bd, gain, FSCounts,&FSEngUnits);
         }

      fcounts = FSCounts*val/FSEngUnits;
      counts = fcounts;
      }

   if (counts > FSCounts)
      counts = FSCounts;

   return counts;
}
示例#5
0
文件: ULAI11.C 项目: otoauler/sdkpub
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;
    }
}
示例#6
0
LONG FAR PASCAL
MainMessageHandler(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
    HDC        hDC;                     /* handle for the display device  */
    PAINTSTRUCT ps;                     /* holds PAINT information        */
    TEXTMETRIC tm;                      /* holds TEXT information         */

    static unsigned short *ADValues;    /* Win32 pointer                  */
    static HGLOBAL         MemHandle32;        
    static short           CurStatus;

    static HRGN     hRgn;                   /* Rectangle region Handles       */
    static int      CharWidth, CharHeight;
    static HGLOBAL  MemHandle; 
    int             x, y, i;
    long            Count, Rate;
    char            OutString[80], *str;
    float           Voltage;
    unsigned short  CurValue;


    switch (Message)                    /* Windows Message Loop           */
        {
        case WM_CREATE:
            hDC = GetDC(hWndMain);      /* Get the device context for window */
            GetTextMetrics(hDC, &tm);   /* From context, get size of font */
            CharWidth = tm.tmAveCharWidth;
            CharHeight = tm.tmHeight + tm.tmExternalLeading;
            ReleaseDC(hWndMain, hDC);
            hRgn = CreateRectRgn(0,0, CharWidth*30, CharHeight*20);    

            /* Allocate a Windows buffer */
            MemHandle = cbWinBufAlloc ((long)BUF_SIZE);

            /* WIN32: This code is added to be able access more than  */
            /* 32K words of data.                                     */
            
            /* WIN32: allocate a local WIN32 buffer to hold A/D Data  */
             MemHandle32 = GlobalAlloc(GMEM_FIXED | GMEM_DDESHARE, BUF_SIZE *sizeof(short));
				
            /* Get a 32-bit pointer to the WIN32 buffer */
            ADValues = (unsigned short *)GlobalLock(MemHandle32);
            
            /* Start up A/D scan */
            Count = BUF_SIZE;
            Rate = BUF_SIZE / NUM_SECS;
            cbAInScan (BOARD_NUM, 0, 0, Count, &Rate, ADRANGE, MemHandle,
                       CONVERTDATA);
            break;


        case WM_PAINT:                  /* Repaint client area of window */
            hDC = BeginPaint(hWndMain, &ps);     
            
            x = CharWidth * 2;          /* Position cursor within window */     
            y = CharHeight;             /* One line down and 2 chars in */
            str = "         A/D Info";  /* Print title */
            TextOut(hDC, x, y, str, strlen (str));

			Count = BUF_SIZE;
			/* Copy Data from memory to 32-bit memory buffer */
			cbWinBufToArray( MemHandle, &ADValues[0], 0, Count );

            for (i=0;i<=4;i++)
                {
                CurValue = ADValues[i];
                y       += CharHeight*2;            /* Print raw data value */
                sprintf (OutString,"Raw A/D value(%d) = %u    ", i, CurValue);
                TextOut(hDC, x, y, OutString, strlen (OutString));
                                    
                y       += CharHeight;    /* Convert raw A/D to volts and print */
                cbToEngUnits(BOARD_NUM,ADRANGE,CurValue,&Voltage);
                sprintf (OutString,"Voltage = %.2f    ", Voltage);
                TextOut(hDC, x, y, OutString, strlen (OutString));
                }
                
            SetTextAlign(hDC, TA_LEFT | TA_TOP);
            EndPaint(hWndMain, &ps);
            break;

        case WM_CLOSE:                      /* Close the window */
            DestroyWindow(hWnd);                          
            if (hWnd == hWndMain)
                PostQuitMessage(0);         /* Send message to Quit application */
            if (MemHandle)                  
                cbWinBufFree (MemHandle);   /* Free allocated memory */

			if ( MemHandle32 )
				GlobalFree( MemHandle32 );
			break;

        default:
            return (DefWindowProc(hWnd, Message, wParam, lParam));
        }
    return (0l);
}