Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Document Type: Tutorial
NI Supported: Yes
Publish Date: Sep 28, 2006

Step-by-Step Code Interface Node (CIN) Tutorial

2 ratings | 2.50 out of 5
Print

Overview

This document 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.

Refer to the Using External Code in LabVIEW manual for more information about CINs.

Using Microsoft Visual C++ 5.0 with a Makefile

You must compile the source code for your CIN as a LabVIEW subroutine, or .lsb, file. This section describes using a Makefile to generate the .lsb file.

Complete the following steps to generate the .lsb file.

1. Create the Makefile.
    a. Open a new document in a text editor such as Notepad.

    b. Enter the following lines in the document:

    name=name_of_c_file_without_the_extension
    type=CIN
    cinlibraries=Kernel32.lib
    CINTOOLSDIR=path_to_cintools_directory
    !include <$(CINTOOLSDIR)\ntlvsb.mak>

    File paths are in MS-DOS format.

    c. Save the file in the same folder as your .c file and name the new file Your_VI_Name.mak.

    Refer to the Using External Code in LabVIEW manual for information about .c files.
2. Create the Project in Visual C++.
    a. Open Visual C++ and select File»Open.

    b. Select your .mak file and click Open.
    Note: Two dialog boxes open when you attempt to load your .mak file. The first dialog box displays the message This makefile was not generated by Developer Studio and asks Do you want to continue?. Answer the question Yes. The second dialog box opens and asks what kind of platform to use. Win32 is the default and is the platform you should use. Click OK.
    3. Add your .c file to the project.
      a. Select Project»Add To Project»Files to open the Insert Files into Project dialog box.

      b. Navigate to the folder where your .c file resides.

      c. Select your .c file.

      d. Click OK.
    4. Add your compiled code to your .c file.
      a. Select the File View tab in the Work Space Window.

      b. Double click your .c file.

      c. Ensure your code compiles.

      d. Add your compiled code to the /*ENTER YOUR CODE HERE*/ area in your .c file.

    5. Select Build»Build VI_name.exe to create the.lsb file that you load into your CIN.

    CIN Example


    In this example, you create a CIN that takes in two numbers, multiplies them, and returns the result according to the equation A*B = C. You generate the CIN object code with MS Visual C++ 5.0 in the Integrated Development Environment (IDE).

    Complete the following steps to build the CIN example.

    1. Open a new VI and save it as Mult.vi.

    2. Place two numeric controls and a numeric indicator located on the Controls»Numeric palette on the front panel.

    3. Label the controls A and B and the indicator C, as shown in the following illustration.

    Mult VI Front Panel Controls and Indicator


    4. Right-click control A and select Representation»Single Precision from the shortcut menu.

    5. Repeat step 4 for control B and indicator C.

    6. Place a Code Interface Node located on the Functions»Advanced palette on the block diagram.

    7. Resize the CIN so it has three parameter boxes.

    8. Wire the controls and indicator as shown in the following illustration.

    Mult VI Block Diagram


    9. Right-click the parameter box wired to your output and select Output Only from the shortcut menu.

    10. Right-click the CIN and choose Create .c File from the shortcut menu to create your Mult.c file.

    11. Open MS Visual C++ and follow the procedures in the Using External Code in LabVIEW manual for Visual C++ IDE. Observe the following guidelines when performing the MS Visual C++ IDE procedures:
    • Use Mult for your project name.
    • Enter *C = *A * *B; when instructed to enter your code in your .c file.
    12. Return to your Mult VI in LabVIEW.

    13. Right-click the CIN on your block diagram.

    14. Select Load Code Resource from the shortcut menu to open the Choose a code resource file dialog box.

    15. Navigate to the folder where your Mult.lsb file resides.

    16. Select your Mult.lsb file.

    17. Click Open.
      You should get a white arrow in the Run button of your Mult VI and be able to execute the VI.
      Related Links:
      Code Interface Node (CIN) Resource Library
      Using External Code in LabVIEW (Manual)
      2 ratings | 2.50 out of 5
      Print

      Reader Comments | Submit a comment »

       

      Legal
      This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).