LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Pass struct by value

Hi

 

Sorry for duplicating this topic repeadly, but I need assistance.

 

I am trying to call a function OpenPort in Dll that has a struct on the input, as shown below


extern uint8_T        (_stdcall *RMsys__OpenPort)(uint8_T, uint8_T*, uint8_T, TPortComParams);

 

typedef struct {
  uint32_T       TimeOut;
  uint32_T       OpenDelayTime;
  uint8_T        StopByte;
  uint32_T       BufferSize;
  //-------------- RS232 -------------------------
  uint32_T       Baud;
  uint8_T*       Parity;
  uint8_T*       Handshake;
  uint8_T        DataBits;
  uint8_T        StopBits;
  uint8_T        StartByte;
  //-------------- IP Based Connection -----------
  uint8_T*       Host;
  uint16_T       Port;
  uint8_T*       Protocol;
  uint8_T        HostMode;
  //-------------- Proemion Based Connection -----
  uint8_T*       //-------------- CANlink GSM 2xxx and 5xxx -----                                    
    UserName;
  uint8_T*       UserPassword;
  uint8_T*       DeviceIMEI;
  uint8_T*       DevicePassword;
  //-------------- CANlink GSM 5xxx --------------
  uint8_T*       UsrMyEMail;
  uint8_T*       UsrAppName;
  uint8_T*       WebServiceIP;
  uint16_T       WebServicePort;
  boolean_T      UseWindowsProxy;
  uint8_T        AppProxySet;
  uint8_T*       AppProxyIP;
  uint8_T*       AppProxyUsrName;
  uint8_T*       AppProxyUsrPwd;
  //-------------- VCI Driver --------------------
  uint8_T        CANidType;
} TPortComParams;


Passing structure by value can be accieved in LabVIEW simply by passing every parameter individually (http://forums.ni.com/t5/LabVIEW/Interface-dll-function-with-struct-in-LabVIEW/td-p/1490848/page/2), therefore this I tried to do. I've configured each number as a proper number and passed by values, strings are passed as an arrays of U8 (Array Data Pointer), and they are never empty, as there is always some text on each input, and a boolean I am passing as an I32 (I have 64-bit system, but I am using a 32-bit LabVIEW version, besides, I tried also 64 bits). You can see a code below.

 

Can anybody give me any suggestions, about what is wrong in here? I have already run out of ideas.

 

Thank You in advance for any help.

 

Best regards

 

Barbara

 

ui.png

0 Kudos
Message 1 of 11
(4,113 Views)

What is the indication that it's not working? Do you get any errors? Have you checked the error out terminal from the Call Library Function Node? Does it make a difference if you configure the Call Library Error Checking level to Maximum?

0 Kudos
Message 2 of 11
(4,094 Views)

Won't solve your problem, but you may want to right-click the CLFN and show the names of the parameters. 

0 Kudos
Message 3 of 11
(4,092 Views)

Hi

 

Thank You for an interest.

 

When I turned of an error checking, LV crushed completely:

InCaseOfErrorsDisabled.PNG

 

Always, when I am trying different configurations, I receive the same error:

error.PNG

 

This is my function with names shown:

DLL names.PNG

 

In addition I am attaching a result C code file constructed by default by LabVIEW from dll.

 

Any ideas?

 

0 Kudos
Message 4 of 11
(4,074 Views)

Error checking set to Maximum makes no difference. You can see a dll configuration in attachement.

0 Kudos
Message 5 of 11
(4,070 Views)

There is a good example that ships with Labview. Found here: C:\Program Files\National Instruments\LabVIEW 2012\examples\dll\data passing\


CLA CTAChampionI'm attending the GLA Summit!
Subscribe to the Test Automation user group: UK Test Automation Group
0 Kudos
Message 6 of 11
(4,051 Views)

Thank You aCe for pointing this example. It is really great. Unfortunatelly, all of the structures are passed to dlls by references in there, so I cannot use it. Still, it gave me new ideas for troubleshooting. As I am assuming, that either boolean value either strings a causing an issue, I played with and tested all of the combinations, that I could think of (see below). Still, I am not capable of calling this function. Can anybody please think of something else I could try? Any suggestions are welcome.

 

 

 

>>     Boolean     - adopt to source    - handles by value
    >> string     - String            - C string pointer            No
    >> string     - String            - C string handle pointer    No
    >> string     - String            - String handle                No
    >> string     - Array                - Array Data Poiter            No
    >> string     - Array                - Array Handle                No
>>     Boolean     - Numeric I32        - Value
    >> string     - String            - C string pointer            No
    >> string     - String            - C string handle pointer    
    >> string     - String            - String handle            
    >> string     - Array                - Array Data Poiter            No
    >> string     - Array                - Array Handle                No
>>     Boolean     - Numeric I16        - Value
    >> string     - String            - C string pointer            No
    >> string     - String            - C string handle pointer    No
    >> string     - String            - String handle                No
    >> string     - Array                - Array Data Poiter            No
    >> string     - Array                - Array Handle                No
>>     Boolean     - Numeric U8        - Value
    >> string     - String            - C string pointer            No
    >> string     - String            - C string handle pointer    No
    >> string     - String            - String handle                No
    >> string     - Array                - Array Data Poiter            No
    >> string     - Array                - Array Handle                No

0 Kudos
Message 7 of 11
(4,040 Views)

Are your strings null terminated?

Message 8 of 11
(4,030 Views)

You may need to manually allocate/deallocate the memory for your strings. I had to do this with a DLL I worked with. There are three LabVIEW VIs that may help. They are DSNewPtr.vi, GetValusByReference.vi and DSDisposePtr.vi. You can find them in vi.lib\utility\imports. They are not documented anywhere but they are fairly self explanatory. If you need to set values into these memory blocks you can use the kernel32.dll:RtMoveMemory call to do that.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 9 of 11
(4,021 Views)

@Darin.K wrote:

Are your strings null terminated?


That's probably exactly the problem.

 

The easiest way to fix this is to configure the CLFN to pass all the strings as C strings. From the DLL's point of view it's still receiving a pointer to an array of U8, but LabVIEW will add the null termination automatically.

0 Kudos
Message 10 of 11
(4,011 Views)