LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array of Strings as a Call Library Function Node parameter

Is it possible to pass a array of Strings as a parameter using only the block diagram? I can build writing a C wrapper, but I am trying to do it using only the block diagram.

In C, I have a code like that:

...
char                    Names[5][Name_Len];
char                    Values[5][Value_Len];
...
sprintf(Paths[0], "/Paramenter 1");
sprintf(Paths[1], "/Second Parameter");
sprintf(Paths[2], "/Another one");
...

getValues(Paths, Values);

How can I do it? If it is not possible, why?

Thank you in advance.


0 Kudos
Message 1 of 9
(6,073 Views)

Because the way Labview handles strings is so different than the way C handles strings, it would be very difficult to do this with your particular array without using a wrapper.  If it were simple strings or a 1D array of char, this is how it could be done, as long as all the strings are the same length.  Sorry, I can't include a picture or some code because I am not at my work computer, so I will try to explain.

Convert each char array to a byte array.  You would then have an array of byte arrays.  This big array must be converted into a cluster.  Right click on the Array to Cluster function and set the length of the cluster to the length of the byte array.  There is a limit on how big it can be, forgot what it was.  Do the same for the second string array.  Then bundle all into a bigger cluster.  Pass the bigger cluster (cluster of clusters of arrays of byte arrays) into the Call Library Node, set parameter to Adapt to Type, and data format to Pointers to Handles.

Now for your problem.  You have a 2D array of char.  In order to get by with this, you would have to list each row separately as 1D arrays.  Convert each one into clusters, and then bundle all into a cluster.  So your final cluster would have 5 clusters of byte arrays of Name_Len elements and 5 clusters of byte arrays of Value_Len elements.  Whew!  Try it if you dare, or just write a wrapper.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 9
(6,064 Views)
It didn't work properly what I tried. If it possible to send a example, later, of what you wrote about, it will be heplfull.

Thank you in advance

Correcting the code:

char                    Names[5][Name_Len];
char                    Values[5][Value_Len];
...
sprintf(
Names[0], "/Paramenter 1");
sprintf(
Names[1], "/Second Parameter");
sprintf(
Names[2], "/Another one");
...

getValues(
Names, Values);

Message Edited by gborges on 08-21-2006 02:58 PM

0 Kudos
Message 3 of 9
(6,056 Views)
I tried something like this attached file.

What I could observe is that when I tried to get only one parameter, passing only the "/parameter1" to the cluster, the code work correctly. But when I try something like the attached file, getting many parameters in the same time, I get only invalid data. The code in C works well.

Maybe, I can corret this, passing a NULL value separating the parameter's names that I want to collect. So, I think labview will understand where "one parameter starts and where it ends". Do you know how can I get NULL value in LabVIEW? In C code, I use \00.


Message Edited by gborges on 08-22-2006 07:21 AM

0 Kudos
Message 4 of 9
(6,042 Views)

A picture is worth more than 1000 words:

Message Edited by tbob on 08-22-2006 09:42 AM

- tbob

Inventor of the WORM Global
Message 5 of 9
(6,032 Views)

This seems to be very close to what I need, but it doesn't quite work.

 

I have to interface to a DLL which has the following parameter list:

DLLEXPORT int test_string_array(unsigned int argc, const char *argv[], char *str_ret);

 

And the char *argv[] is causing me a lot of problems.

 

I tried the method mentioned here, as well as a 2-d byte array, using various ways of combining them (build array, build cluster, bundle, etc). 

Nothing I tried seemed to work.

 

I guess char *argv[] is an array of pointers to chars. So is there a way to get labview to interface to this datatype?

It would be a huge help if someone could provide any info on this at all!

0 Kudos
Message 6 of 9
(5,045 Views)

I have the same problem. Great if someone can come up with a solution 🙂

0 Kudos
Message 7 of 9
(4,618 Views)

If you really want to do an array of string pointers, contrary to an array of fixed size arrays, then you will either have to write a wrapper in C or get your brain cells cooked in trying to come up with a solution that generates the necessary array on the LabVIEW diagram using numerous calls to the LabVIEW memory manager functions DSNewPtr(), MoveBlock() and DSDisposePtr() in a loop. This will created code that is:

 

- painful to maintain for future releases of your application including moving to different platform

- not possible to move between 32 bit and 64 bit of LabVIEW without two different diagram sections for each version

- a bitch to debug until you get it not to crash

- even if you do not crash you are very likely to still corrupt some memory somehow because you got the offsets and lengths somewhere wrong. This not crashing bugs are the most fun, since they corrupt somewhere memory that will eventually crash your program anyhow, but sometimes only hours or days after the corruption happened.

 

Basically writing such a solution in the LabVIEW diagram will require you to know a lot more about C compilers and how they are aligning and setting up pointers and such stuff in memory than if you wrote the wrapper DLL. So those not able to create a DLL in C are lost anyhow and those who know how to do it in C will surely go for the wrapper solutions, since that is much easier to maintain in the long run.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 8 of 9
(4,603 Views)

Here's one way you can do it in LabVIEW, although as Rolf explained it does require the use of several LabVIEW memory manager calls:

http://lavag.org/topic/14642-passing-array-of-string-to-c-dll/#entry87758

0 Kudos
Message 9 of 9
(4,589 Views)