LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Manipulating bytes in a byte array and displaying them as 16 bit signed int in a waveform chart

Solved!
Go to solution

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?

0 Kudos
Message 1 of 23
(8,735 Views)

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.




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
0 Kudos
Message 2 of 23
(8,730 Views)

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

 

0 Kudos
Message 3 of 23
(8,721 Views)

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...

0 Kudos
Message 4 of 23
(8,706 Views)

@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.

0 Kudos
Message 5 of 23
(8,690 Views)

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.

0 Kudos
Message 6 of 23
(8,675 Views)

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.)

0 Kudos
Message 7 of 23
(8,664 Views)

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....

0 Kudos
Message 8 of 23
(8,656 Views)

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?

0 Kudos
Message 9 of 23
(8,647 Views)

It is little endian.

0 Kudos
Message 10 of 23
(8,642 Views)