01-24-2013 05:56 PM
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
01-24-2013 07:49 PM
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?
01-24-2013 07:53 PM
Won't solve your problem, but you may want to right-click the CLFN and show the names of the parameters.
01-25-2013 02:14 AM
Hi
Thank You for an interest.
When I turned of an error checking, LV crushed completely:
Always, when I am trying different configurations, I receive the same error:
This is my function with names shown:
In addition I am attaching a result C code file constructed by default by LabVIEW from dll.
Any ideas?
01-25-2013 02:26 AM
Error checking set to Maximum makes no difference. You can see a dll configuration in attachement.
01-25-2013 04:46 AM
There is a good example that ships with Labview. Found here: C:\Program Files\National Instruments\LabVIEW 2012\examples\dll\data passing\
01-25-2013 07:21 AM
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
01-25-2013 08:44 AM
Are your strings null terminated?
01-25-2013 10:17 AM
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.
01-25-2013 11:28 AM
@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.