Main /
CapeCodeScriptParameterBelow are notes about the Problem StatementWe would like to write JavaScript that replicates the Cape Code NonStrictTest actor and share that JavaScript code between multiple Composite Accessors. We now have https://ptolemy.berkeley.edu/accessors/test/TrainableTest.js, which implements a subset of that functionality. The problem is how to use it? The script Parameter of the JavaScript actor.One way would be to use the File ReaderThe Ptolemy way is to drag in a FileReader, set the fileOrURL to The problems here are:
So, we connect the trigger port: Note that the ports of the JavaScript actor are not updated. After we run the model the ports of the JavaScript actor are updated. If we run the model, we get this stack trace: ptolemy.kernel.util.IllegalActionException: Failure executing the react function: Error: After seeing 0 tokens, the value of the input was null? Perhaps the input is not connected? in <function> at line number 55 at column number 16 in .RampJSTestJS.JavaScript Because: Error: After seeing 0 tokens, the value of the input was null? Perhaps the input is not connected? in <function> at line number 55 at column number 16 at ptolemy.actor.lib.jjs.JavaScript._invokeMethodInContext(JavaScript.java:1856) at ptolemy.actor.lib.jjs.JavaScript.fire(JavaScript.java:904) at ptolemy.domains.de.kernel.DEDirector._fire(DEDirector.java:1955) at ptolemy.domains.de.kernel.DEDirector.fire(DEDirector.java:501) at ptolemy.actor.CompositeActor.fire(CompositeActor.java:454) at ptolemy.actor.Manager.iterate(Manager.java:841) at ptolemy.actor.Manager.execute(Manager.java:367) at ptolemy.actor.Manager.run(Manager.java:1252) at ptolemy.actor.Manager$PtolemyRunThread.run(Manager.java:1903) Caused by: javax.script.ScriptException: Error: After seeing 0 tokens, the value of the input was null? Perhaps the input is not connected? in <function> at line number 55 at column number 16 at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:467) at jdk.nashorn.api.scripting.NashornScriptEngine.invokeImpl(NashornScriptEngine.java:389) at jdk.nashorn.api.scripting.NashornScriptEngine.invokeMethod(NashornScriptEngine.java:199) at ptolemy.actor.lib.jjs.JavaScript._invokeMethodInContext(JavaScript.java:1833) ... 8 more Caused by: <function>:55:16 Error: After seeing 0 tokens, the value of the input was null? Perhaps the input is not connected? at jdk.nashorn.internal.objects.NativeError.initException(NativeError.java:137) at jdk.nashorn.internal.objects.NativeError.<init>(NativeError.java:102) at jdk.nashorn.internal.objects.NativeError.<init>(NativeError.java:106) at jdk.nashorn.internal.objects.NativeError.<init>(NativeError.java:110) at jdk.nashorn.internal.objects.NativeError.constructor(NativeError.java:129) at jdk.nashorn.internal.scripts.Script$Recompilation$18991$1677$\^function\_.L:1$fire(<function>:55) at jdk.nashorn.internal.scripts.Script$Recompilation$18990$57155A$require.L:1$react(/Users/cxh/ptII/ptolemy/actor/lib/jjs/external/require.js#325:30<eval>:1353) at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:662) at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:228) at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393) at jdk.nashorn.api.scripting.ScriptObjectMirror.callMember(ScriptObjectMirror.java:199) at jdk.nashorn.api.scripting.NashornScriptEngine.invokeImpl(NashornScriptEngine.java:383) ... 10 more Caused by: javax.script.ScriptException: Error: After seeing 0 tokens, the value of the input was null? Perhaps the input is not connected? in <function> at line number 55 at column number 16 at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:467) at jdk.nashorn.api.scripting.NashornScriptEngine.invokeImpl(NashornScriptEngine.java:389) at jdk.nashorn.api.scripting.NashornScriptEngine.invokeMethod(NashornScriptEngine.java:199) at ptolemy.actor.lib.jjs.JavaScript._invokeMethodInContext(JavaScript.java:1833) at ptolemy.actor.lib.jjs.JavaScript.fire(JavaScript.java:904) at ptolemy.domains.de.kernel.DEDirector._fire(DEDirector.java:1955) at ptolemy.domains.de.kernel.DEDirector.fire(DEDirector.java:501) at ptolemy.actor.CompositeActor.fire(CompositeActor.java:454) at ptolemy.actor.Manager.iterate(Manager.java:841) at ptolemy.actor.Manager.execute(Manager.java:367) at ptolemy.actor.Manager.run(Manager.java:1252) at ptolemy.actor.Manager$PtolemyRunThread.run(Manager.java:1903) Caused by: <function>:55:16 Error: After seeing 0 tokens, the value of the input was null? Perhaps the input is not connected? at jdk.nashorn.internal.objects.NativeError.initException(NativeError.java:137) at jdk.nashorn.internal.objects.NativeError.<init>(NativeError.java:102) at jdk.nashorn.internal.objects.NativeError.<init>(NativeError.java:106) at jdk.nashorn.internal.objects.NativeError.<init>(NativeError.java:110) at jdk.nashorn.internal.objects.NativeError.constructor(NativeError.java:129) at jdk.nashorn.internal.scripts.Script$Recompilation$18991$1677$\^function\_.L:1$fire(<function>:55) at jdk.nashorn.internal.scripts.Script$Recompilation$18990$57155A$require.L:1$react(/Users/cxh/ptII/ptolemy/actor/lib/jjs/external/require.js#325:30<eval>:1353) at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:662) at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:228) at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393) at jdk.nashorn.api.scripting.ScriptObjectMirror.callMember(ScriptObjectMirror.java:199) at jdk.nashorn.api.scripting.NashornScriptEngine.invokeImpl(NashornScriptEngine.java:383) ... 10 more So, we connect the input and set the training mode and then run the model. After running in training mode, the problem is that the Code Generation for Composites Accessors.Even worse, the FileReaderActor cannot be used in a composite accessor, so the Accessor code generator will fail. Possible SolutionA possible solution would be to have the body of the JavaScript file read the contents of the script. However, this probably causes problems with the same-origin policy. Also, I'm not sure how to do it. SolutionWe decided to make TrainableTest be an accessor. See How To Create A Node Module -> When to create an accessor. |