>From: [EMAIL PROTECTED] (john m.)
>Subject: Convert parameters to ports
>Date: 3 Sep 2002 07:55:21 -0700
>
>Dear all,
>
>I would greatly appreciate it somebody could point out a solution to
>the following problems:
>
>1. Is there a way in Vergil (PtolemyII) to add ports to an actor and
>connect it to the parameters in the actor? I know it can be done on
>custom copies of the actors at the .java source level (implementing
>propably in the fire method) but I was looking for something quick in
>Vergil.
>
>2. Is it possible and how to connect an input port to a user defined
>parameter in a composite actor? In other words can the value of a user
>defined parameter be updated by the output of some other actor? If
>this was possible then problem 1. can be solved by making composite
>actors containing the actors i need with ports by stting the internal
>parameters of the original actor in terms of the user parameters of
>the composite actor that contains them, which in turn (the user
>defined parameters) would be connected to the input port of the
>corresponding composite actor.


Interestingly, I'm implemented this just a few weeks ago.
In my implementation, you create an instance of PortParameter,
and it automatically creates an associated ParameterPort.
Below is the doc for the PortParameter class.  Of course,
this isn't in any release yet...  It might just work to
install the new classes on top of the 2.0.1 release, but there
are two risks:

1) It won't work.
2) The implementation and/or interface will change in the next release.

Let me know if you want to try...

Edward


//////////////////////////////////////////////////////////////////////////
//// PortParameter
/**
A parameter that creates an associated port that can be used to update
the current value of the parameter.  The "current value" is set by the
setCurrentValue() method and read by getToken().  The current value
is distinct from the persistent value, which is set by setExpression()
or setToken(), and accessed by getExpression().  Note that getToken()
returns the current value, which is not necessarily the persistent value.
The current value can be set in the usual way for a parameter (calling
setToken() or setExpression()), or by feeding data into the associated port.
Until the port receives data, the current value of the parameter is
the same as the persistent value.  After the port has received
data, then the current value is that most recently received on the port
since the last update of the persistent value.
The getExpression() methods always return the persistent
value, regardless of whether an override value has been received on the
input port.  On each call to getToken(), this parameter first checks
to see whether an input has arrived at the associated port
since the last setExpression() or setToken(), and if so, returns a token
read from that port.  Also, any call to get() on the associated
port will result in the value of this parameter being updated.
<p>
When using this parameter in an actor, care must be exercised
to read its value exactly once per firing by calling getToken().
Each time getToken() is called, a new token will be consumed from
the associated port (if there is a token).  If this is called
multiple times in an iteration, it may result in
consuming tokens that were intended for subsequent firings.
Thus, for example, it should not be called in fire() and then
again in postfire().  Moreover, in some domains (such as DE),
it is essential that if a token is provided on a port, that it
is consumed.  In DE, the actor will be repeatedly fired until
the token is consumed.  Thus, it is an error to not call getToken()
once per iteration.
<p>
If this is actor is placed in a container that does not implement
the TypedActor interface, then no associated port is created,
and it functions as an ordinary parameter.  This is useful,
for example, if this is put in a library, where one would not
want the associated port to appear.

@author Edward A. Lee
@version $Id: PortParameter.java,v 1.11 2002/08/30 04:35:22 cxh Exp $
*/
public class PortParameter extends Parameter {
   etc.
}



------------
Edward A. Lee, Professor
518 Cory Hall, UC Berkeley, Berkeley, CA 94720
phone: 510-642-0455, fax: 510-642-2739
[EMAIL PROTECTED], http://ptolemy.eecs.berkeley.edu/~eal


----------------------------------------------------------------------------
Posted to the ptolemy-hackers mailing list.  Please send administrative
mail for this list to: [EMAIL PROTECTED]

Reply via email to