LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

identify specific bit in bytes of data

Hi All,

 

Not sure the subject really explains what i'm trying to achieve but i'll try to explain. I'm trying to carry out data diagnostics from incoming serial data. i have managed to clean the message up by filtering any unwanted bytes. Within these bytes each bit is a representation of something i will be monitoring (when finished). So would like to ahieve is taking a signal bit from a specific byte and displaying what this represents with maybe an LED coming on when the bit is high/binary '1'.

 

I have attached what i have done so far. I have got access to the permenat incoming stream so have used string to input the data. Any help would be appreciated, i have some experience with labview but would still say i'm a novice.

 

Many Thanks

 

Rob

0 Kudos
Message 1 of 7
(3,630 Views)

apologies there is a small bit of code on the right which i was using for diagostics to work out the coding so ignore this. Also the code is currently not laid out very well so sorry again.

0 Kudos
Message 2 of 7
(3,625 Views)

Tip:  There is no need to do an array size and wire it into the For Loop's N terminal when you are using auto-indexing on the tunnel for that array wire.

 

I don't understand what any of the code you have presented is supposed to be doing.

 

But if you want to know the value of a bit for a particular byte, the way do do that is with "masking".  Once you've converted the bytes to U8, use the AND function with a number to break out a particular bit.  So if you want to know the highest order bit, AND the byte with 128.  The result will give you either  0000 0000  or 1000 0000.  If the result is >0, then the bit was True.  If the result =0 then the bit was false.  If you want to find the 2nd to lowest bit, than AND it with 2.

 

The other possibility is to use the Number to Boolean Array function like you have in there now.  Then just index out the boolean of interest.

Message 3 of 7
(3,616 Views)
Apologies if I wasn't clear. What I have done is more of a test bed, but what you have explained sounds great. Many th aka for the pointers
0 Kudos
Message 4 of 7
(3,598 Views)

A few other pointers:

 

You can wire integer data types to the selector terminal of a case structure.

You can set ranges of values in case structures. (This can sometimes simplify the testing and logic).

You can use conditional indexing on output tunnels. This eliminates the Build Array inside a case structure. Arbitrarily growing an array inside a loop can cause memory problems.

You can use subdiagram labels to document what each case does.

 

This produces the same results as your code.

 

Lynn

Message 5 of 7
(3,593 Views)

Very nice, appreciate that and thanks again

0 Kudos
Message 6 of 7
(3,535 Views)

If you want slightly flatter code, here's another alternative. Won't be more efficient, just cleaner. 😄

 

 

(Gives the same result as Lynn's code for the default data and other datasets I tried, but please verify for the general case before using. No guarantees ;))

 

 

Download All
Message 7 of 7
(3,507 Views)