Class LabVIEWSimulator

  • All Implemented Interfaces:
    java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, SequenceActor, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

    public class LabVIEWSimulator
    extends Simulator
    Actor that works with a LabVIEW simulation program. To use this actor, the LabVIEW program must follow a fixed semantics, which is specified later in this documentation.

    This actor communicates the LabVIEW simulation program, as well as synchronizes simulated physical time between these two platforms. This actor assumes the Ptolemy program dictates what time to advance to, while the LabVIEW program proposes times to advance to.

    This actor can be invoked in two cases, one, when an input is received from the Ptolemy II simulation; two, when this actor triggers itself to fire at some future time through the use of pure events. In either case, outputs may or may not be produced by this actor. However, since the timeline this actor deals with is the simulated physical time, the outputs produced should not be a response of consumed input at the same time. The LabVIEW program should ensure this behavior.

    At initialization, this actor reads input from the LabVIEW program, which proposes a simulated physical time (hereby referred to as "time", unless otherwise stated) to advance to. This actor then produces a pure event (by calling fireAt() of the director, with this time as its timestamp. Notice this time may or may not be different from the current time of the Ptolemy simulation environment.

    The director will invoke this actor either when a trigger event arrives at this actor's input port, or when the pure event produced earlier triggers this event. In the first case, the input is consumed, and this data is transmitted into the LabVIEW program. The LabVIEW program should then react to this input and propose the next time to advance to, and send it back to the Ptolemy actor. Also, if a previous input has decided to produce an output at the current time, then an output will be produced by the LabVIEW program at the current time, and that output will be produced by this actor.

    The key assumption we make about the LabVIEW program is that it always has information about what is the next time it wants to advance to. Thus at any point in time when the LabVIEW program is invoked, it proposes a new time to advance to, and send that time to the Ptolemy program.

    Since:
    Ptolemy II 10.0
    Version:
    $Id$
    Author:
    Jia Zou
    • Method Detail

      • fire

        public void fire()
                  throws IllegalActionException
        Send the input token to the client program and send the output from the client program to the output port. However if the received proposed time to advance to from LabVIEW is less than 0, it is interpreted as an indication to terminate the program. In which case this actor does not send an event to the output port. Nor do we call fireAt(). Note the other way to stop execution is to set the stop time of the DE actor to a finite value.
        Specified by:
        fire in interface Executable
        Overrides:
        fire in class Simulator
        Throws:
        IllegalActionException - If the simulation time between Ptolemy and the client program is not synchronized.
      • _getDoubleArray

        protected double[] _getDoubleArray​(Token t)
                                    throws IllegalActionException
        Get a double array from the Token.
        Overrides:
        _getDoubleArray in class Simulator
        Parameters:
        t - the token which must be a type that can be converted to an ArrayToken
        Returns:
        the double[] array with the elements of the Token
        Throws:
        IllegalActionException - If the base class throws it.
      • _startSimulation

        protected void _startSimulation()
                                 throws IllegalActionException
        Start the simulation program. Currently we do this manually, but there should be a way to run a labview model through command line.
        Overrides:
        _startSimulation in class Simulator
        Throws:
        IllegalActionException - If the simulation process arguments are invalid.
      • _outputInitToken

        protected void _outputInitToken()
                                 throws IllegalActionException
        During initialize, we output one token to startup the co-simulation between Ptolemy and LabVIEW program.
        Overrides:
        _outputInitToken in class Simulator
        Throws:
        IllegalActionException - If there the client flag is non-zero, or the double array returned by the server is null.