Jump to content

passing a struct to a labview library function

Recommended Posts

I want to pass a struct to the library function.

this is the code from the function:

EXTERN_C SV_GEN_SDK_API SV_RETURN SVLibSystemGetInfo(uint32_t uiIndex, SV_TL_INFO *pInfoOut);

/** SVLibSystemOpen
   *  Opens the System module and puts the instance in the phSystem handle. This allocates all system wide
   *  resources. A System module can only be opened once.
   *  @param [in] uiIndex  Zero-based index of loaded GenTLProducers.
   *  @param [out] phSystemOut System module handle.
   *  @return success or error code

this is the struct I want to pass to the function:

typedef struct _SV_TL_INFO
    char id[SV_STRING_SIZE];
    char vendor[SV_STRING_SIZE];
    char model[SV_STRING_SIZE];
    char version[SV_STRING_SIZE];
    char tlType[SV_STRING_SIZE];
    char name[SV_STRING_SIZE];
    char pathName[SV_STRING_SIZE];
    char displayName[SV_STRING_SIZE];
    uint32_t gentlVersionMajor;
    uint32_t gentlVersionMinor;
    int32_t encoding;


1.png shows my labview architecture

2.png show how I call this function


I tried almost all of the parameter permutations to call this function but my program keeps on crashing. I'm on debian.






Link to comment
1 hour ago, thenoob94 said:

I tried almost all of the parameter permutations to call this function but my program keeps on crashing.

No, don't pass LabVIEW arrays straight to the cluster! They are different entity than those in C/C++. In order to match your struct definition, you have to turn each array into a separate cluster. Use Array To Cluster primitive for that. RMB click -> Cluster size on it allows you to specify the output cluster size. Then bundle all the clusters into one (plus three int parameters), then pass that resulting cluster to your CLFN. I assume, you know your .so's calling convention.

Oh, I forgot to add, that Array To Cluster node doesn't accept more than 256 elements. So, if SV_STRING_SIZE is 512, you need to make a pairs of 256+256 elements (e.g., two "id" clusters, two "vendor" clusters etc.). There's another way with DSNewPtr+MoveBlock, but it's a bit more advanced.

Edited by dadreamer
added more info
  • Like 1
Link to comment

Join the conversation

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

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.