rk1960in Posted August 17, 2011 Report Share Posted August 17, 2011 Hello, I need to fill in the structure that C++ provide in LV and send using UDP. I create a cluster but UPD write function only takes in string. How can cluster be send using UDP write? Flatten to string function seems to add more bytes to it. Thanks! Quote Link to comment
Ton Plomp Posted August 17, 2011 Report Share Posted August 17, 2011 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 Quote Link to comment
ned Posted August 17, 2011 Report Share Posted August 17, 2011 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. Quote Link to comment
rk1960in Posted August 17, 2011 Author Report Share Posted August 17, 2011 Yes the program expects C struct and not LabVIEW data. Could you please elaborate on " you need to replace all of the arrays in your cluster with clusters containing the number of elements defined in the C struct definition." In the attached VI I believe I do what u are suggesting, even then how does this data gets passed to typecast function? TIA. LS35_SetFrequency.vi Quote Link to comment
ned Posted August 17, 2011 Report Share Posted August 17, 2011 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 1 Quote Link to comment
rk1960in Posted August 18, 2011 Author Report Share Posted August 18, 2011 Thanks a lot ned for helping:) Quote Link to comment
rk1960in Posted August 19, 2011 Author Report Share Posted August 19, 2011 On the same topic: Type cast function cast the data as *(char *) &data. The C++ code I noticed needs the data as (char *) &data. I am uncertain the way labVIEW cast and send the pointer, if it will be interpreted correctly by C++, if not is there a approach for it? Quote Link to comment
ned Posted August 22, 2011 Report Share Posted August 22, 2011 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. 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.