LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing strings through .NET interface - Bug or Feature?

I am experiencing an issue passing strings to and from a .NET assembly through the LabVIEW .NET interface. I am calling a method that takes a string input. I am passing a binary data stream directly from Read from Binary File and then reading it back from another method. I can confirm that the assembly received the data and it thinks it's sending it back to me, but I only receive an empty string. Looking more closely at the data, I discovered that the first character of the data stream is a null character. If I use a simple ASCII string, I don't have any problems. If I precede the binary string with a simple ASCII string, the string is returned up until it hits the null character. I don't know C#, but apparently it doesn't use null terminated strings. So why does the LabVIEW .NET interface assume that the string is null terminated? Is this a bug, or is there a reason it works this way?

 

The code snippet doesn't actually work, but it illustrates what I'm talking about. The x=y? would be false, and the empty? would be true.

 

Thanks,

Chris

 

NET Interface Problem.png

0 Kudos
Message 1 of 2
(2,166 Views)

Using a NUL to terminiate a string is fairly common in most of the programming languages. Both C and C++ use NULLS to terminate strings. Many standard string functions don't handle binary data very well specifically because of this. I suspect that somewhere in the lower levels of the code (.NET or even the LabVIEW nodes) standard string functions are being called and the data is then truncated at the first NULL character.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 2
(2,158 Views)