From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DLL Call library function typedef struct

Solved!
Go to solution

Dear all,

 

I know that this topic rises several times in the past, but I did not found helpful suggestion in that posts.

Can you please help me to get the correct cluster for a typedef struct for a call library function node.

 

I want to send and receive CAN frames to and from a gas sensor.

The CAN converter is USB connected and only programmable by a DLL.

 

Please find attached the typedef struct description from the DLL API manual and a VI with call library function to get the board info.

 

typedef struct _VCI_BOARD_INFO {
USHORT hw_Version;
USHORT fw_Version;
USHORT dr_Version;
USHORT in_Version;
USHORT irq_Num;
BYTE can_Num;
CHAR str_Serial_Num[20];
CHAR str_hw_Type[40];
USHORT Reserved[4];
} VCI_BOARD_INFO, *PVCI_BOARD_INFO;

 

hw_Version
Hardware version number, hexadecimal notation. E.g. 0x0100 represents V1.00.
fw_Version
Hardware version number, hexadecimal notation. E.g. 0x0100 represents V1.00.
dr_Version
Driver version number, hexadecimal notation. E.g. 0x0100 represents V1.00.
in_Version
Interface library version number, hexadecimal notation. E.g. 0x0100 represents V1.00.
irq_Num
System reserved.
can_Num
Represents the total number of CAN channel.
str_Serial_Num
This board card's serial number.
str_hw_Type
Hardware type, such as “USBCAN V1.00” (Note: Includes string terminator ’\0’).
Reserved
System reserved.

 

---

DWORD __stdcall VCI_ReadBoardInfo(DWORD DevType,DWORD DevIndex,PVCI_BOARD_INFO pInfo);
Parameters:
DevType
Device type. See: Adapter device type definition.
DevIndex
Device Index, for example, when there is only one USB-CAN adapter, the index number is 0, when there are multiple USB-CAN adapters, the index numbers in an ascending order starting from 0.
pInfo
VCI_BOARD_INFO is used to store device information structure pointer.
Returns:
Return value = 1, which means that the operation is successful; = 0 indicates that the operation failed; = -1 indicates that the device does not exist.

0 Kudos
Message 1 of 11
(1,813 Views)
Solution
Accepted by topic author MOJO_FZJ

You cannot use nested arrays in the cluster. LabVIEW will pass their handles in the cluster to which is not what the library expects. It wants fixed sized arrays.

Either convert your arrays to clusters using array to cluster and the appropriate size.

Or pass a byte array of at least sizeof(_VCI_BOARD_INFO) elements by pointer. You can take it apart element by element in LabVIEW after the call.

The data type for can_Num, str_Serial_Num and str_hw_Type should be u8.

Message 2 of 11
(1,755 Views)

Thank you for your advice!

 

I use array to cluster and it works fine.

 

MOJO_FZJ_0-1669740718913.png

 

But I am now stuck with the receive function. Can you please help me again?

 

DWORD __stdcall VCI_Receive(DWORD DevType, DWORD DevIndex, DWORD CANIndex, PVCI_CAN_OBJ pReceive, ULONG Len, INT WaitTime);

 

the C example looks like that:

#include "ControlCan.h"
int nDeviceType = 4; /*USB-CAN2.0 */
int nDeviceInd = 0; /* zeroth device */
int nCANInd = 0;
long lRel;
VCI_CAN_OBJ vco[2500];
lRel = VCI_Receive(nDeviceType, nDeviceInd, nCANInd, &vco,2500,0);

 

--> Do I have to build a cluster with 2500 elements for VCI_CAN_OBJ or what does VCI_CAN_OBJ vco[2500] mean?

The solution above does not work in this case.

 

0 Kudos
Message 3 of 11
(1,728 Views)

@MOJO_FZJ wrote:

 

 

--> Do I have to build a cluster with 2500 elements for VCI_CAN_OBJ or what does VCI_CAN_OBJ vco[2500] mean?

The solution above does not work in this case.


That's exactly what it means. It depends on what VCI_CAN_OBJ is if this is going to be a total pita or just a bit of an annoyance.

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 11
(1,720 Views)

When one has never worked with "array to cluster" and sees this code

 

LLindenbauer_0-1669741549047.png

 

one (as I certainly did) might assume that the cluster leaving on the right will have 21 elements. That is almost certainly wrong.

 

The size of the resulting cluster is determined by right-clicking the array-to-cluster node. The size of the array on the input is ignored. It must be, because you can't have variable sized clusters in a statically typed language.

0 Kudos
Message 5 of 11
(1,717 Views)

Ahh thanks, you can reduce it to:

 

MOJO_FZJ_0-1669745691998.png

 

0 Kudos
Message 6 of 11
(1,691 Views)

rolfk, do you have an idea for a better solution?

VCI_CAN_OBJ is the structure to send and receive CAN frames.

 

typedef struct _VCI_CAN_OBJ {
UINT ID;
UINT TimeStamp;
BYTE TimeFlag;
BYTE SendType;
BYTE RemoteFlag;
BYTE ExternFlag;
BYTE DataLen;
BYTE Data[8];
BYTE Reserved[3];
}VCI_CAN_OBJ, *PVCI_CAN_OBJ;

 

Can you confirm, that I have to build a cluster A for VCI_CAN_OBJ like I learned before and than build a cluster B with 2500 elements of cluster A?

0 Kudos
Message 7 of 11
(1,677 Views)
Solution
Accepted by topic author MOJO_FZJ

Array to cluster can only build clusters of up to 256 elements. If I'm interpreting that function call right you can use a smaller array if you match the second-to-last parameter of the function call.

 

You can create a cluster for VCI_CAN_OBJ, flatten it to string, get its length, initialize a byte array with n*length and pass that array by pointer to the dll. Then unflatten the data.

 

cordm_1-1669756858328.png

 

 

Something like this.

 

Message 8 of 11
(1,651 Views)
Solution
Accepted by rolfk

It’s even simpler. You only need to create the cluster itself for VCI_CAN_OBJ correctly. Then initialize an array of it. Configure the parameter as Adapt to Type and Pass as: Array Data Pointer. Make sure to pass for the next parameter a value that is NOT greater than the number of array elements you initialized. 

Rolf Kalbermatter
My Blog
Message 9 of 11
(1,632 Views)

rolfk & cordm KUDOS to you!!!

 

Thank you so much for your help. Unfortunately I can only mark one post as solution.

cordm, it is not something like that, it is exactly like that : D

and here a picture to visualize rolfk solution:

 

MOJO_FZJ_0-1669779425773.png

 

Message 10 of 11
(1,615 Views)