My primary goal of this example is to demonstrate something cool in LabVIEW. I hope to have accomplished a few things: Demonstrate cool LV capabilities such as scripting and XNodes in new and interesting ways and to share my vision for a new type of math tool in LabVIEW that is based on G, but leverages the power of other tools such as Mathematica, Math Type, LaTeX, and others. In short, I utilize the power of LaTeX and MathML to quickly and easily share equations between all of these programs (and even Wikipedia) and implement them in native G code in LabVIEW.
At the heart of the code is an expression parser which uses the Shunting Yard algorithm to convert math expressions to G code using scripting. On top of this, I have written parsers which convert both MathML and LaTeX to regular expressions which can then be converted to G. With this ability, it is very easy to transfer equations to LabVIEW. In addition, with the use of freely available software (MikTeX and Ghostscript) this tool will automatically place beautifully formatted equations as labels next to the G code. The generated code can be placed on the clipboard for pasting, put into a new VI, or saved as a Math Snippet. The Math Snippets contain the LaTeX or MathML used for the equation and label and they can be loaded and edited by the tool, a great timesaver.
As a bonus, I have taken things to the next level. While G code is beautiful for many things, complex equations can be difficult to follow and debug. Therefore, I have included an XNode which encapsulates the G code and presents only a Typeset equation and a set of terminals. Think formula node with LaTeX typesetting.
Finally, it may not be practical, but one of the flat-out coolest things I have done with LabVIEW is to use the Math Input Control of Windows 7 to write out an equation by hand (scribble really), and see that handwritten code turned automatically into G. Now you can do that too if you have Windows 7.
The code is Windows only since I do not have Mac access. Most of the Windows only functionality is in clipboard functions and system exec calls to execute the external tools, which should be fairly easy to port for those interested.
Three tools are included in this example.
Convert Math Expression to G: Takes code written in MathML, LaTeX, or normal text (y=a+b) and converts it to G with a nicely typeset label (if you install LaTeX and Ghostscript). You can also launch the Math Input Control and the result is automatically placed into the control, or go to a Wikipedia page and copy and equation and you can paste the code into the controls automatically. With Wikipedia, you can either use the web image as the label or tweak the LaTeX as you desire.
Math Node.xnode: When you drop this XNode onto a block diagram, a dialog box appears which is very similar in feel to the Convert Math Expression to G tool. You can load math snippets, or generate code in many of the same ways. When you are finished, you get a beautiful node powered by G under the hood. My knowledge of XNodes is primarily from reverse engineering the ones in vi.lib and this code should be considered a hack. It does however, demonstrate a Math Node I would like to see as a fully integrated tool in LV's arsenal. Plus, with scripting fully supported, maybe we can get some more light shed onto XNode technology, the logical next step. Note: the terminals are fully type adapting, need an array, or cluster, just wire it in. If you can wire it to the math primitives, you should be able to wire it up to the math node. Much of the underlying code is the same as the Convert Math Expression VI to G, I just keep them namespaced since having an XNode in memory reserves the SubVIs and prevents editing.
G shortcut for Quick Drop: Just a bonus tool I use to convert Greek symbols in control labels to Greek, so things like \alpha or \beta are converted to Symbol font. Some LV bugginess with copy and paste of formatting in terminal labels, but the front panel looks good. Shift-G undoes the greek-ification.
A math snippet with embedded information about the equations used for the G and the label. You can open this in either the ConvertMathExpressionToG.vi or the Math Node configuration dialog to edit the code.
Part 1 - Introduction : http://www.screencast.com/t/WgKDsNzI0
Part 2 - Math Input Control and Math Node : http://www.screencast.com/t/jnW69fj1P
Part 3 - Multiple Equations from Wikipedia and Quick Drop Action : http://www.screencast.com/t/YzG9ojDPig3
Removed a few vestigial passwords.
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
Hi Darian.x,
This is such an awesome work thank you for doing this for the community.
Is there any change to get the DLLs for 64 bit, please?
Cheers,
I can't believe I only just stumbled upon this now after being around LV for nearly 8 years. Any update about a 64 bit option?