Probe signal values in a model using the Model Interface API, including signal buffering, formatting, and accessing values during execution.

Signals in a model serve as probes, or test points, of a model as it runs. An outport connects to other parts of the application and must return data during every time step. Applications do not need to read signal values at such a high priority. The Model Interface API provides VIs for accessing signal values in the background portion of your code.

The following block diagram shows the use of a Timed Loop that steps the model at a constant rate and a While Loop that reads signal values and displays them on the front panel:

Figure 9. Reading Signal Values
Block diagram showing a Timed Loop for model stepping and a While Loop for reading and displaying signal values.

Both loops run until an error occurs or the stop front panel control is TRUE.

The code performs the following steps:

  1. Loads the model from disk.
  2. Reads the compiled rate of the model in seconds, which is used to calculate the Timed Loop period.
  3. Performs the following tasks to prepare the VI to read signal values:
    1. Returns an array of paths for all the signals in the model.
    2. Creates a Signal Interface reference that you pass to other VIs to define which signals to probe and to get values from the probed signals.
  4. Defines the list of signals to probe in the Signal Paths array. The Maximum Probed Data History input also configures the Model Interface API to store signal values from up to 100 model time steps in a buffer.
    Tip To improve performance in your application, only probe signals whose values you need. Avoid frequently changing the signals to probe. Probing many signals and frequently changing the signal list can both decrease performance.
  5. Steps the model during each iteration of the Timed Loop. Reads and writes inports and outports. The Timed Loop iterates until an error occurs or the stop control is TRUE.
  6. Returns the signal values from a specific model time step. The format of this output is a flattened 1D array that contains the values of each signal.
    Tip This VI contains a Simulation Time output. This output returns the elapsed time in the model, in seconds, when the model produced the current signal values. This value is useful for allowing you to correlate events within the model with the time they occurred.
  7. When LabVIEW returns probed signal values before the timeout, the False case of the Case structure converts the array of signal values to a cluster and plots them in a waveform chart on the front panel.
  8. Closes the reference to the signal-probe session. Unloads the model from memory, and handles any errors.

For an example code that demonstrates probing signal values, see the MIT Signal Probes VI in the labview\examples\Control and Simulation\Model Interface directory.

The Get Probed Signal Values VI returns signal values in the following formats, depending on which instance of the polymorphic VI you use:

  • Raw—Returns signal values in a flattened 1D array in column-major order. This polymorphic instance allows your code to run with higher performance.
    Tip If you read probed signal values in raw format, you can format them offline using the Format Raw Signal Values VI.
  • Formatted—Returns signal values in a formatted array in which the value for each signal is a separate element, shown as follows:
    Figure 10. Formatted Array of Signals
    A user interface showing signal paths and their corresponding probed data values.
  • To change the signals that the Model Interface API is probing while the control loop steps the model, call the Set Signals to Probe VI again with the new list of signals. If any signal values from the previous signal list are still in the signal buffer, meaning the Get Probed Signal Values VI has not returned those values, the Model Interface API discards those values and immediately starts buffering values for the new signal list.

    Storing Signal Values from Multiple Time Steps

    Each time the Get Probed Signal Values VIs executes, it returns signal values from the earliest time step for which LabVIEW stores signal data. Storing signal values from multiple time steps is useful because code that probes signals typically runs at a lower priority than the control loop that steps your model. Therefore, the model might execute multiple times, producing multiple values for each signal, between subsequent calls to the Get Probed Signal Values VI.
    Tip If you find that the Get Probed Signal Values VI loses signal values because it does not run before the buffer overflows, you can increase the value of the Maximum Probed Data History input of the Set Signals to Probe VI.