The MacView

Virtual Instrumentation from a Mac perspective

My Photo
Name:
Location: Pflugerville, TX, United States

Friday, January 06, 2006

ADVANCED: How To Call The Mac OS Directly From LabVIEW Part I: Call Library Function Node Basics

This is not for the faint of heart. Using the Call Library Function Node you can easily crash LabVIEW, corrupt memory and do some really bad things to LabVIEW.

While adding support for several features in LabVIEW on the Mac, we found it fairly easy to call the OS directly from LabVIEW. For some examples of the fruits of this, you can look at many of the VIs in vi.lib/Platform. This will require extensive use of the Call Library Function Node (Connectivity -> Libraries & Executables). It also requires quite a bit of knowledge about the C programming language and Apple's Documentation.

The first thing to become familiar with is how to use the Call Library Function Node. Once dropped on the block diagram, you double click on it to configure it to be the OS call you want. Most of the calls into the OS will be into Carbon.framework, so in the Library Name or Path, enter "Carbon.*" (without the quotes). The star (*) means framework on the Mac, DLL on Windows and so on Linux. The Carbon framework is not on any other OS, so I could just use .framework, but its less typing to just put a star (*).

The next step is to set the Function Name. For this example, we will use :TickCount" (again, without the quotes). If you look at Apple's Documentation on TickCount, you'll see that it takes no parameters and returns a UInt32. So we set the Type for the return type to be Numeric and set the Data Type to Unsigned 32-bit Integer. It should show the Function Prototype to be "unsigned long TickCount(void);"

One other thing to note is the Run in UI Thread pop-up in the upper-right corner. Many of Apple's APIs are thread-safe. Those that are thread-safe can be changed to Reentrant. If it is not thread-safe, you must keep it Run in UI Thread. When in doubt, use Run in UI Thread.

Now that you are done configuring the Call Library Function Node, you can control-click (or right-click) on the U32 output of the Node, and select Create Indicator. Then run the VI and you will get the tick count.

In Part II, we'll look at more advanced calls and more advanced data types.

0 Comments:

Post a Comment

<< Home

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