The MacView

Virtual Instrumentation from a Mac perspective

Monday, August 04, 2014

LabVIEW 2014, First 64-bit Version for Mac

It has been a while since I've posted here, but with good reason. We've been really busy working on rewriting large chunks of LabVIEW for Mac 64-bit (see also Christina Roger's mention).

LabVIEW originated on the Mac APIs. Since then, LabVIEW was ported to Windows and Linux, and more modern APIs on those platforms. However, the Mac code largely remained unchanged, except for a minor rewrite for Mac OS X. When Apple switched to the NeXT based Mac OS X, they provided an API set named Carbon, which allowed for much of the pre-existing code to come across without much change. When LabVIEW was ported to Mac OS X, we took advantage of several POSIX APIs that we had battle-tested on Linux, and there were some changes to take specific use of Mac OS X, but much of the old API usages were not changed.

Then Apple decided not to port Carbon APIs to 64-bit. Apple has also deprecated much of the Carbon APIs. So we launched out to rewrite the Mac-specific sections of LabVIEW to be more modern and take advantage of Apple's new and forward looking Cocoa API. We decided the best way to do this and make sure we didn't miss anything that still called into Carbon APIs, was to port LabVIEW to 64-bit on the Mac.

We didn't want to do another minimal-port like we did when we went to Mac OS X. We wanted to fix as much as we could. We put together a terrific team of great developers on the LabVIEW team, and got to work on evaluating what needed be rewritten, what needed to change and what should stay the same. So here are some of the differences between Mac 32-bit and Mac 64-bit and VIs to help with the transition.


Depending on the operation, 64-bit LabVIEW on Mac is noticeably faster. There are a couple of corner cases where small sub-sections of the code are slightly slower, but everything else we've tested is somewhere between slightly faster to much faster. We went down to the C-Code subroutine level to compare performance between 32-bit and 64-bit to make sure we were not slowing LabVIEW down in porting to 64-bit. We were pleasantly surprised.


This was long overdue. Paths in 32-bit are formatted in HFS Classic format. 64-bit uses the more common POSIX paths. It's mostly showing slash (/) instead of colon (:) between path elements (although there is more to it than that). 

There is also a little bit of magic that happens in 64-bit when a path in a string is converted to a path type that allows either format, and then converts it into POSIX style. You can try this by copying the path from the 32-bit path indicator and paste it into the 64-bit indicator. Once focus leaves the indicator, the path will be converted to POSIX format (it's pretty fun to watch).

This magic also happens when using the String to Path primitive. You can have a string of either format and it will convert it to a POSIX path. This makes it easier to transition between 32-bit and 64-bit as you are testing your VIs in 64-bit.
Some other VIs that assist in dealing with paths between 32-bit and 64-bit are Path to Command Line and Command Line String To in Programming -> String -> Path/Array/String Conversion palette. These VIs are helpful in building a path that can be used in System or system shared libraries in a cross-platform manner. They have actually existed in LabVIEW since before 2009, but are added to the palettes now to assist in transitioning between 32-bit and 64-bit on Mac.

Another path related VI that is helpful for Mac users is Executable Path To Command Line This VI helps in getting the path to the executable in an app.
This is particularly helpful writing cross platform code that will launch LabVIEW built apps, LabVIEW itself, or other GUI applications. Windows and Linux just take the path to the EXE. On Mac, the .app is really just a folder. This VI will give you a path to the executable you can call from System, in a cross-platform way. This VI did not make the cut for the palettes, but you can find it in vi.lib/AdvancedString.

POSIX Line Ending

Another long overdue change was the "platform line ending." Since Mac OS X, most Mac software uses New Line (\n), however LabVIEW clung to the old Mac Classic Carriage Return (\r). The End of Line Constant (I know the icon shows New Line/Carriage Return) in the String palette returns what LabVIEW thinks is the platforms end-of-line character(s). Windows returns Carriage Return/New Line (\r\n). Linux returns New Line (\n). Mac 32-bit returns Carriage Return (\r) and Mac 64-bit return New Line (\n).
To assist in handling line endings from various environments, we now have Normalize End Of in the String palette. This VI has shipped with LabVIEW since before LabVIEW 2009, but is now available in the palettes. This VI takes a string and converts all the line endings in the string to a standard end of line. That way, no matter what the source of the string (Windows, Linux, Mac LabVIEW 32-bit, etc), you can normalize the end-of-lines in the string and then parse the string regardless of the source.

AESend is Dead, Run AppleScript Code Instead

LabVIEW used to communicate with other applications on the Mac using Apple Events via AESend family of VIs. We have removed those from the palettes and added Run AppleScript (in Connectivity -> Libraries & Executables next to System AppleScript is easier for most people to use, and you can test the code in Apple's AppleScript Editor app. The AESend family of VIs still ships with LabVIEW, but is deprecated and we encourage users to move to Run AppleScript (NOTE: LabVIEW 2014, both 32-bit and 64-bit, shipped with a crash when running the AESend family of VIs. This is expected to be fixed in a future version). The AESend family of VIs will not work in 64-bit.

Unicode / UTF-8

Mac LabVIEW 64-bit is the first LabVIEW that supports Unicode. When displaying, entering, copying, pasting, etc. strings, 64-bit LabVIEW assumes all the data is UTF-8. This has several ramifications. First, you can put emoticons in text. Pretty cool, but not that helpful. The other implication is that now there is no limit to what languages you can use for file/folder names (this ones for you, Socrates). In LabVIEW 32-bit on Mac, we had users who would name their hard drive something meaningful in their native language, which LabVIEW would then choke on and report it couldn't open the VI. LabVIEW 64-bit, because all strings are UTF-8, can handle any language in the path.

CINs are gone, use Call Library Function Node

On all 64-bit LabVIEW platforms, CIN is no longer supported. All of the functionality is available via the Call Library Function Node (in Connectivity -> Libraries & Executables next to System Since Apple supports Universal Libraries, LabVIEW on Mac does nothing special to differentiate between 32-bit and 64-bit in library names. If you have a framework or dylib that you want to call into from both 32-bit and 64-bit, make sure it is a universal binary. You can use the lipo command line tool to merge binary code from 32-bit and 64-bit into a universal binary.


There are separate installers for LabVIEW 32-bit and 64-bit on the Mac LabVIEW media. We recommend you install both, as not all NI toolkits and addons are available for 64-bit yet.

The Dock icon differs between 32-bit and 64-bit. Think of it as Coal (32-bit) and Solar (64-bit). The icons now also have the LabVIEW version on them. This makes it easier to tell the difference and switch between them when working with both simultaneously.

LabVIEW 32-bit is still in /Applications/National Instruments/LabVIEW 2014 folder. LabVIEW 64-bit is in a sibling folder named LabVIEW 2014 64-bit.

I encourage you to try out LabVIEW 64-bit and leave me a comment below as to what other differences you have found.

Labels: , , , , ,

The views expressed on this website/weblog are mine alone and do not necessarily reflect the views of my employer.

Monday, April 22, 2013

About LabVIEW, Wait, Correction, About My App

I've had several customers creating applications with LabVIEW, and wanting to show their own About … window instead of About LabVIEW … window.

The first thing to notice, is that while you are in the editor, it will always have the "About LabVIEW …" text in the application menu. However, when you build your application, it will change to "About …" Remember that while you're running the LabVIEW editor, LabVIEW still owns the LabVIEW menu.

Even though the menu changes from "About LabVIEW …" to "About …" it still behaves like "About LabVIEW…" in your built app. The trick is to create a VI named "" and add it as an Always Included source in your application.

When "About…" is selected in your built application, your will be run. If you want behavior like LabVIEW's About window, you can just use an event structure with a Mouse Down in Pane. That way, just clicking on the front panel dismisses the About Window.

This is an image rich and text poor post, but I wanted to make it easy to scan and see what you can do to replace the About… behavior.

I believe this can be done on Windows and Linux also, but I haven't tried it.

UPDATE: Someone just pointed me to a NI Developer Zone article on the same subject (sans pictures).

Labels: , , , , ,

The views expressed on this website/weblog are mine alone and do not necessarily reflect the views of my employer.

Friday, March 08, 2013

More Magic with Post-Build Steps

I'm in a Post-Build magic mood. I was chatting with a LabVIEW user who wanted to have a drag and drop install experience for their LabVIEW built app. My previous post about merging the LabVIEW Runtime Engine into your built app is part of the puzzle. The magic he was looking for was creating one of those spiffy .dmg files with a background image giving instructions to drag-and-drop onto a symlink to /Applications folder.

This gave rise to my DMG Post-Build Step. It's really not meant to be a Post-Build step, but an example of using the DMG and Finder VIs I wrote. You can combine these VIs into an amalgamation of the LabVIEW Runtime Engine Merge, the example DMG step here and your own magic.

The idea is that you can mix and match the parts to do what you need to get done for your project. In the example I've included in the project, it builds a Read/Write .dmg (which is required to arrange it correctly) and then a Read-Only, Compressed .dmg for distribution.

The .dmg tools allow you to create DMGs, mount and unmount them and convert them to other formats. The convert VI allows you to convert any .dmg to two difference compressed formats (pre-10.4 compatible and a 10.4+ that has better compression), Read/Write, ISO (for CD/DVD Burning) and Sparse (disk image size on disk grows as contents of disk image grow).

After creating the .dmg tools, I realized there was some somewhat tricky things I needed to do in the Finder to get things to look just right. Luckily the lingua franca of the Finder is AppleScript, and LabVIEW just happens to ship with a VI to run AppleScripts, at vi.lib/Platform/Run AppleScript Also lucky for us, AppleScript's native path format is Classic Mac (ie Macintosh HD:Users:labview vs POSIX /Users/labview).
Above is the contents of Set Finder Item It calls Open Finder to make sure the window is open in the Finder, and Close Finder at the end. The Finder is particular about when it will persist changes made via AppleScript. Goofy things like opening and closing windows can make a difference.

Speaking of which, you'll notice that in the example Post-Build VI (Create App, we open the Finder Window (and don't close it) right before we unmount the Read/Write .dmg file. After reading the tea-leaves on the internet (or at least my poor recollection of reading them) reveals that in order for the Finder to persist the position changes made, you need to have the window(s) open when you unmount.
So with all those magic AppleScript incantations and tweaking the sizes and positions until it is just right, when you build, the output directory will have your application (as well as the Preferences and .aliases files) along with a Read/Write .dmg file (helpful for debugging positions, etc.) and the final, compressed .dmg.

When you double-click on the Read/Write .dmg file, you'll need to find the disk to open it (Finder -> Go -> Computer). However the Compressed .dmg file will open it's window when double-clicked. Not only does it open, but it opens in the top-left corner (with a little space from the edge of the screen), it shows my background image (you can have any .jpg file you want there) and my application (with the extension hidden).

My Finder tools do have some limitations (and someone may want to modify/extend them). They only work on Icon View (list, column, etc are not supported). I've hard-coded the following behaviors: no side bar, no status bar, no tool bar, no item info shown, no icon preview shown, icons are not arranged and the label position is at the bottom of the icons. The Set Finder Icon Window was intended to give you just the tools you need to create the customary .dmg drag/drop install.

Oh, and I did omit creating the symlink to /Applications folder. I'll leave that as an exercise for the reader, but I'll give you some hints: System and ln -s /Applications /Volumes/Example/Applications, just don't forget to build the path for /Volumes/Example/Applications from the root path passed out of Create and of course, don't forget Path to Command Line to get it in POSIX format.

Happy app building!

Labels: , , , ,

The views expressed on this website/weblog are mine alone and do not necessarily reflect the views of my employer.

Wednesday, February 27, 2013

Build a Standalone Mac App in LabVIEW (no need to install the Runtime)

I just posted an example VI that Installs the LabVIEW Runtime Engine into your built apps. LabVIEW has added pre/post action VIs that you can add to your Build Application Specification. This can be very useful for automating prep-work or post-build tweaks.

One thing I have found that not many people are aware of is that you can embed the Runtime Engine in your LabVIEW built application. Since applications on the Mac are just folder (right click or control-click on an app and select Show package contents) you just need to create a folder inside your built app called "Support". Put the appropriate version of the LabVIEW Runtime Engine in that folder and now there is no need to include the LabVIEW Runtime Engine Installer.
Now the Runtime Engine is quite large (159MB for 2012), and some of that is due to items that you may not need. For some things it's obvious if you need it or not (if you're not using MathScript, you can delete the MathScript framework). Some things, if you delete them, can prevent the application from launching or working correctly. The VI I cooked up not only installs the correct version of the Runtime Engine (installed on your machine) but it also removes everything that is not needed to launch a simple VI.

Another reason the Runtime Engine is large is because there may be more than one architecture in the libraries. On the Mac, you can have what is called Universal Binaries, which includes native executable code for more than one processor in the same file. We have done this in the past to allow PowerPC and Intel code coexist in the same file. Some of our libraries may contain vestigial PowerPC code. If, in the future, LabVIEW were to support 64-bit Intel, it might have both 32-bit Intel and 64-bit Intel in the same binary. This VI also goes through every library in the Runtime Engine and strips out any code that is not 32-bit Intel.

We also ship a good amount of information in LabVIEW executable code to help us diagnose problems on users machines. You probably don't need all that diagnostic code, so in addition to installing the Runtime Engine, stripping out non-32-bit executable code, the VI also strips out any information that would help in diagnosing problems.

The Install Runtime also zips up your .app instal a zip file right next to the app (using the maximum zip compression). That way you have a standalone application in a zip file you can email or post to a web server, ftp site, or however you want to distribute your app.

Oh, and you know those annoying .aliases and Preferences files that are always dumped next to your app? Well, this post-build step VI will also remove those for you, leaving just the app and the zip file of the app.

Use this VI as a starting point. Modify it, hack it up, improve it. Please leave comments below of any recommended improvements or cool tricks you found for post-build steps.

Labels: , , , , , ,

The views expressed on this website/weblog are mine alone and do not necessarily reflect the views of my employer.

Thursday, June 03, 2010

How to Get All Mac System Colors in LabVIEW

Christina Roger's blog posts over at Eyes on VIs (specifically Secret LabVIEW System Colors and System Colors - Don't Believe Your Eyes) got me looking into the System Colors on the Mac. In doing so I wrote some VIs to query the OS directly (at least on the Mac) what all the system colors are. You can download the VIs at:

Mac System Color VIs

Both the Text Color API and the Brush Color API are very similar. They differ only in the function to call (duh) and the constants passed for what color to get. Here is's block diagram:

My last post talked about converting a list of constants into an enum. I used this method (for both API calls) to create the enum input. For the RGBColor input, I just used an array of three Unsigned 16-bit Integers (Red, Green and Blue in that order in the array). The trickiest part was how to convert three u16s to a LabVIEW color code. LabVIEWs colors are an Unsigned 32-bit integer. The least significant byte is the Blue value. The next most significant byte is the Green value and the next most is the Red value, in other words: 0x00RRGGBB. The most significant byte is where LabVIEW stores magic flags, so we'll keep that zero. To convert from 16-bit values to 8-bit values, we just need the upper half of the 16-bit values. So we use Split Number primitive to get the upper half of the 16-bit values and use Join Numbers to put the colors in the right places.

Then it's just a matter of getting the Call Library Function primitive set up correctly. There you go. Simple call to get all sorts of colors from the OS.

Labels: , , , ,

The views expressed on this website/weblog are mine alone and do not necessarily reflect the views of my employer.

Thursday, May 06, 2010

How To Automate Creating Large Enums

I was creating some VIs to call the OS to get system colors directly when I ran into an annoyance. The OS defines a long list of constants (in this case kThemeBrush* in Appearance.h on the Mac). I wanted an enum in my VI API to make code calling my VI more readable (right click -> create constant on the enum terminal creates an enum constant on the diagram). There were 62 enum values to enter. This was not something I wanted to type one by one into the enum control. So I came up with a way to automate much of the creation.

First I searched for all lines in Appearance.h that contain kThemeBrush and a number. I took those lines and pasted them into a string constant and then wrote some code to parse out the constant name and value (see diagram below).

So what does this diagram do? First I use vi.lib/AdvancedString/Normalize End Of to make sure the line endings in the string are the LabVIEW platform line ending (\r on the Mac). I then use Spreadsheet String To Array primitive to parse the string into lines (one of my favorite text parsing tricks in LabVIEW). Then for each line I get the part before the equals (name of the constant) and then I get the part between the equals and the comma (constant value).

I then copy the Ring to my VI, right click on it and select Replace and replace it with an enum. LabVIEW preserves all the strings. However, to get the appropriate value (enums by default use their (zero based) index as their value) I use the output array.

The front panel of the VI has a Ring (not enum because you can't write the strings to an enum on a running VI). The constant names are written to the Ring values (Strings[]) and we output an array of the constant values. We right click on the array control and select Data Operations -> Copy Data. Then right click on the array constant in the diagram below and select Data Operations -> Paste Data.

This diagram converts the enum values to the constants from the header.

I did this for two separate API calls (Theme Text and Theme Brush), each with their own set of constants. More reliable and much faster than doing it by hand.

Labels: , ,

The views expressed on this website/weblog are mine alone and do not necessarily reflect the views of my employer.

Thursday, April 01, 2010

Threading using Queues

I found something unexpected today. I had written a VI to generate a report of the linkages between files in the LabVIEW distribution. It was a quick and dirty VI that basically did the following:

1. Find all the VIs, Controls, Classes, Libraries, Projects, etc. in the LabVIEW distribution

2. Read the linkage information from the file

3. Write out a report on the file

Here is a simplified version of what I was doing:

With this method, LabVIEW pegged the CPU at 100%. Well, LabVIEW pegged one of my four CPUs at 100%. That's great because I can do other things, but I'd like this to finish as soon as possible. So I broke the three tasks into three separate loops that communicate through Queues. Below is the code:

My code went from using 100% CPU to 250% to 270% CPU.

To use Queues to increase your threading, you need to be able to break up your code into tasks that can be run simultaneously. Usually if you are waiting for I/O, that is a good task. Here I have three disk operations (Directory Listing, Read From File, Write To File). It turns out the slowest of these is reading the linkage information from the file. So much so that the Queue of Paths stays full and the Queue of information to write remains close to empty. To help improve performance in a case like this, you can set a maximum Queue size (on the Path Queue in my case). I set the maximum size to 1,000 Paths. So the Read Link loop would always have no more than 1,000 Paths waiting for it. When it takes a Path from the Queue, the Directory Listing loop wakes up and puts another Path in the Queue.

One trick is to figure out how to end the loops. With many of the LabVIEW APIs, you can loop until the Read operation returns an error, and in the Write loop, just close the reference. With Queues that doesn't work because you may close the Queue with data still in it (1,000 Paths, for instance). So instead we send some invalid data that we would not otherwise send (Not A Path in the Path Queue instance). When each loop finishes stuffing data into the Queue, it puts an invalid element in the Queue. Then the loops that read from the Queue know to stop when they see invalid data.

I hope using this can improve the performance of your VIs. If you have any questions or improvements, please leave them in the comments.

Labels: , , , , ,

The views expressed on this website/weblog are mine alone and do not necessarily reflect the views of my employer.