From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Binary to String

Solved!
Go to solution

Hello,

  I am getting a very weird issue when I get a binary value out of a database and cast it to a string. If I use an indicator to show the string it looks ok, with what appears to be spaces in between characters. However, the spaces actually seem to be something else, string functions do not recognize them as spaces and neither does probing them.

 

BinaryToString.png

 

As you can see, the value is shown simply as "[" while the probe indicator shows my full string as "[ 9 ] [ 1 ]". Does anyone have any idea what issue I am running into?

 

EDIT: I have included a very quick VI to illustrate my issue. It simply passes my weird string from control to indicator. Visually it appears fine, but if you probe the wire in between you'll see the issue. Also, if you copy and paste from the indicator or control into another program you will also see the issue.

 

Thank you very much,


Corey Rotunno

0 Kudos
Message 1 of 7
(3,573 Views)

Hello,

  I am getting a very weird issue when I get a binary value out of a database and cast it to a string. If I use an indicator to show the string it looks ok, with what appears to be spaces in between characters. However, the spaces actually seem to be something else, string functions do not recognize them as spaces and neither does probing them.

 

BinaryToString.png

 

As you can see, the value is shown simply as "[" while the probe indicator shows my full string as "[ 9 ] [ 1 ]". Does anyone have any idea what issue I am running into?

 

Thank you very much,


Corey Rotunno

0 Kudos
Message 2 of 7
(3,564 Views)

91 decimal is the equivalent to the ascii character "["  

0 Kudos
Message 3 of 7
(3,571 Views)

Hmm, you might be on to something here. However, if I show my string in a string indicator it appears correctly as "[ 9 ] [ 1 ]". The probe window I showed is actually probing a string "wire", so the conversion has already taken place.

 

However if I copy the string from the indicator and paste it here it appears as just "[". Thanks for the reply, that gives me an idea or two.


Corey Rotunno

0 Kudos
Message 4 of 7
(3,566 Views)

So, I sort of resolved my issue although I am still really curious I was seeing what I was seeing. Seems as if the "spaces" I was seeing had binary values of 0, instead of 32 which is ascii for space. When I removed those ghost characters everything works fine.


Corey Rotunno

0 Kudos
Message 5 of 7
(3,548 Views)
Solution
Accepted by topic author Corey.Rotunno

Did you notice that every other character is a null (a zero value)?  Have you ever heard of Unicode, a string encoding mechanism that uses 16 bits to represent a character rather than the 8 bits that ASCII uses?  Perhaps your string is being saved as Unicode, which is the simplest explanation for what you are observing.

 

Bob Schor

Message 6 of 7
(3,532 Views)

Bob,

 

  I think you are right. I got the string included in my posts out of a database created by TestStand. If I go to the database schema configuration dialog, it shows the entry I am interested in as datatype "String(BTSR)". When I read about BTSR I see that a BTSR is a null-terminated Unicode string, with a byte count. I think my issue presented itself because when I read the BTSR string out of the database I read it out in raw binary, then used labview to convert it back to text. When I request it as an actual string from the database it comes in just fine.

 

Thanks for your input,

 

 


Corey Rotunno

0 Kudos
Message 7 of 7
(3,480 Views)