Sample Program Listing

/***************************************************************************

 

    FILE        : GxFpgaExampleC.cpp

 

    PURPOSE     : Windows/Linux (32/64 bit) example program

                  for GX3500, GX3700, GX3700e boards

                  using the GXFPGA driver.

 

    CREATED     : Oct 2009

 

    COPYRIGHT   : Copyright (c) Marvin Test Solutions, Inc.

 

    COMMENTS    :

 

    To compile the example:

 

    1. Microsoft VC++

        Load GxFpgaExampleC.dsp, .vcproj or .mak, depends on

        the VC++ version from the Project\File/Open... menu

        Select Project/Rebuild all from the menu

 

    2. Borland C++ Builder

        Load GxFpgaExampleC.bpr from the Project/Open

            Project... menu

        Select Project/Build all from the menu

 

    3. Linux (GCC for CPP and Make must be available)

        make -fGxFpgaExampleC.mk [CFG=Release[64] | Debug[64]] [rebuild |

            clean]

 

****************************************************************************/

#ifndef __GNUC__

#include "windows.h"

#else

#include <unistd.h>

#endif

#include "GxFpga.h"

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <ctype.h>

 

// Borland C++ Builder compat. block

#if defined(__BORLANDC__)

#pragma hdrstop

#include <condefs.h>

USELIB("GxFpgaBC.lib");

USERC("GxFpgaExampleC.rc");

#endif // defined(__BORLANDC__)

 

//**************************************************************************

//        DisplayMsg

//**************************************************************************

void DisplayMsg(PCSTR lpszMsg)

{

#ifndef __GNUC__

    MessageBeep(0);

    MessageBox(0, lpszMsg, "GxFpga example program", MB_OK);

#else

    printf("\r\nGxFpga example program: %s\r\n", lpszMsg);

#endif

    return;

}

 

//**************************************************************************

//        __sleep in mSec

//**************************************************************************

void __sleep(int imSeconds)

{

#ifndef __GNUC__

    ::Sleep(imSeconds);

#else

    usleep(imSeconds*1000);

#endif

    return;

}

 

//**************************************************************************

//        __strupr

//**************************************************************************

char * __strupr(char * sz)

{

    int i;

 

    for (i=0; sz[i]; i++)

        sz[i]=toupper(sz[i]);

    return sz;

}

 

//**************************************************************************

//        DisplayUsage

//**************************************************************************

void DisplayUsage(void)

{

    DisplayMsg(

        "This example shows how to use the GX3500/GX3700/e:\r\n"

 

        "Usage:\r\n"

        "GxFpgaExampleC <slot|address> <operation> <[parameter]>"

 

        "\r\n\r\nWhere :"

        "<slot> - Under Windows: PCI/PXI slot number as shown by the PXI \

            explorer\r\n"

        "<address> - Under Linux: Bus/device as displayed with lspci \

            utility\r\n"

 

        "<operation> - one of the following:\r\n"

        "\tLOAD_VOLATILE <parameter>=Load Volatile FPGA configuration \

            from the specified file\r\n"

        "\tLOAD_EEPROM <parameter>=Load EEPROM FPGA configuration from the \

            specified file\r\n"

        "\tREAD_REG <parameter>=Read FPGA Register from the specified \

            offset\r\n"

        "\tREAD_MEM <offset>=Read FPGA Memory from the specified \

            offset\r\n"

                  "\tWRITE_REG <offset> <data>=Write FPGA Register to the specified \

            offset\r\n"

        "\tWRITE_MEM <parameter>=Write FPGA Memory to the specified \

            offset\r\n"

        "\tIOBANKBYPASS <parameter>=Route IO Bank to Expansion Board \

            or IO Connector (0-15), function supported only by \

            GX3500/GX3500E\r\n"

        "\tINTERRUPT prints when interrupt is received, use\r\n"

            "\t  GX3500_Example.rpd for GX3500 (interrupt generated \

                every 250mSec),\r\n"

            "\t  use GX3700_Example.rpd for the GX3700 (manual \

                interrupt generation\r\n"

            "\t  by register toggling), use GX3700e_Example.rpd for \

                the GX3700e\r\n"

            "\t  (also manual interrupt)\r\n"

        "\tDMA_READ <parameter>=Read the specified number of bytes from \

            the User FLEX FPGA memory\r\n"

        "\tDMA_WRITE <parameter>=Write the specified number of bytes to \

            the User FLEX FPGA memory\r\n"

        "\tSUM=Print Board Summary information\r\n"

        "\r\nThe example should be run from the Windows command \

            prompt/Linux terminal.\r\n"

 

        "\tExamples:\r\n"

        "\t./GxFpgaExampleC 7 LOAD_VOLATILE \"GXFPGAExample-Tutorial.svf\" \

            (under Windows, slot 7)\r\n"

        "\t./GxFpgaExampleC 0x60c LOAD_VOLATILE \"GXFPGAExample-Tutorial\

            .svf\" (under Linux, bus 6 device 12)\r\n"

        );

    exit(1);

}

 

//**************************************************************************

//        CheckStatus

//**************************************************************************

void CheckStatus(SHORT nStatus)

{

    CHAR    sz[128];

 

    if (!nStatus) return;

    GxFpgaGetErrorString(nStatus, sz, sizeof sz, &nStatus);

    DisplayMsg(sz);

    DisplayMsg("Aborting the program...");

    exit(nStatus);

}

 

//**************************************************************************

//        Interrupt Callback

//**************************************************************************

 

static int g_iCount=0;

 

LONG WINAPI InterruptCallback(SHORT nHandle, SHORT enEventType, PVOID pvUserData)

{

    g_iCount++;

    printf("Interrupt received #%d\r\n", g_iCount);

    return 0;

}

 

//**************************************************************************

//        MAIN

//

// This main function receives the following parameters

//

// GxFpgaExampleC <slot|address> <operation> <[parameter]>

//

// Where :"

//  <slot> - Under Windows: PCI/PXI slot number as shown by the PXI explorer

//  <address> - Under Linux: Bus/device as displayed with lspci utility

//

//    <operation> - one of the following:

//        LOAD_VOLATILE <parameter>=Load VOLATILE FPGA configuration from

//          the specified file

//        LOAD_EEPROM <parameter>=Load EEPROM FPGA configuration from the

//          specified file

//      READ_REG <parameter>=Read FPGA Register from the specified offset

//      READ_MEM <parameter>=Read FPGA Memory from the specified offset

//        WRITE_REG <parameter>=Write FPGA Register to the specified offset

//      WRITE_MEM <parameter>=Write FPGA Memory to the specified offset

//      IOBANKBYPASS <parameter>=Route IO Bank to Expansion Board or IO

//          Connector (0-15), function supported only by GX3500/GX3500E.

//      INTERRUPT prints when interrupt is received, use

//          GX3500_Example.rpd for GX3500 (interrupt generated every

//          250mSec),    use GX3700_Example.rpd for the GX3700 (manual

//          interrupt generation by register toggling), use

//          GX3700e_Example.rpd for the GX3700e (also manual interrupt)

//      DMA_READ<parameter>=Read the specified number of bytes from the User

//            FLEX FPGA memory

//      DMA_WRITE<parameter>=Write the specified number of bytes to the User

//            FLEX FPGA memory

//      SUM=Print Board Summary information

//

//**************************************************************************

int main(int argc, char **argv)

{

    SHORT    nSlotNum;          // Board slot number

    PSTR     szOperation;       // Board Operation

    PSTR     szParameter1;      // Command's Parameter

    PSTR     szParameter2;      // Command's Parameter 2 (optional)

    SHORT    nHandle;           // Board handle

    SHORT    nStatus;           // Returned status

    SHORT    nType;             // Board type

    SHORT    nPercentage=0;

    DWORD    dwData;                     

    DWORD    dwData1;           // Command's Parameter (optional)

    DWORD    dwData2;           // Command's Parameter 2 (optional)

    DWORD    dwDmaByteCount;    // Max DMA Byte Count is 65528

                                // per Rd/Wr cycle

    PDWORD   padwDataWr=0;      // Write data buffer

    PDWORD   padwDataRd=0;      // Read data buffer

    DWORD    dw;

    CHAR     sz[512];           // Board Summary

 

    // Check minimum number of arguments received

    if (argc<3) DisplayUsage();

 

    // Parse command line parameters

    nSlotNum=(SHORT)strtol(*(++argv), NULL, 0);

    if (nSlotNum<0) DisplayUsage();

    szOperation=__strupr(*(++argv));

 

    GxFpgaInitialize(nSlotNum, &nHandle, &nStatus);

      CheckStatus(nStatus);

 

    if (!strcmp(szOperation, "LOAD_VOLATILE"))

    {

            if (argc<4) DisplayUsage();

            szParameter1=__strupr(*(++argv));

 

        GxFpgaLoad(nHandle, GXFPGA_LOAD_TARGET_VOLATILE, szParameter1,

            GXFPGA_LOAD_MODE_ASYNC, &nStatus);

        CheckStatus(nStatus);

 

        GxFpgaLoadStatus(nHandle, &nPercentage, &nStatus);

        while (nPercentage != 100)

        {

            GxFpgaLoadStatus(nHandle, &nPercentage, &nStatus);

            printf("FPGA Loading in progress, %d Percent Complete\r\n",

                nPercentage);

            __sleep(1000);    // sleep 1 second

        }

    }

    else if (!strcmp(szOperation, "LOAD_EEPROM"))

    {

            if (argc<4) DisplayUsage();

            szParameter1=__strupr(*(++argv));

 

        GxFpgaLoad(nHandle, GXFPGA_LOAD_TARGET_EEPROM, szParameter1,

            GXFPGA_LOAD_MODE_ASYNC, &nStatus);

        CheckStatus(nStatus);

 

        GxFpgaLoadStatus(nHandle, &nPercentage, &nStatus);

        while (nPercentage != 100)

        {

            GxFpgaLoadStatus(nHandle, &nPercentage, &nStatus);

            printf("FPGA Loading in progress, %d Percent Complete\r\n",

                nPercentage);

            __sleep(1000);    // sleep 1 second

        }

    }

    else if (!strcmp(szOperation, "READ_REG"))

    {

        if (argc<4) DisplayUsage();

        szParameter1=__strupr(*(++argv));

        dwData1=strtol(szParameter1, NULL, 0);

        GxFpgaReadRegister(nHandle, dwData1, &dwData, 4, &nStatus);

        printf("READ_REG : 0x%04x = 0x%08x\r\n",

            (UINT)dwData1, (UINT)dwData);

    }

    else if (!strcmp(szOperation, "READ_MEM"))

    {

        if (argc<4) DisplayUsage();

        szParameter1=__strupr(*(++argv));

        dwData1=strtol(szParameter1, NULL, 0);

        GxFpgaReadMemory(nHandle, dwData1, &dwData, 4, &nStatus);

        printf("READ_MEM : 0x%04x = 0x%08x\r\n",

            (UINT)dwData1, (UINT)dwData);

    }

    else if (!strcmp(szOperation, "WRITE_REG"))

    {

        if (argc<5) DisplayUsage();

        szParameter1=__strupr(*(++argv));

        szParameter2=__strupr(*(++argv));

        dwData1=strtol(szParameter1, NULL, 0);

        dwData2=strtol(szParameter2, NULL, 0);

        GxFpgaWriteRegister(nHandle, dwData1, &dwData2, 4,

            &nStatus);

        printf("WRITE_REG: 0x%04x = 0x%08x\r\n",

                       (UINT)dwData1, (UINT)dwData2);

    }

    else if (!strcmp(szOperation, "WRITE_MEM"))

    {

        if (argc<5) DisplayUsage();

        szParameter1=__strupr(*(++argv));

        szParameter2=__strupr(*(++argv));

        dwData1=strtol(szParameter1, NULL, 0);

        dwData2=strtol(szParameter2, NULL, 0);

        GxFpgaWriteMemory(nHandle, dwData1, &dwData2, 4,

            &nStatus);

        printf("WRITE_MEM: 0x%04x = 0x%08x\r\n",

            (UINT)dwData1, (UINT)dwData2);

    }

    else if (!strcmp(szOperation, "IOBANKBYPASS"))

    {   if (argc<4) DisplayUsage();

            szParameter1=__strupr(*(++argv));

            GxFpgaGetBoardType(nHandle, &nType, &nStatus);

        // Function supported only by GX3500/GX3500E

        if (nType==GXFPGA_BOARD_TYPE_GX3500 ||

            nType==GXFPGA_BOARD_TYPE_GX3500E)

            GxFpgaSetExpansionBoardBypass(nHandle, atoi(szParameter1) ,

                &nStatus);

    }

    else if (!strcmp(szOperation, "INTERRUPT"))

      {    

        GxFpgaGetBoardType(nHandle, &nType, &nStatus);

        CheckStatus(nStatus);

        if (nType==GXFPGA_BOARD_TYPE_GX3700 ||

            nType==GXFPGA_BOARD_TYPE_GX3700E)

        {

            // Use the interrupt method example with

            // tutorial_design_top.rpd or tutorial_design_top.svf.

            // Example files which provided by the GXFPGA installation.

            // We generate an interrupt by toggling bit in the User's

            // FLEX Fpga: allocate buffers.

            // This functionality is also available in

            // GX3700_Example.rpd for the GX3700, and

            // GX3700e_Example.rpd for the GX3700e.

 

            // Set the interrupt event.

            GxFpgaSetEvent(nHandle, GT_EVENT_INTERRUPT, true,

                InterruptCallback, (PVOID)111, &nStatus);

 

            // Generate 10 interrupts by by toggling bit in the User's

            // FLEX Fpga

            while (g_iCount<10)

            {   

                // A transition from ‘0’ to ‘1’ will generate an

                // interrupt

                dw=0;

                GxFpgaWrite(nHandle, GXFPGA_MEMORY_BAR1, 0x3EC, &dw,

                    4, 1, &nStatus);

                dw=1;

                GxFpgaWrite(nHandle, GXFPGA_MEMORY_BAR1, 0x3EC, &dw,

                    4, 1, &nStatus);

                __sleep(1);    // sleep 1 msec

                // Wait 1000 mSec for the interrupt before timeout

                GxFpgaWaitOnEvent(nHandle, GT_EVENT_INTERRUPT, 1000,

                    &nStatus);

                if (nStatus==0)

                    InterruptCallback(nHandle, GT_EVENT_INTERRUPT,

                    (PVOID)111);

                else

                    break;

            }

 

            // Disable the interrupt event.

            GxFpgaSetEvent(nHandle, GT_EVENT_INTERRUPT, false, NULL,

                NULL, &nStatus);

            __sleep(1000);    // sleep 1 sec to show interrupt message

        }

        else

        {   // GXFPGA_BOARD_TYPE_GX3500/GXFPGA_BOARD_TYPE_GX3500e

            // two interrupt methods examples provided here use with

            // GX3500_Example.rpd for GX3500 (targets 484C8)

       

            // 1) call back wait 1ms (example generate 4 per second)

            GxFpgaSetEvent(nHandle, GT_EVENT_INTERRUPT, true,

                InterruptCallback, (PVOID)111, &nStatus);

            __sleep(1000);    // sleep 1 second

 

            // 2) wait 1 second for an interrupt (10 times), should

            //    take around 2.5 second to complete

            while (g_iCount<10)

            {   GxFpgaWaitOnEvent(nHandle, GT_EVENT_INTERRUPT,

                    1000, &nStatus);

                if (nStatus==0)

                    InterruptCallback(nHandle, GT_EVENT_INTERRUPT,

                    (PVOID)111);

                else

                    break;

            }

            GxFpgaDiscardEvents(nHandle, GT_EVENT_INTERRUPT,

                &nStatus);

            GxFpgaSetEvent(nHandle, GT_EVENT_INTERRUPT, false, NULL,

                NULL, &nStatus);

        }

    }

    else if (!strcmp(szOperation, "DMA_READ"))

    {    GxFpgaGetBoardType(nHandle, &nType, &nStatus);

        CheckStatus(nStatus);

        // Function supported only by GX3700 and GX3700E

        // Functionality is based on the User's FPGA design example

        // tutorial_design_top.rpd or tutorial_design_top.svf files

        // example supplied by Marvin Test Solutions

        if (nType==GXFPGA_BOARD_TYPE_GX3700

            || nType==GXFPGA_BOARD_TYPE_GX3700E)

        {   // Max DMA Byte Count is 65528 per DMA Rd/Wr cycle

                  if (argc<4) DisplayUsage();

                  szParameter1=__strupr(*(++argv));

 

            dwDmaByteCount=atoi(szParameter1);

            // allocate buffers

            padwDataWr=new DWORD[dwDmaByteCount/4];

            padwDataRd=new DWORD[dwDmaByteCount/4];

 

            // Write to User FPGA internal SRAM

            //--------------------------------------------------

            // Enable rd/wr to internal SRAM thru BAR2.

            dwData=0x4;

            GxFpgaWriteRegister(nHandle, 0x3F4, &dwData, 4, &nStatus);

            CheckStatus(nStatus);

 

            // Fill User FPGA's internal SRAM with data

            for (dw=0; dw<(dwDmaByteCount/4); dw++)

                padwDataWr[dw]=dw;

            GxFpgaWrite(nHandle, GXFPGA_MEMORY_BAR2, 0, padwDataWr, 4,

                dwDmaByteCount/4, &nStatus);

            CheckStatus(nStatus);

 

            // Read back the data from the internal SRAM

            GxFpgaRead(nHandle, GXFPGA_MEMORY_BAR2, 0, padwDataRd, 4,

                dwDmaByteCount/4, &nStatus);

            CheckStatus(nStatus);

 

            // Disable rd/wr to internal SRAM thru BAR2.

            dwData=0x0;

            GxFpgaWriteRegister(nHandle, 0x3F4, &dwData, 4, &nStatus);

            CheckStatus(nStatus);

 

            // Set memory start address

            dwData=0x0;

            GxFpgaWriteRegister(nHandle, 0x3F0, &dwData, 4, &nStatus);

            CheckStatus(nStatus);

            dwData=0x1;

            GxFpgaWriteRegister(nHandle, 0x3F4, &dwData, 4, &nStatus);

            CheckStatus(nStatus);

 

            // Set # of bytes for DMA

            GxFpgaWriteRegister(nHandle, 0x3F8, &dwDmaByteCount, 4,

                &nStatus);

            CheckStatus(nStatus);

 

            // Move User FPGA data into FIFO for DMA write to PCIe.

            dwData=0x2;

            GxFpgaWriteRegister(nHandle, 0x3F4, &dwData, 4, &nStatus);

            CheckStatus(nStatus);

 

            // Read data from User FPGA in to buffer.

            GxFpgaDmaTransfer(nHandle, GXFPGA_DMA_READ, padwDataRd, 4,

                dwDmaByteCount/4, 0, 0, &nStatus);

            CheckStatus(nStatus);

 

            // Reset memory-to-FIFO process

            dwData=0x0;

            GxFpgaWriteRegister(nHandle, 0x3F4, &dwData, 4, &nStatus);

            CheckStatus(nStatus);

 

            // Compare data

            for (dw=0; dw<(dwDmaByteCount/4); dw++)

            {    if (padwDataWr[dw]!=padwDataRd[dw])

                {    printf("Compare Failed: dw=%u, padwDataWr[dw]=%u, \

                       padwDataRd[dw]=%u\r\n",

                       (UINT)dw, (UINT)padwDataWr[dw],

                       (UINT)padwDataRd[dw]);

                    break;

                }

                else

                {    printf("Compare Successful: dw=%u, padwDataWr[dw]=%u, \

                           padwDataRd[dw]=%u\r\n",

                        (UINT)dw, (UINT)padwDataWr[dw],

                        (UINT)padwDataRd[dw]);

                }

            }

        }

    }

    else if (!strcmp(szOperation, "DMA_WRITE"))

    {    GxFpgaGetBoardType(nHandle, &nType, &nStatus);

        CheckStatus(nStatus);

        // Function supported only by GX3700 and GX3700E

        // Functionality is based on the User's FPGA design example

        // tutorial_design_top.rpd or tutorial_design_top.svf files.

        if (nType==GXFPGA_BOARD_TYPE_GX3700 ||

            nType==GXFPGA_BOARD_TYPE_GX3700E)

        { // Max DMA Byte Count is 65528 per DMA Rd/Wr cycle

                  if (argc<4) DisplayUsage();

                  szParameter1=__strupr(*(++argv));

            dwDmaByteCount=atoi(szParameter1);

            // allocate buffers

            padwDataWr=new DWORD[dwDmaByteCount];

            padwDataRd=new DWORD[dwDmaByteCount];

 

            // Fill buffer with data

            for (dw=0; dw<(dwDmaByteCount/4); dw++)

                padwDataWr[dw]=dw;

 

            // Set memory start address

            dwData=0x0;

            GxFpgaWriteRegister(nHandle, 0x3F0, &dwData, 4, &nStatus);

            CheckStatus(nStatus);

            dwData=0x1;

            GxFpgaWriteRegister(nHandle, 0x3F4, &dwData, 4, &nStatus);

            CheckStatus(nStatus);

 

            // Set # of bytes for DMA

            GxFpgaWriteRegister(nHandle, 0x3F8, &dwDmaByteCount, 4,

                &nStatus);

            CheckStatus(nStatus);

 

            // Write data from User FPGA in to buffer.

            GxFpgaDmaTransfer(nHandle, GXFPGA_DMA_WRITE, padwDataWr, 4,

                dwDmaByteCount/4, 0, 0, &nStatus);

            CheckStatus(nStatus);

 

            // Read data from User FPGA internal SRAM and compare to

            // original data

            // Enable rd/wr to internal SRAM thru BAR2.

            dwData=0x4;

            GxFpgaWriteRegister(nHandle, 0x3F4, &dwData, 0x4, &nStatus);

            CheckStatus(nStatus);

 

            // Read back the data from the internal SRAM

            GxFpgaRead(nHandle, GXFPGA_MEMORY_BAR2, 0, padwDataRd, 4,

                dwDmaByteCount/4, &nStatus);

            CheckStatus(nStatus);

 

            // Disable rd/wr to internal SRAM thru BAR2.

            dwData=0x0;

            GxFpgaWriteRegister(nHandle, 0x3F4, &dwData, 4, &nStatus);

            CheckStatus(nStatus);

 

            // Compare data

            for (dw=0; dw<(dwDmaByteCount/4); dw++)

            {    if (padwDataWr[dw]!=padwDataRd[dw])

                {    printf("Compare Failed: dw=%u, padwDataWr[dw]=%u, \

                         padwDataRd[dw]=%u\r\n",

                        (UINT)dw, (UINT)padwDataWr[dw],

                        (UINT)padwDataRd[dw]);

                    break;

                }

                else

                {    printf("Compare Successful: dw=%u, \

                       padwDataWr[dw]=%u, padwDataRd[dw]=%u\r\n",

                      (UINT)dw, (UINT)padwDataWr[dw], (UINT)padwDataRd[dw]);

                }

            }

        }

    }

    else if (!strcmp(szOperation, "SUM"))

    {   // print board summary

        GxFpgaGetBoardSummary(nHandle, sz, sizeof sz, &nStatus);

        CheckStatus(nStatus);

        printf("Board Summary: %s.\n", sz);

    }

    else if (!strcmp(szOperation, "GX3788_SCAN"))

    {

        // 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);

        CheckStatus(nStatus);

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

        Gx3788AnalogInSetGroundSource(nHandle,

GX3788_ANALOG_IN_CHANNELS_8_15,

            GX3788_ANALOG_IN_ANALOG_GND, &nStatus);

        CheckStatus(nStatus);

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

        dwScanCount = dwChannelCount * 2;

        Gx3788AnalogInScanSetCount(nHandle, dwScanCount, &nStatus);

        CheckStatus(nStatus);

        // Set sample rate to 5KHz

        Gx3788AnalogInScanSetSampleRate(nHandle, 5000, &nStatus);

        CheckStatus(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);

                CheckStatus(nStatus);

            }

            else

            {   Gx3788AnalogInScanSetChannelListIndex(nHandle, dwListIndex,

                    dwScanChannel,

                    GX3788_ANALOG_IN_RANGE_NEG_10p24V_TO_POS_10p24V,

                    GX3788_ANALOG_IN_SINGLE_ENDED,

                    FALSE, &nStatus);

                CheckStatus(nStatus);

            }

        }

 

        // read back and verify the channel scan list

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

        {

            Gx3788AnalogInScanGetChannelListIndex(nHandle, dwListIndex,

    &dwScanChannel, &nRange, &nMode, &bIsLastChannel, &nStatus);

            CheckStatus(nStatus);

            // verify range

            if (nRange == GX3788_ANALOG_IN_RANGE_NEG_13p60V_TO_POS_13p60V)

                printf("Scan Channel %u analog in voltage rang is " \

"±13.60V\r\n", (UINT)dwScanChannel);

            else if (nRange ==

GX3788_ANALOG_IN_RANGE_NEG_10p24V_TO_POS_10p24V)

                printf("Scan Channel %u analog in voltage rang is " \

                    "±10.24V\r\n", (UINT)dwScanChannel);

            else if (nRange == GX3788_ANALOG_IN_RANGE_NEG_5p12V_TO_POS_5p12V)

                printf("Scan Channel %u analog in voltage rang is "

                    "±5.12V\r\n", (UINT)dwScanChannel);

            else if (nRange == GX3788_ANALOG_IN_RANGE_NEG_2p56V_TO_POS_2p56V)

                printf("Scan Channel %u analog in voltage rang is " \

                    "±2.56V\r\n", (UINT)dwScanChannel);

            else if (nRange == GX3788_ANALOG_IN_RANGE_NEG_1p28V_TO_POS_1p28V)

                printf("Scan Channel %u analog in voltage rang is " \

  "±1.28V\r\n", (UINT)dwScanChannel);

            else if (nRange == GX3788_ANALOG_IN_RANGE_NEG_0p64V_TO_POS_0p64V)

                printf("Scan Channel %u analog in voltage rang is " \

  "±0.64V\r\n", (UINT)dwScanChannel);

            else

                printf("Channel %u invalid analog in voltage range\r\n",

                    (UINT)dwScanChannel);

            // verify analog in Differential or Single Ended

            if (nMode == GX3788_ANALOG_IN_DIFFERENTIAL)

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

                    (UINT)dwScanChannel);

            else if (nMode == GX3788_ANALOG_IN_SINGLE_ENDED)

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

                    (UINT)dwScanChannel);

            else

                printf("Scan Channel %u invalid Analog Input Mode\r\n",

                    (UINT)dwScanChannel);

 

            // verify last channel

            if (bIsLastChannel)

                printf("Scan Channel %u is the Last Channel\r\n",

                    (UINT)dwScanChannel);

            else

                printf("Scan Channel %u is not the Last Channel\r\n",

                    (UINT)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);

        CheckStatus(nStatus);

        // verify scan operation is done

        Gx3788AnalogInScanIsRunning(nHandle, &bRunning, &nStatus);

        CheckStatus(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);

        CheckStatus(nStatus);

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

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

    }

    printf("FPGA Done (Status=%i)\r\n", nStatus);

    if (padwDataWr)

        delete[] padwDataWr;

    if (padwDataRd)

        delete[] padwDataRd;

 

    return 0;

}

 

//**************************************************************************

//        End Of File

//**************************************************************************