LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to convert a char string into an array

I need to convert a char string into an array, pass it down to a dll(in C). Is the char array in labview(I am using 7.0 on WinXP) different from a char array in C? how do I do the conversion? Thanks!
Can a computer learn how to program?
0 Kudos
Message 1 of 21
(5,736 Views)
Use the String To Byte Array function found in Functions - String - String/Array/Path Conversions. This will convert a Labview string into an array of bytes. Your array should be of numerical type U8. C handles strings as an array of bytes (unsigned 8 bit integers). Each byte is the ASCII representation of the character. After conversion from string to a byte array, append a numerical 0 at the end of the array. C interprets this as the end of the string. Labview strings are defined like this: first four bytes contain the number of characters in the string (n), the next n bytes are the characters themselves. C strings are arrays with the elements being the ASCII representation of the characters, and a '\0' or NULL byte to signal the end of the string. The NULL is represented by ASCII code 0. To sum it up, wire the string to the String to Byte Array function, and wire this byte array output to Insert Into Array function with the index being the length of the array, and the element being 0. The output of the Insert Into Array can be wired into the DLL function call.
- tbob

Inventor of the WORM Global
Message 2 of 21
(5,735 Views)
Thanks for your help! When you say "wire this byte array output to Insert Into Array function with the index being the length of the array, and the element being 0" what array function do you mean? Isn't the array comes out of "Byte Array function" already a labview char array and I just need to change the last entry into 0 before I pass it to the dll? Also my original command string has no fixed size. I guess I can use "array size" node to get the dynamic size of the byte array function. But I am not sure what to do before I send this array to dll.
Can a computer learn how to program?
0 Kudos
Message 3 of 21
(5,729 Views)
After you convert your string into a byte array, you have to append a 0 to the end to signal end of string in C. The Insert Into Array function (look in Functions - Array palette) has three inputs: array, index, element. Wire the byte array to the array input. Also wire this byte array to the Array Size function. Wire the output of the Array Size function to the index input of the Insert Into Array function. This will make the index after the last element, so the function will append the element to the end of the array. Of course wire a 0 constant (U8) into the element input. The overall effect is to add a 0 to the end of the array. It does not matter what the array size is because you are using the Array Size function to dynamically define the end of the array. Now you can send the output of Insert Into Array to your DLL. See the attached vi.
- tbob

Inventor of the WORM Global
Message 4 of 21
(5,707 Views)
Why not just use the build array with the array input and a numeric 0 as the two inputs as in the attached file?
Message 5 of 21
(5,701 Views)
Oops. Here's the attachment
Message 6 of 21
(5,700 Views)
Thanks for such detailed help, but I am using labview 7.0 and can't open your VI. I am starting to try what you have described. Thank you again!
Can a computer learn how to program?
0 Kudos
Message 7 of 21
(5,689 Views)
Thank you very much for the generous help! but I am using labview 7.0 and can't open your attached VI, >_<. I am going to try the method you've suggested, Thanks again!
Can a computer learn how to program?
0 Kudos
Message 8 of 21
(5,687 Views)
Here it is in 7.0.
Message 9 of 21
(5,679 Views)
This is another great way of doing it! Thanks, I am going to wire the hardware to my program and test it now, thousand thanks to you all!
Can a computer learn how to program?
0 Kudos
Message 10 of 21
(5,676 Views)