02-20-2009 09:07 AM
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
02-20-2009 09:17 AM - edited 02-20-2009 09:23 AM
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
02-20-2009 09:21 AM
Thanks for the tip, Ben! I suppose it is easier to keep track of descriptive names than long lists of numbers.
I'll start adding the enums to my code.
02-20-2009 10:28 AM
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.
02-20-2009 03:04 PM
02-23-2009 02:41 PM
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.
02-23-2009 02:46 PM
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
02-24-2009 11:48 AM
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.
02-24-2009 11:54 AM
Bad link!
Ben
02-24-2009 01:04 PM
Sorry about that! Here is the url: http://digital.ni.com/public.nsf/allkb/9ED7A4F0DCCEDAAF862575660071E492?OpenDocument
Kristen H.