LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Solution for Handling Complex Logic

I want to share a simple solution for handling complex logic or simple logic that may grow in the future. I didn't see anything about it in the forums, so I'd assume no one has shared this yet.

 

Often times I have found that using the logic gates with my booleans gets me into trouble as my program grows. Eventually, the logic becomes unreadable unless you really sit down and look at what is happening. That is why I came up with this simple, scalable logic handler. It easily grows to accomodate more booleans, and as it grows it does not add a ton of clutter to your block diagram. The attachment details the solution.

 

Basically, I feed all my booleans into an array and then I convert that boolean array into a number, which is fed into a case structure. In that case structure, I can do whatever I want. Manipulate a string, enqueue different states for a queued state machine, etc... I generally like to include a truth table with the handler so that I know what each state is doing, and to make sure there are no suprise cases.

 

Have fun!

 

- Matt

Download All
0 Kudos
Message 1 of 10
(3,647 Views)

 

Hi Matt,

 

I usually take that approach one step farther by first converting your numeric (blue wire ) to U16 then type cast it to an enum where each of the enum values ahs a descritive name e.g. Suppose your booleans where "Part in Place", Safety Switch closed", and "Drive Press Button" the "111" binary or "7" decimal value would be called "Safe to Drive Press". That way your cases will ick up those names and be even easier to go righ to the condition you are interested in.

 

 

See here for the thread where that image was posted.

 

Thank you for sharing and have fun!

 

Ben

PS Edit because the U16 is important for the type cast to work right.
Message Edited by Ben on 02-20-2009 09:23 AM
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 2 of 10
(3,640 Views)

Thanks for the tip, Ben! I suppose it is easier to keep track of descriptive names than long lists of numbers. Smiley Wink

 

I'll start adding the enums to my code.

0 Kudos
Message 3 of 10
(3,630 Views)

Ben -

 

Maybe I'm missing something, but it seems like when I use the enum approach I must have a unique case for each number generated by the boolean array, correct? This means that I'll have a lot of redudant code if I have cases that use the same code. Is there a way to specify the same case for different items in the enum that I am overlooking?

 

Thanks.

0 Kudos
Message 4 of 10
(3,602 Views)
In the text at the top of the case structure, you can put multiple strings representing different enumeration values.  Separate them with commas.  Be warned that if you put more than two consecutive values in the same case, LabVIEW will treat them as a range so you'll only see the upper and lower values.
0 Kudos
Message 5 of 10
(3,571 Views)

Thank you for sharing your ideas and VIs!  I thought I would mention the NI Community because it is a great place designed specifically for sharing.  Look for the Developer Zone Community link on the right side of the Developer Zone homepage.  Once in the Community, you can add your code by goign to New >> Document.  Then you can add version specifications and a description.  It's pretty cool.  Take a look!

 

Kristen H. 

0 Kudos
Message 6 of 10
(3,538 Views)

Kristen H. wrote:

Thank you for sharing your ideas and VIs!  I thought I would mention the NI Community because it is a great place designed specifically for sharing.  Look for the Developer Zone Community link on the right side of the Developer Zone homepage.  Once in the Community, you can add your code by goign to New >> Document.  Then you can add version specifications and a description.  It's pretty cool.  Take a look!

 

Kristen H. 


 

Hi Kirsten,

 

Yes I have been thinking about the Community but I do not have the time to figure out o how to use it.

 

Post a good tutorial and maybe we'll use it. Yes, I am capable if figuring it out myself, but that is too much like work. Make it easy and I'm there.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 7 of 10
(3,534 Views)

Hi Ben!

 

Here is a KnowledgeBase article that explains how to add to the NI Developer Zone Community. How Do I Add My Example Code To the NI Developer Zone Community.  Please, let me know if you have any further questions. 

 

Kristen H.

0 Kudos
Message 8 of 10
(3,501 Views)

Bad link!

 

Smiley Sad 

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 9 of 10
(3,495 Views)

Sorry about that!  Here is the url:  http://digital.ni.com/public.nsf/allkb/9ED7A4F0DCCEDAAF862575660071E492?OpenDocument

 

Kristen H.

0 Kudos
Message 10 of 10
(3,483 Views)