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

Creating a CIN That Multiplies Two Numbers

LabVIEW 8.5 Help
August 2007

NI Part Number:
371361D-01

»View Product Info

Complete the following steps to create a CIN that takes two single-precision floating-point numbers and returns their product.

Note  LabVIEW must be installed on the computer you use to create the CIN.
  1. Place the CIN on the block diagram.
  2. Add two input and output terminals to the CIN.
  3. Add two single-precision numeric controls and one single-precision numeric indicator to the front panel. Wire the node as shown in the illustration below. A*B is wired to an output-only terminal pair.

  4. Save the VI as mult.vi.
  5. Right-click the CIN and select Create .c File. LabVIEW prompts you to select a name and a storage location for a .c file.
  6. Name the file mult.c. LabVIEW creates the following .c file:

    /*
    * CIN source file
    */
    #include "extcode.h"
    CIN MgErr CINRun (float32 *A, float32 *B, float32 *A_B);
    CIN MgErr CINRun (float32 *A, float32 *B, float32 *A_B) {
        /* ENTER YOUR CODE HERE */
        return noErr;
        }

    The preceding.c file contains a prototype and a template for the CINRun routine of the CIN. LabVIEW calls the CINRun routine when the CIN executes. In this example, LabVIEW passes CINRun the addresses of the three 32-bit floating-point numbers. The parameters are listed left to right in the same order as they are wired to the CIN, that is, top to bottom. Thus, A, B, and A_B are pointers to A, B, and A*B, respectively.

    As described in the Parameters in the CIN .c File section, the float32 data type is not a standard C data type. For most C compilers, the float32 data type corresponds to the float data type. However, this might not be true in all cases because the C standard does not define the sizes for the various data types. You can use these LabVIEW data types in your code because extcode.h associates these data types with the corresponding C data type for the compiler you are using. In addition to defining LabVIEW data types, extcode.h also prototypes LabVIEW routines you can access.

  7. Fill in the code for the CINRun routine for this multiplication example. You do not have to use the variable names LabVIEW gives you in CINRun. You can change the variable names to increase the readability of the code. Replace /* ENTER YOUR CODE HERE */ in the .c file with the following example code:

    CIN MgErr CINRun (float32 *A, float32 *B, float32 *A_B);
        {
        *A_B = *A * *B;
        return noErr;
        }
    CINRun multiplies the values to which A and B refer and stores the results in the location to which A_B refers. It is important that CIN routines return an error code so LabVIEW knows whether the CIN encountered any fatal problems and handles the error correctly.

    If you return a value other than noErr, LabVIEW stops running the VI.
  8. Compile the source code and convert it into a form LabVIEW can use. The following sections summarize the steps for each of the supported compilers.

    (Mac Xcode) Create a new project and place mult.c in it. Build mult.lsb.

    (Microsoft Visual C++ Compiler Command Line and Symantec C on Windows) Create a file named mult.lvm. Make sure the name variable is set to mult. Build mult.lvm.

    (Microsoft Visual C++ Compiler IDE on Windows) Create a project.

    (Linux Compilers) Create a makefile using the shell script lvmkmf in the labview\cintools directory. For this example, enter the following command:

    lvmkmf mult

    The preceding command creates a file called Makefile. After running lvmkmf, enter the standard make command, which uses Makefile to create a file called mult.lsb. You can load mult.lsb into the CIN in LabVIEW.
  9. Right-click the node and select Load Code Resource. Select mult.lsb, the object code file you created.

You should be able to run the VI. If you save the VI, LabVIEW saves the CIN object code along with the VI.

Refer to the Multiply using a CIN VI in the labview\examples\cins\mult directory for an example of a CIN that multiplies two numbers.


Resources


 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit