Fred chen Posted April 13, 2018 Report Share Posted April 13, 2018 Trying to call the function below: typedef struct tagZCAN_CHANNEL_INIT_CONFIG { UINT can_type; //0:can 1:canfd union { struct { UINT acc_code; UINT acc_mask; UINT reserved; BYTE filter; BYTE timing0; BYTE timing1; BYTE mode; }can; struct { UINT acc_code; UINT acc_mask; UINT abit_timing; UINT dbit_timing; UINT brp; BYTE filter; BYTE mode; USHORT pad; UINT reserved; }canfd; }; }ZCAN_CHANNEL_INIT_CONFIG; CHANNEL_HANDLE ZCAN_InitCAN(DEVICE_HANDLE device_handle, UINT can_index, ZCAN_CHANNEL_INIT_CONFIG* pInitConfig); Can anyone give me some tips on how to pass this structure with union into DLL? Thanks for any help you can provide! Quote Link to comment
Zou Posted April 13, 2018 Report Share Posted April 13, 2018 Create a wrapper dll in C to simplify the io parameter type. Quote Link to comment
Benoit Posted April 26, 2018 Report Share Posted April 26, 2018 (edited) A wrapper will give him the same situation and create another unnecessary layer. Did you know that a Cluster is what you are looking for? in your case, it will be two cluster into another one. You can create your own header file (.h) and import your .dll into LabVIEW. That would be much better solution Note that the UINT is a separate parameter. Edited April 26, 2018 by Benoit Quote Link to comment
Rolf Kalbermatter Posted April 28, 2018 Report Share Posted April 28, 2018 I'm sorry Benoit but your explanation is at least misleading and as I understand it, in fact wrong. A C union is not a cluster but more like a case structure in a type description. The variable occupies as much memory as the biggest of the union elements needs. With default alignment these are the offsets from the start of the structure: typedef struct tagZCAN_CHANNEL_INIT_CONFIG { /* 0 */ UINT can_type; //0:can 1:canfd union { struct { /* 4 */ UINT acc_code; /* 8 */ UINT acc_mask; /* 12 */ UINT reserved; /* 16 */ BYTE filter; /* 17 */ BYTE timing0; /* 18 */ BYTE timing1; /* 19 */ BYTE mode; } can; struct { /* 4 */ UINT acc_code; /* 8 */ UINT acc_mask; /* 12 */ UINT abit_timing; /* 16 */ UINT dbit_timing; /* 20 */ UINT brp; /* 24 */ BYTE filter; /* 25 */ BYTE mode; /* 26 */ USHORT pad; /* 28 */ UINT reserved; } canfd; }; }ZCAN_CHANNEL_INIT_CONFIG; So the entire structure will occupy 32 bytes: the length of the canfd structure and the extra 4 bytes for the can_type variable in the beginning. The variant where a can message is described only really occupies 24 bytes, and while you can pass in such a cluster inside a cluster with the can_type value set to 0 if you send the value to the function for reading you always will have to pass in 32 bytes if the function is supposed to write a message frame into this parameter as you might not know for sure what type the function will return. Quote Link to comment
ShaunR Posted April 29, 2018 Report Share Posted April 29, 2018 With these types of parms I usually pass in an array of bytes. ZCAN_CHANNEL_INIT_CONFIG.vi 1 1 Quote Link to comment
Fred chen Posted June 21, 2018 Author Report Share Posted June 21, 2018 Thanks for the reply. I'm doing the wrapper dll now. My project is a little complicated. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.