Jump to content

How do I pass this structure with union into my Call Library Function Node?


Recommended Posts

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!:)

Link to comment
  • 2 weeks later...

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 by Benoit
Link to comment

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.

Link to comment
  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.