Jump to content

convert cluster to *(type *)&x


Recommended Posts

Yes flatten to string adds some bytes, (number of elements for instance and size of the total cluster, however you can turn the latter of).

You might be looking for the Typecast function.

However make sure you look at the section 'How LabVIEW stores data in memory' in the LabVIEW fundamentals help.

Ton

Link to comment

Is the receiving program expecting LabVIEW data, or is it expecting a C struct? If the latter, you will want to use the Type Cast function, but in order to do that you need to replace all of the arrays in your cluster with clusters containing the number of elements defined in the C struct definition. Arrays in LabVIEW have variable lengths; arrays in C are either pointers or are fixed-size. In your case you're dealing with fixed-size data, so you need to replace the LabVIEW arrays with an equivalent fixed-size structure, which is a cluster.

Link to comment

Where you have a 10-element array, you need to replace that with a 10-element cluster. There should be no arrays in the final cluster - everything must have a fixed size. Once you do that, you can wire your cluster directly to Type Cast, or use it as the Type input and wire a string to it to convert that string into the cluster. For the two-dimensional array of strings, I assume that it's actually a two-dimensional array of chars (bytes) - this is a big difference - and that the intent is to have an array of 32 strings, each 64 characters long, or vice versa. If that is case, create a cluster of 64 U8 values, then put 32 of those into another cluster. The "Array to Cluster" function speeds up this process enormously because you can enter the number of elements you want in the cluster, then create a control from it. To get string data into that format, convert the string to an array of bytes, then use array to cluster. Use the reverse process to get data back into a string from the cluster.

Here I've modified your VI to demonstrate this. In the process I removed one dimension from the string array, so that you have an array of strings, not a two-dimensional array of strings.

LS35_SetFrequency-modified.vi

  • Like 1
Link to comment

I don't understand your question. Are you trying to call a C++ function through a Call Library Function node, or are you receiving/sending data over the network to a C++ program, or both? If you're using a Call Library Function node, there is no need to type cast at all - just set the parameter type to Adapt to Type if you're passing the structure by reference. If you're sending over the network, you would always send the actual data, not a pointer, so the question would not make sense.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.