12-02-2014 04:55 AM
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!
12-02-2014 05:28 AM - edited 12-02-2014 05:30 AM
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.
12-02-2014 06:36 AM
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.
12-02-2014 07:18 AM
Hi,
It's the same way (s. Attachment)?
12-02-2014 07:29 AM - edited 12-02-2014 07:30 AM
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:
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.
12-02-2014 08:07 AM
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!
12-02-2014 08:12 AM
Use Reverse 1D array on the boolean array and it will reverse the order of the bits in the byte (change endianness).
12-02-2014 08:35 AM - edited 12-02-2014 08:36 AM
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).
12-03-2014 04:39 AM
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!
12-03-2014 05:53 AM
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.