LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

wrong scan from binary string

Hello everybody,

I need to decode binary data that is sent over TCP/IP into U32 and DOUBLE variables. For example the first 4 bytes represent U32, the following 8 bytes DOUBLE and so on. For some reason I wanted to split the string first into substrings with the "scan from string" function and then unflatten the substrings. Doing this I ran into the problem that sometimes variables aren't unflatted correctly. Take the attached vi and set "double in " to "12,1200". "double out" is then "0", unflatten from string returns with an error. But "double out 2" shows the correct result. Another problem occurs when you set "double in" to "0" and "u32 in" to "3503": "u32 out" and "double out" show wrong results. Again, the second output variables are ok. And there are many more strange cases.

Has anybody an explanation for this? I could work around it with clusters, but I'd really like to know whats going on here....

Thanks for your comments,
Clemens
0 Kudos
Message 1 of 5
(2,724 Views)

I am not sure why the scan from string does not always give the numbers correctly (also try e.g. 23; 3.14 and the U32 is correct but the DBL is zero), but somehow I would have never thought using it this way. 😉

 

Why don't you make your life a bit easier and just unflatten it as an ordered cluster? 🙂 (see attached, LabVIEW 7.1)

Message Edited by altenbach on 07-25-2005 10:02 AM

0 Kudos
Message 2 of 5
(2,717 Views)
Clemens,

I think the following quote from the help files may explain:

"Use the following conversion codes for a string:
s—String (for example, abc). When scanning, s matches only up to the next white-space character. A space matches one or more consecutive white-space characters. To scan a string that may contain white space, use the characters in set conversion code. Specify all the characters which the string may contain within the brackets, including space or other white-space characters."

Your data contains "white space characters." Specifically the 3503 converts to 0000 0DAF. The 0D part is Carriage Return, a white space character.

Read the help in more detail to see how to scan strings with these characters. Since you know the number of characters, why not split the string using Search/Split String from Additional String Functions?

Lynn
0 Kudos
Message 3 of 5
(2,712 Views)
Hi Altenbach,

I agree that clusters would be good to use. I came to use "scan from string" because the messages vary in length and data and I didn't want to have separate clusters for each type of message. The other reason was that in one case I need to split the datastring in any case because the same message type can contain more or less data so that I cannot use a fixed cluster to decode it in one run. Using "string subset" to get several substrings looked unconvenient to me compared to using "scan from string" once.

And finally I got curious if there was a bug in Labview....

Regards Clemens


0 Kudos
Message 4 of 5
(2,709 Views)
Hi Lynn,

I think you're right with the whitespaces. "Search/split string" is too much wiring- I just used two variables for the example vi, but the messages I need to decode contain much more data. So I probably should go the "cluster way".

Thanks everybody,
Clemens
0 Kudos
Message 5 of 5
(2,707 Views)