04-14-2016 02:28 PM
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
04-14-2016 02:31 PM
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.
04-14-2016 02:43 PM
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.
04-14-2016 03:18 PM
04-14-2016 03:25 PM
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
04-15-2016 03:52 PM
Very nice, appreciate that and thanks again
04-16-2016 01:11 PM - edited 04-16-2016 01:12 PM
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 ;))