Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| daq-and-datalogging:documents:usb-quad08-c-cpp-windows [2023/06/13 16:11] – created Scandiweb | daq-and-datalogging:documents:usb-quad08-c-cpp-windows [2023/07/11 05:16] (current) – Scandiweb | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ====== USB-QUAD08 C/C++ Windows Example |
| - | This app note (PDF file) details configuring the [[ http:// | + | The example program below demonstrates |
| + | It also demonstrates device discovery which doesn' | ||
| + | |||
| + | < | ||
| + | // VC_2008_USB_QUAD08_Encoder.cpp : Defines the entry point for the console application. | ||
| + | // | ||
| + | #include " | ||
| + | |||
| + | |||
| + | /* Include files */ | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include " | ||
| + | |||
| + | #define RATE 100 | ||
| + | #define ChanCount 1 | ||
| + | #define COUNT 100 | ||
| + | #define MAXNUMDEVS 100 | ||
| + | |||
| + | void main () | ||
| + | { | ||
| + | /* Variable Declarations */ | ||
| + | int i=0; | ||
| + | long curCount=0; | ||
| + | long curIndex=0; | ||
| + | |||
| + | int ULStat = 0; | ||
| + | |||
| + | long Rate = RATE; | ||
| + | short Status; | ||
| + | long halfbuf = COUNT/2; | ||
| + | bool NextReadUpper = false; | ||
| + | |||
| + | |||
| + | int numberOfDevices = MAXNUMDEVS; | ||
| + | | ||
| + | | ||
| + | |||
| + | int BoardNum = -1; | ||
| + | |||
| + | float Rev = (float)CURRENTREVNUM; | ||
| + | | ||
| + | | ||
| + | |||
| + | | ||
| + | |||
| + | //Ignore InstaCal device discovery | ||
| + | cbIgnoreInstaCal(); | ||
| + | |||
| + | //locate USB devices | ||
| + | ULStat = cbGetDaqDeviceInventory(USB_IFC, | ||
| + | for( i = 0; i < numberOfDevices; | ||
| + | { | ||
| + | DeviceDescriptor = inventory[i]; | ||
| + | |||
| + | // | ||
| + | // | ||
| + | // C:\Program Files (x86)\Measurement Computing\DAQ | ||
| + | if(DeviceDescriptor.ProductID == 0xCA) | ||
| + | { | ||
| + | BoardNum = i; | ||
| + | ULStat = cbCreateDaqDevice(BoardNum, | ||
| + | printf(" | ||
| + | break; | ||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | | ||
| + | { | ||
| + | | ||
| + | | ||
| + | | ||
| + | } | ||
| + | |||
| + | |||
| + | // | ||
| + | | ||
| + | | ||
| + | | ||
| + | |||
| + | |||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | printf(" | ||
| + | |||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | if (ULStat != 0) | ||
| + | | ||
| + | | ||
| + | |||
| + | // | ||
| + | | ||
| + | 0, | ||
| + | 1, | ||
| + | COUNT, | ||
| + | & | ||
| + | MemHandle, | ||
| + | Options); | ||
| + | if(ULStat != 0) | ||
| + | printf(" | ||
| + | |||
| + | |||
| + | |||
| + | while(!_kbhit()) | ||
| + | { | ||
| + | // | ||
| + | //it uses a NextReadUpper flag so that each half of the buffer is read once | ||
| + | |||
| + | ULStat = cbGetStatus(BoardNum,& | ||
| + | |||
| + | if(ULStat != 0){ | ||
| + | printf(" | ||
| + | break; | ||
| + | } | ||
| + | if((curIndex > halfbuf) && (NextReadUpper == false)) | ||
| + | { | ||
| + | NextReadUpper = true; | ||
| + | //print first value from lower half | ||
| + | printf(" | ||
| + | |||
| + | } | ||
| + | else if((curIndex < halfbuf) && (NextReadUpper == true)) | ||
| + | { | ||
| + | NextReadUpper = false; | ||
| + | //print first value from upper half | ||
| + | printf (" | ||
| + | |||
| + | } | ||
| + | Sleep(100); | ||
| + | |||
| + | } | ||
| + | |||
| + | |||
| + | |||
| + | cbStopBackground(BoardNum, | ||
| + | cbWinBufFree(MemHandle); | ||
| + | cbReleaseDaqDevice(BoardNum); | ||
| + | |||
| + | printf(" | ||
| + | getch(); | ||
| + | } | ||
| + | </ | ||
| **Attachments**\\ | **Attachments**\\ | ||
| - | [[ https:// | + | [[ https:// |

