beautypg.com

Foreground acquisition with one-step commands – Measurement Computing TempBook rev.3.0 User Manual

Page 101

background image

TempBook User’s Manual

Enhanced API Programming Models (TempBook) 10-5

Foreground Acquisition with One-Step Commands

This section shows the use of several one-step analog input
routines. These commands are easier to use than low-level
commands but less flexible in scan configuration. These
commands provide a single function call to configure and
acquire analog input data. This example demonstrates the
use of the 4 Daq*’s one-step ADC functions. Functions
used include:

VBdaqAdcRd&(handle&,chan&, sample%,
gain&)

VBdaqAdcRdN&(handle&,chan&, Buf%(),
count&, trigger%, level%, freq!,
gain&,flags&)

VBdaqAdcRdScan&(handle&,startChan&,
endChan&, Buf%(), gain&, flags&)

VBdaqAdcRdScanN&(handle&,startChan&,
endChan&, Buf%(), count&,
triggerSource&, level%, freq!, gain&,
flags&)

This program will initialize the Daq* hardware, then take
readings from the analog input channels in the base unit (not
the expansion cards). First, some constants need to be
defined and variables dimensioned.

Const freq! = 1000!

‘1000Hz sample rate

Const gain& = DgainX1&

‘gain of x1

Const flags& = DafAnalog&+DafUnipolar&

‘unipolar mode on

Const scans& = 9

‘number of scans to acquire

Const channels& = 8

‘number of channels to scan

Const rising& = DatdRisingEdge

‘XXXX I have no idea

Const HYSTERESIS& = 0.1

‘with a hysteresis of .1

Dim buf%(scans& * channels&)

‘array buffer to hold data

Dim handle&

‘handle for TempBook device

Dim i&, j&

‘counter variables

Dim sample%

‘hold a single reading

Dim ret&

‘function return value

The following code assumes that the Daq* device has been successfully opened and the handle& value is
a valid handle to the device. All the following one-step functions define the channel scan groups to be
bipolar input channels. Specifying this configuration uses the DafAnalog and the DafUnipolar values
in the flags parameter. The flags parameter is a bit-mask field in which each bit specifies the
characteristics of the channel(s) specified. In this case, the DafAnalog and the DafUnipolar values
are added together to form the appropriate bit mask for the specified flags parameter.

The next line requests 1 reading from 1 channel with a gain of ×1. The gain& constant is defined as
DgainX1&

, defined constant from DaqX.bas and included at the beginning of this program. Likewise, the

flags&

constant parameter is defined to be the sum of the DafAnalog and DafUnipolar flags, which are

also defined in DaqX.bas.

ret& = VBdaqAdcRd&(handle& 1, sample%, gain&, flags&)
Print Format$“& ####”; “Result of AdcRd:”; sample%(0)

The next line requests 10 readings from channel 1 at a gain of ×1, using immediate triggering at 1 kHz.

ret& = VBdaqAdcRdN&(handle&,1, buf%(), scans&, DatsImmediate&, rising&, 0!,

freq!, gain&, flags&)

Print “Results of AdcRdN: ”;
For x& = 0 To 9

Print Format$ “#### ”; buf%(x&);

Next x&

The program will then collect one sample of channels 1 through 8 using the VBdaqAdcRdScan function.