Creating a Caller VI (Statechart Module)

LabVIEW 2010 Statechart Module Help

Edition Date: June 2013

Part Number: 372103F-01

»View Product Info
Download Help (Windows Only)

Creating a caller VI to communicate with a statechart is different depending on whether the statechart is asynchronous or synchronous. In either case, you complete the following steps to prepare the statechart.

  1. Generate code for the statechart.
  2. Display the Project Explorer window that contains the .lvsc file for which you generated code.
  3. Create a new, blank VI to serve as the caller VI.
  4. Display the block diagram of this VI.
  5. Drag the .lvsc project item onto the block diagram to create a Run Statechart function that links to the appropriate statechart.
  6. (Optional) Provide input data to the statechart by wiring a value to the Inputs input of the Run Statechart function.
  7. (Optional) Right-click the Outputs output and select Create»Indicator from the shortcut menu to create a cluster indicator for data that the statechart returns. You can unbundle this cluster to access specific elements.

Asynchronous Statecharts

The following example shows how to create a caller VI that both executes and sends triggers to an asynchronous statechart. In this situation, the caller VI has two While Loops that execute in parallel. The first While Loop contains an Event structure that uses the Send External Trigger function to send triggers to the external queue of the statechart. The second While Loop contains the Run Statechart function that executes the statechart. You also can place these loops in two separate VIs to achieve greater modularization.

Complete the following steps to configure a caller VI to execute and send triggers to an asynchronous statechart.

  1. Place an Event structure in the first loop and the Run Statechart function in the second loop.
  2. Add event cases to the Event structure. Each case should correspond to one or more triggers that you want to send to the statechart.
  3. Wire a value to the Instance Name input of the Run Statechart function to create a name for the external queue of the statechart instance this function runs.
    Note  If you do not see this input, the Run Statechart function is linked to a synchronous statechart. You must link the Run Statechart function to an asynchronous statechart.
  4. Right-click the Run Statechart function and select Create Send External Trigger Function to create a Send External Trigger function that links to the appropriate statechart.
  5. Place the Send External Trigger function in the loop that contains the Event structure.
  6. Specify the queue to which this function sends the trigger by wiring a value to the Instance Name terminal of the Send External Trigger function. Ensure this name is identical to the value you wired to the Instance Name input of the Run Statechart function.
  7. Specify the trigger to send by wiring a value to the Trigger input of the Send External Trigger function.
    Tip  You can obtain a list of valid triggers by right-clicking the Trigger input and selecting either Create»Control or Create»Constant from the shortcut menu.
  8. Move the trigger constant or control inside the corresponding case of the Event structure.
  9. Wire the trigger constant or control to the Trigger input of the Send External Trigger function. This wire exits the Event structure through an output tunnel.
  10. For each case of the Event structure, right-click the output tunnel and select either Create Control or Create Constant. Change the control or constant to represent the trigger you want to send.

The caller VI now resembles the following figure:

The caller VI now is configured to execute and send triggers to the statechart.

Synchronous Statecharts

You use only one loop in a caller VI. This loop contains only the Run Statechart function. You also can use this loop to send triggers to the statechart by wiring a trigger to the Trigger input of this function.

This loop can be a While Loop. However, if you need to execute the statechart at specific intervals, National Instruments recommends placing the Run Statechart function in a Timed Loop instead.

Complete the following steps to configure a caller VI to execute a synchronous statechart.

  1. Place the Run Statechart function in the loop.
  2. (Optional) Specify the trigger to send by wiring a value to the Trigger input of the Run Statechart function.
    Tip  You can obtain a list of valid triggers by right-clicking the Trigger input and selecting either Create»Control or Create»Constant from the shortcut menu.

The caller VI now is configured to execute the statechart.

Creating a Caller VI to Call from C Code

Complete the following steps to create a statechart caller VI that you can call using C code.

Note  To build a build a shared library (DLL) for the project, you must have the Application Builder installed. The LabVIEW Professional Development System includes the Application Builder. If you use the LabVIEW Base Development System or Full Development System, you can purchase the Application Builder separately by visiting the National Instruments Web site.
  1. Select File»New Project to display the Project Explorer window.
  2. Right-click the My Computer item in the Project Explorer window and select Add»File from the shortcut menu.
  3. Navigate to the .lvsc file for the statechart you want to call and click the Add File button to add the statechart to the project.
  4. Select File»New VI to create a new VI. LabVIEW adds the new VI to the project.
  5. Create a caller VI that links to the statechart.
  6. Select File»Save to save the VI.
  7. From the Project Explorer window, select File»Save to save the project.
  8. Build a shared library (DLL) for the project. Define the caller VI as an exported VI in the shared library.

The DLL has the same functionality as the statechart caller VI. Using C code, obtain the function pointer to the address of the caller VI inside the DLL. You then can use the function pointer to call the caller VI inside the DLL. The caller VI will run the iterations of the statechart until the statechart terminates. The caller VI then returns output data to the C code construct.

WAS THIS ARTICLE HELPFUL?

Not Helpful