Jump to content

Calculating dynamic formulas with boolean operations


Sima

Recommended Posts

Using the formula evaluation VIs, you can setup a way for the user to enter the formula of his or her choice and calculate the result based on what the values are. The limitation is that these VIs don't support boolean operations like the formula node does or like manually coding the formula with a bunch of ANDs and ORs. If only the formula node could accept a formula to be entered at run-time.

Does anyone know of a way that will allow users to enter formulas with boolean operations, such as y = a & b, that will perform a bitwise AND, for example?

Thanks.

Link to comment

Bitwise is the part that makes that more challenging as you could use multiply and add for AND and OR otherwise. I wound up using spreadsheet string to array, converting to RPN, then parsing through. It's not fast nor strait forward. I'm certainly interested if someone has a better idea.

Link to comment

I've used LuaVIEW for this as well. From the manual:

Since part of the job of the Lua parser/compiler is to parse arithmetic expressions, Lua can be abused as an expression evaluator.

I had a (mostly) binary decision tree that had an arbitrary set of rules that users could input to reach a manufacturing rework/binning decision. I used Lua for the original tests, but ended up building my own parser and evaluator directly in LabVIEW.

Sadly, the company I did that for is now gone, and the code with it... but such code is possible, and not even that hard, if you don't mind getting all computer-science-like. I adapted my implementation from an elementary textbook, but the basic subjects for googling are evaluating postfix expressions, and converting infix to postfix expressions.

Joe Z.

Link to comment

There's an arithmetic parser in the Labview examples. It can easily be modified to include boolean evaluation (just search for "expressions" in the example finder)

The arithmetic parser doesn't handle bitwise operations, or at least it didn't when I last looked. May have to look again...

Link to comment
  • 11 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.