![]() |
Note In most cases, a Call Library Function Node is easier to use than a CIN. Assuming the underlying code is the same, the calling speed is the same whether you use a Call Library Function Node or a CIN. |
The LabVIEW Call Library Function Node and the CIN are block diagram objects that link source code written in a conventional programming language to LabVIEW. They appear on the block diagram as icons with input and output terminals. Linking external code to LabVIEW includes the following actions:
The LabVIEW compiler can generate code fast enough for most programming tasks. Call CINs and shared libraries from LabVIEW to accomplish tasks a text-based language can accomplish more easily, such as time-critical tasks. Also use CINs and shared libraries for tasks you cannot perform directly from the block diagram, such as calling system routines for which no corresponding LabVIEW functions exist. CINs and shared libraries also can link existing code to LabVIEW, although you might need to modify the code so it uses the correct LabVIEW data types.
CINs and shared libraries execute synchronously, so LabVIEW cannot use the execution thread used by these objects for any other tasks.
LabVIEW cannot interrupt object code that is running, so you cannot reset a VI that is running a CIN or shared library until execution completes. If you want to write a CIN or shared library that performs a long task, be aware that LabVIEW cannot perform other tasks in the same thread while these objects execute.
You can call most standard shared libraries with the Call Library Function Node. On Windows, these shared libraries are DLLs, on Mac OS, they are Frameworks, and on Linux, they are Shared Libraries. The Call Library Function Node includes a large number of data types and calling conventions. You can use the Call Library Function Node to call functions from most standard and custom-made libraries.
DLLs have the following advantages:
The Call Library Function Node is most appropriate when you have existing code you want to call, or if you are familiar with the process of creating standard shared libraries. Because a library uses a format standard among several development environments, you can use almost any development environment to create a library that LabVIEW can call. Refer to the documentation for your compiler to determine whether you can create standard shared libraries.
The CIN is a general method for calling C code from LabVIEW. You can pass arbitrarily complex data structures to and from a CIN. In some cases, you might have higher performance using CINs because data structures pass to the CIN in the same format that they are stored in LabVIEW.
CINs have the following advantages:
In some cases, you might want a CIN to perform additional tasks at certain execution times. For example, you might want to initialize data structures at load time or free private data structures when the user closes the VI containing the CIN. For these situations, you can write routines that LabVIEW calls at predefined times or when the node executes. Specifically, LabVIEW calls certain routines when the VI containing the CIN is loaded, saved, closed, aborted, or compiled. You generally use these routines in CINs that perform an ongoing task, such as accumulating results from call to call, so you can allocate, initialize, and deallocate resources at the correct time. Most CINs perform a specific action at run-time only.
To create a CIN, you must be an experienced C developer. Also, because CINs are tightly coupled with LabVIEW, restrictions exist about which compilers you can use.
After you write your first CIN, writing new CINs is relatively easy. The work involved in writing new CINs is mostly in coding the algorithm because the interface to LabVIEW remains the same, regardless of the development system.