Measurement Computing   Easy to Use | Easy to Integrate | Easy to Support catalog banner

How to reset or clear a USB-QUAD08 Encoder Channel

Expand / Collapse

How to reset or clear a USB-QUAD08 Encoder Channel

The example program below demonstrates (using C++) how to configure and clear a USB-QUAD08 channel for quadrature encoder input. To use the cbCClear function, you must read the counter input asynchronously using cbCIn32.

 At the bottom of this article you will find a Zip file that contains the Visual Studio 2008 project.

// VC_2008_USB_QUAD08_AsynchronousReadClear.cpp : Defines the entry point for the console application.

#include "stdafx.h"

/* Include files */
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include "cbw.h"

#define MAXNUMDEVS 100

void main ()
   /* Variable Declarations */
   int i=0;
   int ULStat = 0;

   int numberOfDevices = MAXNUMDEVS;
   DaqDeviceDescriptor inventory[MAXNUMDEVS];
   DaqDeviceDescriptor DeviceDescriptor;

   int BoardNum = -1;
   float Rev = (float)CURRENTREVNUM;
   ULStat = cbDeclareRevision(&Rev);
   cbErrHandling(PRINTALL, STOPALL);

   printf ("Demonstration of cbConfigScan() in BACKGROUND mode\n\n");

//Ignore InstaCal device discovery

//locate USB devices
ULStat = cbGetDaqDeviceInventory(USB_IFC, inventory, &numberOfDevices);
for( i = 0; i < numberOfDevices; i++)
DeviceDescriptor = inventory[i];
//Product ID for USB-QUAD08 = 0xCA   
//Product IDs can be found in ULProps.txt located in 
// C:\Program Files (x86)\Measurement Computing\DAQ
if(DeviceDescriptor.ProductID == 0xCA)
BoardNum = i;
ULStat = cbCreateDaqDevice(BoardNum, DeviceDescriptor);
printf("Device Name: %s\n", DeviceDescriptor.ProductName);

   if(BoardNum < 0)
   printf("USB device not any key to exit\n");

   ULStat = cbCConfigScan(BoardNum,
   if(ULStat != 0)
printf("Error Code %d\n",ULStat);
    unsigned long encoderValue;
    int clearCounter = 0;
       //this loop reads the low half of the buffer then the upper half continuously.
       //it uses a NextReadUpper flag so that each half of the buffer is read once

        ULStat = cbCIn32(BoardNum,0,&encoderValue);


        //test clear counter input every 10 seconds 
        if(clearCounter >100) 
            clearCounter = 0;


printf(" any key to exit\n"); 

Rate this Article:


Add Your Comments

For comments email [email protected].

Article ID: 50792

Last Modified:11/5/2019 1:20:41 PM

Article has been viewed 2,120 times.