3.2. Performing an AD Scan

Description

An A/D scan is similar to an A/D sample except that it performs several conversions on a specified range of input channels with each function call. The Universal Driver function for performing an A/D scan is dscADScan.

Step-By-Step Instructions

Create and initialize an A/D settings structure (DSCADSETTINGS).

Call dscADSetSettings and pass it a pointer to this structure in order to setup the driver for A/D operations.

Create and initialize an A/D scan structure (DSCADSCAN).

Create and initialize a sample buffer of type DSCSAMPLE.

Call dscADScan() and pass it a pointer to your scan structure - this will generate an A/D conversion for each channel in your scan range and the results will be stored in the sample_values element of your DSCADSCAN structure.

NOTE: You must always remember to allocate enough memory for your sample buffer (in this case, the WORD sample_values). The driver assumes that your application has allocated at least the amount of memory given in the following formula:

Memory = sizeof(WORD) * ( high_channel - low_channel + 1 )

Example of Usage for A/D Scan

...
DSCCB dsccb = new DSCCB();
DSCADSETTINGS dscadsettings = new DSCADSETTINGS(); 
DSCADSCAN dscadscan = new DSCADSCAN();
DSCUD_Class DSCUD_class = new DSCUD_Library.DSCUD_Class();

/* Step 1 */

dscadsettings.current_channel = 0;
dscadsettings.gain = 0;
dscadsettings.range = 0;
dscadsettings.polarity = 0;
dscadsettings.load_cal = 0;

/* Step 2 */

if ((result = (DSCUD_Library.DSCUD_Class.dscADSetSettings(DSCUD_class.dscb, ref dscadsettings) ) != DSCUD_class.DE_NONE)
return result;

/* Step 3 */
dscadscan.low_channel = 0;
dscadscan.high_channel = 3;

/* Step 4 */

int size = Marshal.SizeOf(ADscan [0]);
IntPtr ADscanarray = Marshal.AllocHGlobal( size * (dscadscan.high_channel - dscadscan.low_channel + 1) );

/* Step 5 */

if ((result =(DSCUD_Library.DSCUD_Class.dscADScan(DSCUD_class.dscb, ref dscadscan, scanarray)) != DSCUD_class.DE_NONE )
	return result;

Last updated