10-30-2014 11:05 AM
I have an array that has 9 bytes. I need to determine method for selecting a case in case structure when a bit is high.
I know how to do it when it is 1 byte but I am not sure the best method to use when its nine byte array.
Can someone provide me suggestions? Or example code?
Thanks.....
10-30-2014 11:18 AM
@sticyfinger wrote:
[...]
I know how to do it when it is 1 byte but I am not sure the best method to use when its nine byte array.
[...]
Either index the array to the particular byte you're interested in and do what you already know, or put what you already know in a For loop to apply your logic to every byte.
10-30-2014 11:58 AM - edited 10-30-2014 12:00 PM
Assuming you have a Boolean array with 9 elements, use "boolean array to number" and wire to the selector terminal. Create cases for all relevant patterns and leave the default case empty.
If only one element can be true at any given time, use search array and search for TRUE. Wire the output to the selector. Leave the "-1" case empty.
10-30-2014 01:36 PM
@altenbach wrote:
Assuming you have a Boolean array with 9 elements, use "boolean array to number" and wire to the selector terminal. Create cases for all relevant patterns and leave the default case empty.
If only one element can be true at any given time, use search array and search for TRUE. Wire the output to the selector. Leave the "-1" case empty.
I think the poster has an array of nine bytes, each with the appropriate booleans. Therefore, I like @jcarmody's suggestion that he index the array and performs the operations that the poster is already familiar with.
Assuming an array of booleans, the first method you described is okay if there is a specific action for each pattern. In most of the scenarios I've worked with, each bit represented a specific test, for instance, and there would be a lot of duplicate code if I used that method. (For instance, binary cases 10 and 11 would both have test subVIs for test 2.) For something like that, I would all my tests in sequence (using error in/out for dataflow, of course) and have T/F cases around each one with the indexed boolean array controlling which tests would be run. Of course I tend to see things in a literal way, so if the requirements say "do the selected tests in this order", that's how I would develop it. Maybe there's a better way programmatically?
10-30-2014 01:51 PM
@sticyfinger wrote:
I have an array that has 9 bytes. [...]
Is it a 1D array with 72 bits, or is it a 2D array with nine 8-bit elements?
10-30-2014 01:53 PM - edited 10-30-2014 02:01 PM
I am looking for a better way to program it. This is part of a command parser.
can someone provide me a with a better way of doing this ? Provide examples please ?
10-30-2014 02:41 PM
If it's certain that only one bit will be high at a time, you can do this (this is similar to what altenbach suggested, but you already had the array as U8):
10-30-2014 02:43 PM
Number to Boolean Array and then use an autoindexing tunnel to pass that into a FOR loop. Then it is a simple TRUE or FALSE case structure.
10-30-2014 03:00 PM
Thanks I never knew you could do that. Pretty cool.
I will have to sort through a 9 byte array. I can do it for 1 byte (as last vi i post show) but to do it for 9 byte array a little more difficult.
Also it could be more than one bit high at any time. Each bit will do a certain command so each bit need a case.
I just assumed there was an example or something out there already that did something like this.
10-30-2014 03:05 PM
sticyfinger wrote:Also it could be more than one bit high at any time. Each bit will do a certain command so each bit need a case.
So autoindex on the boolean array and wire to the big case structure. Leave the FALSE case empty. Now place a smaller case structure inside the true case and wire the interation terminal [i] to that case structure. Cases 0..8 will have the bit specific code and the outer boolean decides if it executes.