LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Import a c/c++ data structure into labview

I use a dll as a communications interface with our product.  One of the functions accepts a pointer to a data structure of mix type.  It then fills the data structure.  How do I incorportate the C/C++ data structure into labview to allow labview to then see/modify the data in the structure.  An example of the CMFTBConfigData structure is shown below.

#pragma pack(1)
struct CPIDParam
{
    char PidState;             // This is to indicate if the PID is ON or OFF (1=ON or 0=OFF)
    char PidMode;              // This is to indicate the PID Mode 0 = Manual 1= Automatic
    char PidType;              // This is to determine what parameter to be controled
                               // 0 = Flow, 1 = velocity
                               // to put it here to simplify the upload/download compatibility.
                               // 0 = indicte that assigned to PID and 1 is assigned to Meters.
    char SetptRef;             // This is to indicate the setpoint reference 0=internal,1=external
//                 char PidOutTo;                // This is to indicate where to send the PID Output 0=4-20mA,1=H-Driver
    char reserve1;                  // This is originally PidOutTo
    float PidOutLimit[2];      // This is the saturation point of the PID output
    float PidIntRefPoint;      // This the internal PID reference point
    float PidCoeff[3];         // These are the 3 proportional constant gain for the 3 terms
    float PidOffset;           // Offset to stablish the control point
    char Reserve[8];           // Reserve for future
};

struct CDriftCheck
{
    float ScaleValue[3];                // Expected output value at zero Drift check (Percent Full Scale 20 mA)
                                        // [0] = Zero Scale Value, [1] = Mid scale value, [2] = Span Scale value
    unsigned short int Duration[3];     // Time duration to perform Drift check. [0] = Zero, [1] = Mid, [2] = Span
    unsigned short int TimeInterval;    // Time for the next cycle
    char DriftChkOnOff;                 // Automatic execution (if OFF, Drift check still can be initiated by Digital Input or MODBUS
                                        // if ON, still can be override by Digital Input or Modbus Command.
};

class CMFTBConfigData
{
public:
    int m_iConfigVersion;
    char m_cVersion[17];                // Version number of the firmware.    
    char m_cEndConfig[13];                  // Configuration files Terminating charaters
    char m_cCfgVersion[17];
...
    CDriftCheck m_DriftCheck;
    CPIDParam m_PidParam;
...
};

I would like to not have to use code interface nodes to modify/view the data.

Scott Schindler
0 Kudos
Message 1 of 13
(11,592 Views)

As long as you have only numerics, you can wire a cluster to the dll. Each
entry in the cluster must have the correct number of bytes (8,16 or 32). You
probably need to swap the words and bytes of each element, to compensate the
difference in big endian and little endian. Btw. a char is simply an U8, so
it qualifies as numeric.

In the dll configuration, make the input type "Adapt to type". Now you can
wire the cluster to it.

Regards,

Wiebe.


0 Kudos
Message 2 of 13
(11,576 Views)
How do I set the order in the cluster to be in the correct order?  In C/C++ the complier orders them as it sees them.  Also I want to pass the HWND (Handle to the labview window so that the DLL's dialog box will be a have it as a parent.  How do I get the labviews HWND?
 
Scott Schindler
0 Kudos
Message 3 of 13
(11,568 Views)

Also how do I Byte swap the data programatically?

Scott Schindler

0 Kudos
Message 4 of 13
(11,566 Views)
How do I Word and Byte swap programmatically?
0 Kudos
Message 5 of 13
(11,564 Views)
You can change the cluster order by right clicking the border of the
cluster, and select "Change cluster ordering", or by dropping the controls
in the cluster in the correct order in the first place. Set the sizing of
the cluster to "Vertically allign", so you can see the ordering!

A HWND can be obtained with Windows API's (FindWindowA, FindWindowExA),
probably in User32.dll. They are not too complex, but you will probably find
them posted somewhere on this forum.

Regards,

Wiebe.


0 Kudos
Message 6 of 13
(11,561 Views)


schindler wrote:
How do I Word and Byte swap programmatically?


Look at Numeric pallette then Data Manipulation.
0 Kudos
Message 7 of 13
(11,559 Views)
Hi!

I'm trying to figure this particular problem out myself on a project.  Although I think I follow what everyone has said, a good example on how to do this would be of great use to me.

Thanks!

-Nic
0 Kudos
Message 8 of 13
(10,738 Views)

What about array of numbers?  say it was something like:

 

typedef mystruct{

  char MyChar[4];

  char MyOtherChar[4];

}

 

And I need to pass a pointer to the DLL function.  The DLL function then passes the data to my cluster in memory...  If I initialize four elements in my structure arrays, will that work?

0 Kudos
Message 9 of 13
(10,627 Views)

Hi all,

 

a good point to get information is the following PDF by NI: www.ni.com/pdf/manuals/370109a.pdf

To pass arbitrary data to a DLL (for example if you have a really complex data structure with many different types), you can write a wrapper DLL yourself in C++ that accepts LabVIEW data and converts it into a useable format for the DLL you want to communicate with. For example, to pass a struct of two arrays, you can pass the arrays alone and create the struct in the wrapper. To get an idea of how LabVIEW passes data, you can configure a Call-Library-Function-Node with an "Adapt to type"-input, wire your data, then right-click your node an choose "Create C-File". In this file, you see how your struct has to look. For example, if you take your example of a cluster of two arrays, create the following LabVIEW-Code:

 

 

You get this C-File:

typedef struct {
    int32_t dimSize;
    double element[1];
    } TD2;
typedef TD2 **TD2Hdl;

typedef struct {
    TD2Hdl elt1;
    TD2Hdl elt2;
    } TD1;

void funcName(TD1 *test1);

void funcName(TD1 *test1)
{

    /* Insert code here */

}

This means this isn't compatible to your struct.

 

Hope this helps

 

Greetings,

 

Christian

Message Edited by cschneider on 08-13-2008 10:05 PM

THINK G!! 😉
------------------------------------------------------------------------------------------------
Using LabView 2010 and 2011 on Mac and Win
Programming in Microsoft Visual C++ (Win), XCode (Mac)
Message 10 of 13
(10,623 Views)