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.

Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Using Data Read from Serial

I have setup a VI to read data in from the serial port. I can read the data in just fine, but I having problems manipulating it after I have read it in.
My application is reading data from a laser range finder. I read in 4 bytes of data at a time, where 2 bytes are range data and 2 are signal stregth data. The most significant 2 bits of each byte is used to identify the byte. ie:
10rrrrrr 00ssssss 11xxxxxx 01yyyyyy , where the first 2 bytes are range info and second two are signal strength.

sample range data: 10101001 00010111 ->2647dm sample signal strength 11010010 01010010 -> 1170

I need to take the first two bytes, cut out the most significant bits of each, combine them, and then convert the result to decimal so I can read the range data. The same also needs to be done for the signal strength with the second 2 bytes.

Right now I am at the point where I read in the data from serial 4 bytes at a time and then convert them to unsigned binary. I can display each byte as binary and I can display each byte as decimal but the decimal values are incorrect since the 2 msb's are just place holders. Any idea how process the data? Now I am only looking to display the range and signal strength, but eventually I would like to write the code to save the data to a file and have a real time plot of range data ( cycles at 400 hz).
0 Kudos
Message 1 of 4
(3,132 Views)
The boolean palette has the 2 VIs which should help you - Number to Boolean Array and Boolean Array to Number.
Once you convert the number, you can cut off the bits and combine using array functions and convert it back to a number.

___________________
Try to take over the world!
0 Kudos
Message 2 of 4
(3,128 Views)
Some logical operators could help you.
For instance, to isolate the 6 least significant bits, you can do an AND operation with b00111111. Similarly, to retrieve the 2 most significant bits, you can do an AND with b11000000. Two 1 bit rotations to the left will give you the identifiers for the corresponding bytes.
Then, to combine the high order byte and the low order byte, you need only to multiply the MSB by 64 (2 to the power 6) and add the LSB.
Have a look at the attached vi, that acts on the 4 bytes array.

CC

edit: typos

Message Edited by chilly charly on 05-16-2005 11:06 PM

Chilly Charly    (aka CC)

         E-List Master - Kudos glutton - Press the yellow button on the left...
        
Message 3 of 4
(3,113 Views)
Thanks, I got it now.
0 Kudos
Message 4 of 4
(3,103 Views)