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

Windows C Program E-1608 Continuous Measurement

Expand / Collapse
 

Windows C Program E-1608 Continuous Measurement


This an example specific to the E-1608. It uses the Discovery interface to locate the E-1608 and program it. Running InstaCal is not necessary but you must have it installed. The program is a simple 32-bit console program created in Visual Studio.  To run the program, create a 32-bit Console project, add the cbw.h and cbw32.dll files to it along with the code file, which is attached at the bottom of this article.

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

#define RATE 100
#define LowChan 0
#define HighChan 4
#define ChanCount 5
#define PACKET 100

#define COUNT PACKET * ChanCount 

#define MAXNUMDEVS 100

void main()
{
/* Variable Declarations */
int i = 0;
int j = 0;
int index = 0;
long curCount, curIndex;

int ULStat = 0;

int Gain = BIP10VOLTS;
long Rate = RATE;
short Status;
long halfbuf = COUNT / 2;
long NumRows = PACKET / 2;
bool NextReadUpper = false;


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

int BoardNum = -1;

float Rev = (float)CURRENTREVNUM;
ULStat = cbDeclareRevision(&Rev);
cbErrHandling(PRINTALL, STOPALL);

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

//Ignore InstaCal device discovery
cbIgnoreInstaCal();

//locate USB devices
ULStat = cbGetDaqDeviceInventory(ANY_IFC, inventory, &numberOfDevices);
for (i = 0; i < numberOfDevices; i++)
{
DeviceDescriptor = inventory[i];

//Product ID for E-1608 = 0x012F
//Product IDs can be found in ULProps.txt located in 
// C:\Program Files (x86)\Measurement Computing\DAQ
if (DeviceDescriptor.ProductID == 0x012F)
{
BoardNum = i;
ULStat = cbCreateDaqDevice(BoardNum, DeviceDescriptor);
printf("Device Name: %s\n", DeviceDescriptor.ProductName);
break;
}

}

if (BoardNum < 0)
{
printf("USB device not found...press any key to exit\n");
getch();
return;
}

cbAInputMode(BoardNum, SINGLE_ENDED);

//allocate buffer
HANDLE MemHandle = 0;
MemHandle = cbScaledWinBufAlloc(COUNT);

double ScaledData[COUNT];

unsigned long RawData[COUNT];  //read counts

unsigned Options= BACKGROUND + CONTINUOUS + SCALEDATA;

ULStat = cbAInputMode(BoardNum, SINGLE_ENDED);
if (ULStat != 0)
printf("%d", ULStat);

// connect a wire from AOUT0 to CH0H to apply 2.5v test voltage
ULStat = cbVOut(BoardNum, 0, BIP10VOLTS, 2.5f, 0);

//Start acquisition
ULStat = cbAInScan(BoardNum,
LowChan,
HighChan,
COUNT,
&Rate,
Gain,
MemHandle,
Options);
if (ULStat != 0)
printf("%d", ULStat);



while (!_kbhit())
{
//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 = cbGetStatus(BoardNum, &Status, &curCount, &curIndex, AIFUNCTION);
if (ULStat != 0){
printf("Error Code %d\n", ULStat);
break;
}
if ((curIndex > halfbuf) && (NextReadUpper == false))
{
NextReadUpper = true;
index = 0;

cbScaledWinBufToArray(MemHandle, ScaledData, 0, halfbuf);


for (j = 0; j< NumRows; j++)
{
for (i = 0; i<ChanCount; i++)
{
printf("%2.3f\t", ScaledData[index++]);
}
printf("\n");
}
}
else if ((curIndex < halfbuf) && (NextReadUpper == true))
{
NextReadUpper = false;
index = 0;
cbScaledWinBufToArray(MemHandle, ScaledData, halfbuf, halfbuf);

for (j = 0; j< NumRows; j++)
{
for (i = 0; i<ChanCount; i++)
{
printf("%2.3f\t", ScaledData[index++]);

}
printf("\n");
}

}
Sleep(1);

}


cbStopBackground(BoardNum, AIFUNCTION);
cbWinBufFree(MemHandle);
cbReleaseDaqDevice(BoardNum);

printf("Completed...press any key to exit\n");
getch();
}



Rate this Article:

Attachments


program.cpp program.cpp (3.42 KB, 24 views)

Add Your Comments


For comments email TechSupport@mccdaq.com.

Details
Article ID: 50851

Last Modified:9/16/2021 9:24:23 AM

Article has been viewed 155 times.

Options