Academic Company Events Community Support Solutions Products & Services Contact NI MyNI
40 ratings:
 2.79 out of 5   

Archived: External Code for LabVIEW - CIN / DLL - Starting Point

This document has been archived and is no longer updated by National Instruments



Primary Software: LabVIEW Development Systems
Primary Software Version: N/A
Primary Software Fixed Version: N/A
Secondary Software: N/A

Problem:
I want to get some information on calling external code from LabVIEW.

Solution:
Calling External Code
  1. CIN & DLL Starting Point
  2. Using CINs in LabVIEW Base Package
  3. Optimization and Performance Issues for External Code in LabVIEW 7.x
  4. How To Compile CINs and Shared Libraries with GCC on Solaris
  5. Compilers that support CINs in LabVIEW
  6. Create a CIN with LabWindows/CVI 4.x and Above
  7. Developer Exchange Forum

1. CIN & DLL Starting Point
An excellent place to get start is to reference the following Developer Zone Tutorial: Step-by-Step Code Interface Node (CIN) Tutorial. This is an excellent place to get information.
It provides information about creating and using a Makefile to generate compiled source code in Microsoft Visual C++ 5.0 that can be imported into LabVIEW through a Code Interface Node (CIN). There is also an example that guides you through the process of creating a CIN in LabVIEW, generating your source code with MS Visual C++ 5.0 in the Integrated Development Environment (IDE), and importing your source code into LabVIEW.

If you are using Microsoft Visual Studio .NET 2003, a great reference would be the Developer Zone Tutorial: Creating a CIN Project in Visual Studio .NET 2003. It describes how to configure Microsoft Visual Studio .NET 2003 to create a Code Interface Node (CIN) project to write CIN code for use in LabVIEW 7.1.


2. Using CINs in LabVIEW Base Package
Although CINs are used in the LabVIEW Base Package and show up in the functions palette, they are not supported for application development. The necessary files for creating CIN object files (.lsb) do not come with the base package.

The Base Package does indeed allow you to use CINs, but it does not include the tools to build the code that is used by the CIN. This is why the CIN is present in the palette but the Cintools directory under LabVIEW is absent. There are several steps involved in creating a CIN:
  1. Put the node on the diagram and wire up the inputs and outputs.
  2. Create the .c file from the CIN's pop-up menu
  3. Edit the .c file and insert your code.
  4. Create a code resource file (.lsb) from your .c file. To do this, you need the "CIN Tools"
  5. Load the code resource file (.lsb) from the CIN's pop-up menu.
The base package does not provide the tools to do step 4. However, if you have pre-existing code resource files (.lsb), you may still use them in the base package. If you want to build code resources, you need the Full Development System or higher.

For more information on what is included in each version please reference the LabVIEW Version Comparison Page.


3. Optimization and Performance Issues for External Code in LabVIEW 7.x
You should strongly consider using thread-safe CINs and DLLs. A CIN or DLL is thread-safe if it can reliably be called from two or more separate threads. Since CINs and DLLs that are thread-unsafe must be run in the user interface thread, any call to such a CIN or DLL causes LabVIEW to switch execution from the block diagram's thread to the user interface thread.

There is overhead associated with this switch. In addition, the CIN or DLL will run to completion in the user interface thread before relinquishing control to the thread, so the user interface will appear unresponsive during this time. By default, LabVIEW considers all CINs and DLLs to be thread-unsafe. The reason for this is that the computer may crash or hang if LabVIEW assumes a CIN or DLL to be thread-safe when it is actually thread-unsafe.

CINs and Call Library nodes appear orange on the block diagram if LabVIEW considers them thread-unsafe. They appear yellow if LabVIEW considers them thread-safe.

To identify a CIN to LabVIEW as being thread-safe, you must include certain function calls in the CIN. For more information reference the following KnowledgeBase 0O7DES38: Calling a 32-bit DLL from a Code Interface Node (CIN) in LabVIEW. You can also see Chapter 3 of the LabVIEW Code Interface Reference Manual
»CIN Advanced Topics, for more information.


4. How To Compile CINs and Shared Libraries with GCC on Solaris
Please reference KnowledgeBase 1IMEACNV: How Do I Compile CINs on Unix / Linux? which will covers the steps on how to compile.


5. Compilers that support CINs in LabVIEW
For a list of compilers that support CINs for LabVIEW 5.x see the Code interface Reference Manual, which is linked below. Here is a list of compilers for LabVIEW 4.x:

Macintosh: Symantec’s THINK environment, Metrowerks’CodeWarrior environment, GCC, and Apple’s Macintosh Programmer’s Workshop (MPW) environment.

Microsoft Windows 3.x: Watcom C
Compiler must be able to create 32-bit relocatable object code

Windows 95/NT: Microsoft Visual C++ compiler and Symantec C compiler
With some restrictions, you can also use some CINs created using Watcom C for Windows 3.1.

Solaris 1.x and 2.x: unbundled Sun C compiler
LabVIEW for Sun can use external code compiled in a.out format and prepared for LabVIEW using a LabVIEW utility.

HP-UX and Concurrent PowerMAX: HP-UX C/ANSI C compiler and Concurrent C Compiler

PowerMac: Metrowerks CodeWarrior C/C++
Symantec C++ Version 8

Linux: GCC

For more information please reference Product Manuals: LabVIEW Code Interface Reference Manual.


6. Create a CIN with LabWindows/CVI 4.x and Above
The detailed instructions on how to create a Code Interface Node from LabWindows/CVI is given in the cvilvsb.h file which can be found in LabVIEW/cintools folder.

Please reference KnowledgeBase 1NTCNQX4: How to Create a LabVIEW Code Interface Node (CIN .lsb File) with LabWindows/CVI 4.x and Above for more information.


7. Developer Exchange Forum
The National Instruments Developer Exchange has a powerful NI Discussion Forums offering full-text search. Take advantage of the expertise of your fellow scientists and engineers by browsing, searching, or posting a question in this community.


Related Links:
KnowledgeBase 25SCB5XQ: Using LabVIEW Source Code Control on Different Operating Systems
KnowledgeBase 1NTCNQX4: How to Create a LabVIEW Code Interface Node (CIN .lsb File) with LabWindows/CVI 4.x and Above

KnowledgeBase 12ICDV92: Using Code Interface Nodes (CINs) in LabVIEW, Can I Call an External Subroutine from Another External Subroutine?

KnowledgeBase 0O7DES38: Calling a 32-bit DLL from a Code Interface Node (CIN) in LabVIEW

KnowledgeBase 12UE9A92: Code Interface Nodes (CIN) won't Compile Code that Calls More than One External Subroutine
KnowledgeBase 1IMEACNV: How Do I Compile CINs on Unix / Linux?

KnowledgeBase 0YR9TGW1: How Do I Run an Executable or External File From Within LabVIEW?
KnowledgeBase 1Q3FAFNV: How Do I Create a DLL That Can Call LabVIEW Manager Functions?

Product Manuals: LabVIEW Code Interface Reference Manual (LabVIEW 5.0 or earlier)
 
Developer Zone Tutorial: How to build a CIN code resource (.lsb file)

Attachments:





Report Date: 07/23/1999
Last Updated: 12/07/2007
Document ID: 1NM99D6Q

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit