Gx3788AnalogInScanStart

Purpose

Starts an analog in scan operation.

Syntax

Gx3788AnalogInScanStart (nHandle, nScanMode, dwMemoryStart, pnStatus)

Parameters

Name
Type
Comments
nHandle
SHORT
Handle to a GX3788 board.
nScanMode
SHORT
Sets the scan operation mode:
0.      GX3788_ANALOG_IN_SCAN_MODE_SYNCHRONOUS: In synchronous mode, the function does not return until the requested number of samples are done or time out conditions occurs.
1.    GX3788_ANALOG_IN_SCAN_MODE_ASYNCHRONOUS: In asynchronous mode, the function returns immediately after being called. The user needs to use the Gx3788AnalogInScanIsRunning() API to find out when the scan operation is done.
dwMemoryStart
DWORD
Sets the address in scan sample memory to start from, the scan sample memory range is 0 to 4095.
pnStatus
PSHORT
Returned status: 0 on success, negative number on failure.

Comments

The function starts an analog in scan operation. The scan memory is a circular buffer. If your sample count exceeds the memory limit of 4096 samples, the scan memory pointer will begin overwriting data at address 0.  For example, if your memory start address is 4000 and your sample count is 200, your data will be written to addresses 4000 to 4095 and addresses 0 to 103.

Example

This example requires the Analog Out channels 0 - 4 are connected to Analog In single ended 0 - 4.

The example does the following:

1.    Set the analog out of channel 0-4.

2.    Set channel 0-15 Ground Source to analog ground.

3.    Set Count to 10, each channel will be measured twice.

4.    Set sample rate to 5KHz.

5.    Load the channel scan list to the board.

6.    Read back and verify the channel scan list.

7.    Measure in Synchronous mode, and measurements will be stored in scan memory starting at address 0.

8.    Verify scan operation is done.

9.    Read and print the 10 measurements from the scan memory.

 

dwChannelCount=5;

// Set the analog out of channel 0-4

for (nChannel = 0; nChannel < 5; nChannel++)

{    Gx3788AnalogOutSetVoltage(nHandle, nChannel, adOutputVoltages[nChannel],

                                &nStatus);

     CheckStatus(nStatus);

}

// Set channel 0-7 Ground Source to analog ground

Gx3788AnalogInSetGroundSource(nHandle, GX3788_ANALOG_IN_CHANNELS_0_7,

                                GX3788_ANALOG_IN_ANALOG_GND, &nStatus);

// Set channel 8-15 Ground Source to analog ground

Gx3788AnalogInSetGroundSource(nHandle, GX3788_ANALOG_IN_CHANNELS_8_15,

                                GX3788_ANALOG_IN_ANALOG_GND, &nStatus);

// Set Count to 10, each channel will be measured twice

dwScanCount = dwChannelCount * 2;

Gx3788AnalogInScanSetCount(nHandle, dwScanCount, &nStatus);

// Set sample rate to 5KHz

Gx3788AnalogInScanSetSampleRate(nHandle, 5000, &nStatus);

// load the channel scan list to the board

for (dwListIndex = 0, dwScanChannel = 0; dwScanChannel < dwChannelCount;

    dwListIndex++, dwScanChannel++)

{

    // mark the last channel in the list

    if (dwScanChannel == (dwChannelCount - 1))

    {    Gx3788AnalogInScanSetChannelListIndex(nHandle, dwListIndex, dwScanChannel,

        GX3788_ANALOG_IN_RANGE_NEG_10p24V_TO_POS_10p24V, GX3788_ANALOG_IN_SINGLE_ENDED,

        true, &nStatus);

    }

    else

    {   Gx3788AnalogInScanSetChannelListIndex(nHandle, dwListIndex, dwScanChannel,

        GX3788_ANALOG_IN_RANGE_NEG_10p24V_TO_POS_10p24V, GX3788_ANALOG_IN_SINGLE_ENDED,

        false, &nStatus);

    }

}

// read back and verify the channel scan list

for (dwListIndex = 0; dwListIndex < dwChannelCount; dwListIndex++)

{

    Gx3788AnalogInScanGetChannelListIndex(nHandle, dwListIndex, &dwScanChannel, &nRange,

    &nMode, &bIsLastChannel, &nStatus);

    // verify range

    if (nRange == GX3788_ANALOG_IN_RANGE_NEG_13p60V_TO_POS_13p60V)

        printf("Scan Channel %i analog in voltage rang is ±13.60V\r\n", dwScanChannel);

    else if (nRange == GX3788_ANALOG_IN_RANGE_NEG_10p24V_TO_POS_10p24V)

        printf("Scan Channel %i analog in voltage rang is ±10.24V\r\n", dwScanChannel);

    else if (nRange == GX3788_ANALOG_IN_RANGE_NEG_5p12V_TO_POS_5p12V)

        printf("Scan Channel %i analog in voltage rang is ±5.12V\r\n", dwScanChannel);

    else if (nRange == GX3788_ANALOG_IN_RANGE_NEG_2p56V_TO_POS_2p56V)

        printf("Scan Channel %i analog in voltage rang is ±2.56V\r\n", dwScanChannel);

    else if (nRange == GX3788_ANALOG_IN_RANGE_NEG_1p28V_TO_POS_1p28V)

        printf("Scan Channel %i analog in voltage rang is ±1.28V\r\n", dwScanChannel);

    else if (nRange == GX3788_ANALOG_IN_RANGE_NEG_0p64V_TO_POS_0p64V)

        printf("Scan Channel %i analog in voltage rang is ±0.64V\r\n", dwScanChannel);

    else

        printf("Channel %i invalid analog in voltage range\r\n", dwScanChannel);

    // verify analog in Differential or Single Ended

    if (nMode == GX3788_ANALOG_IN_DIFFERENTIAL)

        printf("Scan Channel %i Analog Input Mode Differential\r\n",

                dwScanChannel);

    else if (nMode == GX3788_ANALOG_IN_SINGLE_ENDED)

        printf("Scan Channel %i Analog Input Mode Single Ended\r\n",

                dwScanChannel);

    else

        printf("Scan Channel %i invalid Analog Input Mode\r\n", dwScanChannel);

    // verify last channel

    if (bIsLastChannel == TRUE)

        printf("Scan Channel %i is the Last Channel\r\n", dwScanChannel);

    else

        printf("Scan Channel %i is not the Last Channel\r\n", dwScanChannel);

}

// Measure in Synchronous mode, and measurements will be stored in scan memory

// starting at address 0

Gx3788AnalogInScanStart(nHandle, GX3788_ANALOG_IN_SCAN_MODE_SYNCHRONOUS, 0, &nStatus);

// verify scan operation is done

Gx3788AnalogInScanIsRunning(nHandle, &bRunning, &nStatus);

if (bRunning)

    printf("Analog In Scan in progress...\r\n");

else

    printf("Analog In Scan not running\r\n");

// read the 10 measurements from the scan memory

Gx3788AnalogInScanReadMemoryVoltages(nHandle, 0, 10, adData, &nStatus);

for (dw = 0; dw < dwScanCount; dw++)

    printf("Analog In measurement = %f Voltage\r\n", adData[dw]);  

 

 

See Also

Gx3788AnalogInMeasureChannel, Gx3788AnalogInSetGroundSource, Gx3788Reset, Gx3788AnalogInScanGetLastRunCount, Gx3788AnalogInScanIsRunning, Gx3788AnalogInScanReadMemoryRawData, Gx3788AnalogInScanReadMemoryVoltages, Gx3788AnalogInScanSetChannelListIndex, Gx3788AnalogInScanSetCount, Gx3788AnalogInScanGetSampleRate, GxFpgaGetErrorString