Class LabVIEWSimulator
- java.lang.Object
-
- 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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
-
Fields inherited from class lbnl.actor.lib.Simulator
clientTerminated, cliPro, dblWri, firstFire, flagWri, isHeadless, LS, outTok, outTokStale, porNo, programArguments, programName, server, showConsoleWindow, simTimAbsTol, simTimPre, simTimReaPre, simulationLogFile, socketConfigurationFile, socketPortNumber, socketTimeout, synchronizeWithClient, terminationMessage, tokTim, warWin, worDir, workingDirectory
-
Fields inherited from class ptolemy.domains.sdf.lib.SDFTransformer
input, input_tokenConsumptionRate, output, output_tokenInitProduction, output_tokenProductionRate
-
Fields inherited from class ptolemy.actor.TypedAtomicActor
_typesValid
-
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
-
-
Constructor Summary
Constructors Constructor Description LabVIEWSimulator(CompositeEntity container, java.lang.String name)
Construct an actor with the given container and name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected double[]
_getDoubleArray(Token t)
Get a double array from the Token.protected void
_outputInitToken()
During initialize, we output one token to startup the co-simulation between Ptolemy and LabVIEW program.protected void
_startSimulation()
Start the simulation program.protected void
_writeToServer()
Write the data to the server instance, which will send it to the client program.void
fire()
Send the input token to the client program and send the output from the client program to the output port.boolean
prefire()
Return true and do not check the inputs.-
Methods inherited from class lbnl.actor.lib.Simulator
_readFromServer, clone, cutQuotationMarks, fireAndSanityCheck, fireAndSynchronize, initialize, preinitialize, resolveCommandName, resolveDirectory, wrapup
-
Methods inherited from class ptolemy.actor.TypedAtomicActor
_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, postfire, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate
-
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
-
Methods inherited from class ptolemy.kernel.Entity
_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
-
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeChanged, attributeDeleted, attributeList, attributeList, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
-
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, postfire, stop, stopFire, terminate
-
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, removeInitializable
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
Constructor Detail
-
LabVIEWSimulator
public LabVIEWSimulator(CompositeEntity container, java.lang.String name) throws NameDuplicationException, IllegalActionException
Construct an actor with the given container and name.- Parameters:
container
- The container.name
- The name of this actor.- Throws:
IllegalActionException
- If the actor cannot be contained by the proposed container.NameDuplicationException
- If the container already has an actor with this name.
-
-
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 interfaceExecutable
- Overrides:
fire
in classSimulator
- Throws:
IllegalActionException
- If the simulation time between Ptolemy and the client program is not synchronized.
-
prefire
public boolean prefire() throws IllegalActionException
Return true and do not check the inputs.- Specified by:
prefire
in interfaceExecutable
- Overrides:
prefire
in classSDFTransformer
- Returns:
- Always return true, indicating that this actor is ready for firing.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
_getDoubleArray
protected double[] _getDoubleArray(Token t) throws IllegalActionException
Get a double array from the Token.- Overrides:
_getDoubleArray
in classSimulator
- 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 classSimulator
- 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 classSimulator
- Throws:
IllegalActionException
- If there the client flag is non-zero, or the double array returned by the server is null.
-
_writeToServer
protected void _writeToServer() throws IllegalActionException
Write the data to the server instance, which will send it to the client program.- Overrides:
_writeToServer
in classSimulator
- Throws:
IllegalActionException
- If there was an error when writing to the server.
-
-