LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Case Structure using Byte Array

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

0 Kudos
Message 1 of 15
(3,903 Views)

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

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 2 of 15
(3,891 Views)

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.

0 Kudos
Message 3 of 15
(3,869 Views)

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

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 15
(3,839 Views)

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

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 5 of 15
(3,831 Views)

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 ?  

0 Kudos
Message 6 of 15
(3,828 Views)

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

 

2014-10-30 15_37_16-Determine%20Command[1].vi Block Diagram _.png

 

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 7 of 15
(3,808 Views)

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.


GCentral
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 8 of 15
(3,806 Views)

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.

0 Kudos
Message 9 of 15
(3,798 Views)

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.

0 Kudos
Message 10 of 15
(3,793 Views)