LabView Development

  • Provides DppApi resources for LabView developers.

  • Demonstrates DP4/PX4/DP5 USB communications using LabView.

  • Provides important technical resources for LabView developers.

  • DppApi.vi data acquisition VI demonstrates:

    • OpenDppApi

    • CloseDppApi

    • OpenUSBDevice

    • GetUSBDppDeviceInfo

    • CloseUSBDevice

    • GetConfigFromDpp

    • ClearDppData

    • PauseDppData

    • GetDppData

    • Uses DPPStatus.vi

    • Uses DppConfig.vi

    • Communicates to DP4/PX4/DP5 type USB DPP devices.

    • Identifies the DPP device type.

    • Acquires spectrum data.

    • Plots spectrum data.

    • Reads DPP status

  • DPPStatus.vi status VI demonstrates:

    • GetStatusStruct

    • Reads DPP status.

    • Uses DPP_STATUS structure.

  • DppConfig.vi configuration VI demonstrates:

    • GetConfigFromFile

    • GetTempConfigSettings

    • SendConfigToDpp

  • LabView 8.6 demonstration VI source.

  • DppApi.vi Panel

  • DPPStatus.vi Panel

  • DppConfig.vi Panel

DppApi.vi Panel

DPPStatus.vi Panel

DppConfig.vi Panel


DppApi.vi

Connector Pane

Front Panel

Controls and Indicators

ii32

objDppApi

ii32

Dpp Devices

ii32

Dpp Serial Number

istr

Dpp Device Type

ii32

Channels

i1di32

Data Array

    ii32

            Numeric

i1ddbl

Spectrum Data

i1ddbl

Plot Data

    idbl

            Numeric

ii32

Dpp Device Type Index

Block Diagram

List of SubVIs and Express VIs with Configuration Information

DppConfig.vi

DppConfig.vi

DPPStatus.vi

DPPStatus.vi

VI Revision History

"DppApi.vi History"

Current Revision: 72

Position in Hierarchy


DppConfig.vi

ci32

objDppApi Handle In

cpath

DPP Configuration Filename

ci32

Dpp Device Type Index

icclst

DPP Config Settings OUT

    iu8

            AcqMode

    iu8

            MCSTimebase

    iu8

            MCAChannels

    iu8

            BufferSelect

    iu8

            TTLGate

    iu8

            SlowThreshold

    iu16

            PAD 2 Bytes

    ii32

            PresetTime

    ii32

            PresetCount

    inclst

            SCA

      ii32

              SCA1

      ii32

              SCA2

      ii32

              SCA3

      ii32

              SCA4

      ii32

              SCA5

      ii32

              SCA6

      ii32

              SCA7

      ii32

              SCA8

    iu8

            TimeToPeak

    iu8

            Decimation

    iu8

            FlatTop

    iu8

            PUREnable

    iu8

            FastThreshold

    iu8

            RTDSlow

    iu8

            RTDOn

    iu8

            RTDFast

    iu8

            BLR

    iu8

            BaselineOn

    iu8

            CoarseGain

    iu8

            PAD 1 Byte

    ii32

            FineGain

    ii32

            PoleZero

    ii32

            InputOffset

    iu8

            InputPolarity

    iu8

            DetReset

    iu16

            PAD 2 Bytes (2)

    ii32

            TEC

    iu8

            HVEnabled

    iu16

            PAD 2 Bytes (3)

    iu8

            PAD 1 Byte (3)

    ii32

            HV

    iu8

            PreampPower

    iu8

            AnalogOut

    iu8

            OutputOffset

    iu8

            AuxOut

    iu8

            AudibleCounter

"DppConfig.vi History"

Current Revision: 97

Position in Hierarchy


DPPStatus.vi

ci32

objDppApi Handle In

ibool

MCA Enabled

inclst

DPP Status

    idbl

            FPGA

    idbl

            Firmware

    idbl

            SerialNumber

    iu8

            StatDevIn

    iu8

            BootStatus

    iu8

            PwrBtnConfig

    iu8

            SwConfigRcvd

    iu8

            SetFastThreshDone

    iu8

            SetSlowThreshDone

    iu8

            SetInputOffsetDone

    iu8

            DataAlignDbl_1BytePAD

    idbl

            BoardTemp

    idbl

            HVMonitor

    idbl

            TECMonitor

    idbl

            FastCount

    idbl

            SlowCount

    idbl

            AccumulationTime

    iu8

            StatMcaEnabled

    iu8

            MCSDone

    iu8

            PresetCountExpired

ibool

Unit Configured

"DPPStatus.vi History"

Current Revision: 49

Position in Hierarchy


An Overview of Accessing DLLs or Shared Libraries from LabVIEW - Developer Zone - National Instruments

An Overview of Accessing DLLs or Shared Libraries from LabVIEW

Overview

Dynamic Link Libraries (DLLs) provide a way for programs to access external code. The Windows concept of a DLL is also found on Macintosh and UNIX systems, but is usually called a shared library or shared object file.

DLLs are sections of code that are linked to the main program at run time (dynamically linked). This has several advantages. The first is space. If many applications share a certain algorithm, you can compile it once as a DLL, and then use the same code in all the applications. DLLs also provide a way for code to be distributed in a fashion that easily allows higher level programs to access the code. A good example of this are hardware drivers, in which the interface between the application software and the hardware is often through a DLL.

LabVIEW can access functions contained in DLLs via the Call Library Function Node.

Table of Contents

  1. Gathering the necessary information
  2. Configuring the Call Library Function Node
  3. Declaring a function call to a library function threadsafe (reentrant)

Gathering the necessary information

In order to call a function from a DLL, you need to know four pieces of information:

  1. The library file in which the code for the function resides
  2. The name of the function as it appears in the library
  3. The number and type of arguments the function requires, including the return type
  4. The calling convention

Items two and three together make the function prototype.

If you are the author of the library, you should already have this information. If the library is from a third party, you should consult the documentation that came with the library to gather this information. (If you are trying to access a function that is part of the Win32 SDK, see the link below.) You may find that you need to look in the header (.h) file included with the DLL in order to find the function prototype. LabVIEW is able to call functions with either C or standard (PASCAL, WINAPI) conventions. Most DLLs use standard calling conventions, and this can usually be assumed, if it is not explicitly stated. If the calling conventions are wrong, LabVIEW will crash when your VI tries to call the function.

When you have the information, it should look something like this:

Library:
Function Prototype:

Calling Conventions: 		mydll.dll
void MyFunction(int a, double* b, char* string, unsigned long arraysize, short* dataarray);
standard

Unfortunately, in order to successfully call this function, you need to understand what the function expects. The first problem is that integer data types are not necessarily consistent in size from one platform to another. LabVIEW alleviates this problem by refering to all integers in a consistent manner. To convert from LabVIEW's notation, to the notation of your particular platform, use the following table:

LabVIEW | Win32 | Win16 | Macintosh (PowerPC) | Most UNIX Systems
int8 | signed char | signed char | signed char | signed char
int16 | short | int, short | short | short
int32 | int, long | long | int, long | int, long
uInt8 | char | char | char | char
uInt16 | unsigned short | unsigned int, unsigned short | unsigned short | unsigned short
uInt32 | unsigned int, unsigned long | unsigned long | unsigned int, unsigned long | unsigned int, unsigned long

Furthermore, you also need to know what the function expects in terms of pointers. Some parameters are passed by value, and some are passed by pointer. For those passed as pointers, the function may expect a single value, or it may expect the starting location of an array of values. Knowing which one is critical if you are to successfully call the library function. In the example above, you can guess from the parameter names, and read in the (hypothetical) manual that dataarray should be a pointer to an array of shorts, while b is a pointer to one double value.

The final piece of information is that strings are generally passed to DLLs as C strings. A C string is an array of chars, and as such, is normally seen in function prototypes as "char*", a pointer to a character array. Incidentally, C functions know when they've reached the end of a string because they are always terminated with a null character (ASCII value 0x00).

With all of this information, you can write a slightly revised function prototype (assuming a Win32 OS):

void MyFunction(int32 a, double* b, char* string, uInt32 arraysize, int16* dataarray);

where:
b is a pointer to one double value,
string is a C String pointer, and
dataarray is a pointer to an array of int16s

Configuring the Call Library Function Node

Once you've gathered all of the necessary information, you are ready to set up the Call Library Function Node. The first thing to do, of course, is to place a node on the block diagram. The Call Library Function Node is found on the Functions Palette >> Advanced >> Call Library Function. After placing the node on the diagram, you must configure it. Popup on the node and select "Configure..."

This will bring up a dialog that allows you to configure the function call.

[+] Enlarge Image

On this dialog, enter the path to the desired library, the name of the function, and the calling conventions. Finally, set up the function prototype by using the Parameter of the dialog. Specify the return type, and then add parameters to the prototype using the "Add a Parameter Before" or "Add a Parameter After" buttons. Use the dropdown boxes "Type," "Data Type," and "Pass" to specify the proper data type and how the parameter is passed.

Once finished, the node will display the appropriate terminal data type on the block diagram:

If the library file cannot be found, or the function cannot be found within the library, you will get a broken run arrow. Click the broken run arrow to display the error list and find the offending node.

Declaring a function call to a library function threadsafe (reentrant)

If you know that the function you are calling in the library is threadsafe, you may inform LabVIEW by appropriately configuring the node. If the node is not configured as a threadsafe call, the call is assumed to be non-threadsafe, and is run in the User Interface thread. This ensures that two calls are not made simultaneously to a non-threadsafe function. If the function is threadsafe, however, it should be configured as such, as this leads to performance improvements.

To configure a call library function as threadsafe, change the dropdown box that says "Run in UI Thread," to "Reentrant."

[+] Enlarge Image

Having done this, the top of the node changes from orange to yellow, indicating that the call is reentrant.
---->


DPP Configuration Cluster Element Order

  • PAD 2 Bytes before long PresetTime. .

  • PAD 1 Bytes before long FineGain. .

  • PAD 2 Bytes before long TEC. .

  • PAD 3 Bytes before long HV. .

  • SCA Cluster Element Order

Configuration Cluster Element Order

SCA Cluster Element Order


DPPAPI Data Stucture Byte Alignment

Pack 1 Position (LabView) | Pack 4 Position (VB 5,6) | Byte Position (Hex) | Auto PAD (Bytes) | Byte Count | // @struct DPP_CONFIG_SETTINGS | DPP Configuration Settings Storage Type | Group
 | No PAD Needed |  |  |  | typedef struct _DPP_CONFIG_SETTINGS { |  |
 |  | 0x00 |  | 1 | byte AcqMode; | // @field acquisition mode 0=MCA;1=MCS | //MCA Properties
 |  | 0x01 |  | 1 | byte MCSTimebase; | // @field MCS timebase value (0-15) see CAcqMode |
 |  | 0x02 |  | 1 | byte MCAChannels; | // @field number of channels 4=256;3=512;2=1024;1=2048;0=4096;5=8192 |
 |  | 0x03 |  | 1 | byte BufferSelect; | // @field Holds Buffer Sel A&B;Buffer Sel Hardware;see DPPBufferSelect |
 |  | 0x04 |  | 1 | byte TTLGate; | // @field gate input settings; determines events included/excluded from spectrum; see DPPGate |
 |  | 0x05 |  | 1 | byte SlowThreshold; | // @field Slow ch threshold; Events w/amp lower not added to spectrum |
Insert 2 Byte Pad |  | 0x08 | 2 | 4 | long PresetTime; | // @field var holds preset time; used in usb |
 |  | 0x0C |  | 4 | long PresetCount; | // @field preset count in selected channels; ch are set in SCA8 |
 |  | 0x10 |  | 32 | long SCA[8]; | // @field SCA values; LL; UL; and Enable are stored together |
 |  | 0x30 |  | 1 | byte TimeToPeak; | // @field TimeToPeak register setting | //Shaping Properties
 |  | 0x31 |  | 1 | byte Decimation; | // @field decimation setting for pulse shaping |
 |  | 0x32 |  | 1 | byte FlatTop; | // @field flatop register setting |
 |  | 0x33 |  | 1 | byte PUREnable; | // @field pile-up rejection enabled |
 |  | 0x34 |  | 1 | byte FastThreshold; | // @field Fast Ch Threshold; events w/fch amp below this are rejected |
 |  | 0x35 |  | 1 | byte RTDSlow; | // @field Risetime Discrimination slow threshold |
 |  | 0x36 |  | 1 | byte RTDOn; | // @field Turns RTD on; and sets the amplitude and timing thresholds |
 |  | 0x37 |  | 1 | byte RTDFast; | // @field RTD Time Threshold;Events w/HWHM wider than this are rejected |
 |  | 0x38 |  | 1 | byte BLR; | // @field Baseline Restoration; see udBLR.Value notes for values |
 |  | 0x39 |  | 1 | byte BaselineOn; | // @field use autobaseline during detector reset |
 |  | 0x3A |  | 1 | byte CoarseGain; | // @field stores current coarse gain value | //Gain PZ Properties
Insert 1 Byte Pad |  | 0x3C | 1 | 4 | long FineGain; | // @field stores current fine gain value |
 |  | 0x40 |  | 4 | long PoleZero; | // @field pole zero adjust value |
 |  | 0x44 |  | 4 | long InputOffset; | // @field input offset |
 |  | 0x48 |  | 1 | byte InputPolarity; | // @field use InvertEnable during detector reset |
 |  | 0x49 |  | 1 | byte DetReset; | // @field detector reset lockout period |
Insert 2 Byte Pad |  | 0x4C | 2 | 4 | long TEC; | // @field TEC temperature setting (displayed in Kelvin) | //Power Properties
 |  | 0x50 |  | 1 | byte HVEnabled; | // @field high voltage setting enable |
Insert 3 Byte Pad |  | 0x54 | 3 | 4 | long HV; | // @field high voltage setting value |
 |  | 0x58 |  | 1 | byte PreampPower; | // @field preamp power select value (5v or 8.5v) |
 |  | 0x59 |  | 1 | byte AnalogOut; | // @field dac enabled and DAC output type;(stobed peak;shaped pulse;dec inp;fast ch) | //Misc Properties
 |  | 0x5A |  | 1 | byte OutputOffset; | // @field Output DAC offset; -64…+63;(signed)(D7-D1) (-500mV to +492mV) |
 |  | 0x5B |  | 1 | byte AuxOut; | // @field Aux output type |
 |  | 0x5C |  | 1 | byte AudibleCounter; | // @field audio volume setting |
Can PAD 3 Bytes if needed | 3 Bytes, Can Ignore | 0x60 Total | 3 |  | } DPP_CONFIG_SETTINGS; *LP_DPP_CONFIG_SETTINGS; |  |
 |  |  |  |  | // @struct DPP_STATUS | DPP Status Storage Type |
 |  |  |  |  | typedef struct _DPP_STATUS { |  |
 |  | 0x00 |  | 8 | double FPGA; | // @field FPGA | // Identification
 |  | 0x08 |  | 8 | double Firmware; | // @field firmware revision |
 |  | 0x10 |  | 8 | double SerialNumber; | // @field unit serial number |
 |  | 0x18 |  | 1 | byte StatDevInd; | // @field device indicator from status block (0=dp4;1=px4) |
 |  | 0x19 |  | 1 | byte BootStatus; | // @field boot status byte (PwrBtnConfig;SwConfigRcvd;McaEnabled) | // Configuration
 |  | 0x1A |  | 1 | byte PwrBtnConfig; | // @field dpp has loaded config from power button |
 |  | 0x1B |  | 1 | byte SwConfigRcvd; | // @field software has sent valid config to unit since startup |
 |  | 0x1C |  | 1 | byte SetFastThreshDone; | // @field DPP tune fast thresh has successfully done | // Tuning
 |  | 0x1D |  | 1 | byte SetSlowThreshDone; | // @field DPP tune slow thresh has successfully done (NOT USED) |
 |  | 0x1E |  | 1 | byte SetInputOffsetDone; | // @field DPP tune input offset has successfully done |
Insert 1 Byte Pad |  | 0x20 | 1 | 8 | double BoardTemp; | // @field board temperature monitor value | // Monitors
 |  | 0x28 |  | 8 | double HVMonitor; | // @field high voltage monitor value |
 |  | 0x30 |  | 8 | double TECMonitor; | // @field TEC temperature monitor value (displayed in Kelvin) |
 |  | 0x38 |  | 8 | double FastCount; | // @field fast channel count | // Acquisition Parameters
 |  | 0x40 |  | 8 | double SlowCount; | // @field slow channel count |
 |  | 0x48 |  | 8 | double AccumulationTime; | // @field real time duration of present data acquisition interval |
 |  | 0x50 |  | 1 | byte StatMcaEnabled; | // @field mca enabled status; high during acq; preset time resets flag | // Acquisition Mode
 |  | 0x51 |  | 1 | byte MCSDone; | // @field MCS done flag 1=finished; 0=not finished |
 |  | 0x52 |  | 1 | byte PresetCountExpired; | // @field indicates presets counts have been reached |
Can PAD 5 Bytes if needed | 1 Byte, Can Ignore | 0x58 Total | 5 |  | } DPP_STATUS; *LP_DPP_STATUS; |  |
 |  |  |  |  | // @struct DPP_BOOT_STATUS | DPP Boot Options Status Storage Type |
 |  |  |  |  | typedef struct _DPP_BOOT_OPTIONS { |  |
 |  | 0x00 |  | 2 | USHORT BootFlags; | // @field Boot flags (MSB currently unused) |
 |  | 0x02 |  | 2 | USHORT HVDACSet; | // @field HV DAC setting (not used in PX4 mode) |
 |  | 0x04 |  | 2 | USHORT TECDACSet; | // @field TEC DAC setting (not used in PX4 mode) |
 |  | 0x06 |  | 2 | USHORT InputOffsetTuning; | // @field Input offset DAC setting (not used in PX4 mode) |
 |  | 0x08 |  | 2 | USHORT uCTempCal; | // @field uC temp cal |
 |  | 0x0A |  | 2 | USHORT SpectrumOffset; | // @field Spectrum offset |
 |  | 0x0C Total |  |  | } DPP_BOOT_OPTIONS; *LP_DPP_BOOT_OPTIONS; |  |


Modifying Cluster Element Order

Cluster elements have a logical order unrelated to their position in the shell. The first object you place in the cluster is element 0, the second is element 1, and so on. If you delete an element, the order adjusts automatically. The cluster order determines the order in which the elements appear as terminals on the Bundle and Unbundle functions on the block diagram.

Complete the following steps to view and modify the cluster order.

  1. Right-click the cluster border and select Reorder Controls in Cluster from the shortcut menu. The toolbar and cluster display the following changes:
    • The cluster shows a numbered set of white and black boxes at each element. The white boxes on the elements show their current places in the cluster order.
    • The numbers in the black boxes match the numbers in the white boxes. If you change the order, the black boxes show the new place in the order for an element.
    • The toolbar also displays a number in a black box. The number on the toolbar affects the next element you change.
    • The cursor changes to the cluster order cursor.
  2. Use any of these methods to change the order:
    • Click an element in the cluster order. The number of the element in the black box changes to match the number on the toolbar.
    • Type the new order number in the Click to set to field and click the element.
    • Click the elements in the order you want to set and the order number automatically increments.
  3. Click the OK button on the toolbar to set the cluster order and exit the cluster order edit mode. Click the Cancel button to revert to the original order.

DPP Status Cluster Element Order

Modifying Cluster Element Order


DPP Status Cluster Element Order

  • PAD 1 Byte before double BoardTemp.