05-25-2013 07:22 AM
Hello, I am reading in two bytes using a VISA READ and then output is a string. However I want to be able to Access these bytes individually because I need to left shift the first byte 8 places and then add it to the second byte and then left shift their sum 4 places to the left giving me a signed 16 bit int. I then need to display this in a waveform chart. Can anyone help please?
Solved! Go to Solution.
05-25-2013 07:34 AM - edited 05-25-2013 07:35 AM
I'm not understanding the final bit shift, but all you really need to do is use the Type Cast to change the string into an I16, perform the left shift, and write to your chart.

05-25-2013 08:10 AM
Thanks very much. The reason for the strange manipulation is that the two bytes were from two measurment 8 bit registers of a 12 bit adc and the first register (first byte) contained 4 MSBs and the second register (second Byte) contained 8 LSBs. I think what you have suggested will be sufficient though.
Thanks again
lking
05-25-2013 09:53 AM
Sorry for not being clear enough in my first post.
After realising I need to access the bytes individually because I need to left shift the first byte 8 places as this is the MSB of a twelve bit ADC. After I do this I need to perform addition on the first byte and the second byte and then left shift the result 4 places. This 16 bit integer is then required to be plotted in a waveform chart.
Again help appreciated (under pressure to get this done!)
lking...
05-25-2013 01:24 PM - edited 05-25-2013 01:54 PM
@lking wrote:
Sorry for not being clear enough in my first post.
After realising I need to access the bytes individually because I need to left shift the first byte 8 places as this is the MSB of a twelve bit ADC. After I do this I need to perform addition on the first byte and the second byte and then left shift the result 4 places. This 16 bit integer is then required to be plotted in a waveform chart.
Again help appreciated (under pressure to get this done!)
This is still not clear. If you perform an addition on two bytes (after some shifting and manipulation), you'll end up with a single byte. Are you talking about joining the bytes instead? Are the integers signed or not?
Please attach a small VI with a typical string and tell us what result you expect.
05-25-2013 02:27 PM
Sorry to explain better I am using an IC to measure AC voltage and the 12 adc on this chip will do the conversion. However the data is stored in two 8 bit registers and read by the microcontroller in the form of two bytes and is sent to labview via USB interface and read by a VISA read. I dont manipulate the data before I send it to labview because I thought I needed to send in the form of Bytes to the Visa Read which outputs a string. This is why I have to use the string to byte array conversion and now I want to manipulate the data in labview as follows.The 4 LSBs of the first register are actually the 4 MSBs of the 12 bit ADC output. I need to left shift it 8 places and then add it to the byte in the second register to give me a 12 bit output. I then left shift this by 4 places to give me a signed 16 bit integer. This is what I want to continiously plot in thee wave form chart. So basically after the Byte array I need to manipulate.
05-25-2013 02:52 PM
OK, so you are reading 20 bytes as a string and converting it to a byte array (why the conversion? it seem easier to work with the string directly).
Can you attach a VI that contains a typical 20byte string as received in a string diagram constant? Which two bytes (of the 20) are you looking at? What result do you expect?
I think you still say "add" when you actually mean "join". (Adding two bytes gives you a new byte. Joining two bytes gives you a 16 bit item.)
05-25-2013 03:03 PM
Sorry for misleading, you are correct I meant join two bytes. The 20 in the VI I sent should have been 2. The two bytes I want to read and manipulate. I am continiously sending them as it is constantly reading in these two bytes. If it is better to work with the string directly then I will. I thought I needed to put them into an array so I could manipulate the first byte and then the second byte and then join the two together to give me the 16 bit signed integer and then plot. Sorry but this is not my strongest area and if there is a better way then I am trying to do it then I would be happy to do it that way.
Thanks....
05-25-2013 04:19 PM
place an indicator on the string (right-click...create indicator), run the VI until the indicator contains data, right-click the indicator and "change to constant", remove the broken wire, place the string constant into a new VI diagram, save and attach it here.
Do you know if the data is little or big endian?
05-25-2013 04:31 PM
It is little endian.