LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Text to binary, binary to text.

Hello.

 

We ave a project where we send information, bit by bit, with a laser, via a liquid crystal-cell which either lets the laser through or not, to a photovoltaic cell which then feeds the information recieved back to LabVIEW via a NI USB-6003 DAQ. The signal is defined as a 1 or 0 by determening if it is higher than a measured limit.

 

We would like some help with converting text to binary for the sending of the signal, and binary to text when recieving. As of now, we can only input 1's and 0's in the string control to generate the signal (sending either 48 or 49 to the case structure). We have yet to come up with a solution for interpreting the recieved data as text.

 

What we would like to be able to do is converting ascii characters put in to the string to binary and sending them one by one in to the case structure (either generating or not generating a signal). The receiver part should interpret every sequence of eigth values (e.g. 10011010) and convert this back to a letter/symbol and showing these in an output string. 

 

Our labview knowledge is very limited (never used it before this project) and if someone could help us construct this it would be much appreciated. Our current VI is attached.

 

Thanks!

0 Kudos
Message 1 of 12
(7,274 Views)

Use the string to byte array / byte array to string function (String -> Array/Path/String conversion palette). This will convert your string into an array of U8 (bytes) which you can then read/write. 

 

You can also use boolean array to number/number to boolean array to convert between an array of booleans and the U8. These are in the boolean palette.

 

You can also use the rotate left / rotate right functions to read the bits out of your number one bit at a time (and store the output in a shift register - essentially popping one bit from the number each time). These are in the numeric -> data manipulation palette.

 

I couldn't open your VI to see exactly what input/output type you're expecting as I don't have LV2014 but that should point you in the right direction.

 

 

 

 


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 2 of 12
(7,257 Views)

Yes, we've tried using the conversion from string to the U8 array, but the problem is that all we get from this is numeric values. Example, h in the string results in "104" instead of "01101000". 

 

Here's a print screen and we attached a 2012 VI.

 

KorvarVI.jpg

0 Kudos
Message 3 of 12
(7,239 Views)

Hi,

 

It's the same way (s. Attachment)?

0 Kudos
Message 4 of 12
(7,223 Views)

Ah ok, now I can see the VI it makes a bit more sense now what you're trying to do. You can right click on the numeric and click 'show radix' which will allow you to display the number in decimal (104) or boolean (0b01101000) - it's the same data (a byte - 8 bits) just displayed in a different format.

 

This should give you an idea of how you can convert a string into a boolean array and write it out bit by bit:

String To Boolean Array.png

 

The reverse is very similar - take each bit you read and every 8th one convert it to a byte (U8) and then convert to a character and add it to your string.


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 5 of 12
(7,218 Views)

Hello again and thanks for your help so far.

 

The array function you presented works fine, except that each character is now sent in the wrong "direction". We get that we can flip the order of the whole array, but the "subelements", in this case the 1's and 0's for each specific characters is sent in the wrong order.

 

Do you get what I'm trying to explain?

 

Thanks again!

0 Kudos
Message 6 of 12
(7,202 Views)

Use Reverse 1D array on the boolean array and it will reverse the order of the bits in the byte (change endianness).


LabVIEW Champion, CLA, CLED, CTD
(blog)
Message 7 of 12
(7,198 Views)

I find it a little more efficient to use the Rotate Left/Right With Carry function instead of the Number To Boolean Array.  It is one less array that the memory manager needs to worry about.  It also makes it easier to state which direction your booleans come out (rotate right for LSB first, rotate left for MSB first).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 8 of 12
(7,191 Views)

Thank you, the conversion from the string to the signal generator now works perfectly!

 

The problem is to get it to work the other way around, at the signal receiver part. First of all the signal generated by the receiver (the part after the "greater or equal") is "dynamic data" which seems to create some problems. We want eight values to be saved to an array, interpreted as a character and put in to the string. We have been trying to get this to work without any real results so again we are asking you for your help.

 

Thanks in advance!

0 Kudos
Message 9 of 12
(7,148 Views)

What have you tried?

 

Do the exact same in reverse. Rotate in the other direction, feeding in the boolean to a number and store the output in a shift register, every 8 times you read a value ([i] terminal with quotient/remainder) convert that number to a string (reinitialise the byte) and do something with it (e.g. concatenate strings and store in another shift register).

 

The express VIs for receiving your data make it very easy to acquire and plot data but not for much else (not very efficient, DDT is difficult to work with etc.), you would be better off converting it to use the DAQmx VIs. You can also initialise the measurement before the loop and close it after the loop as this will improve performance.


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 10 of 12
(7,137 Views)