mistudio_scripting

Javascript may be used in two ways while developing projects in MIStudio. In both cases here are some hints to help you with your scripts:

“incomingValue” is the original raw data or final calculated value in the case of a manipulator. In both cases you can consider “incomingValue” to be the value which the bean would output to its target if there was no script.

incomingValue is a “ValueObject” which has properties, the most important of which is its value. This value can be an int, long, float, double, boolean, or String. Sometimes, depending on the type of data source, the valueObject may be an array (ArrayValueObject) or a 2-dimensional array (TwoDimensionalValueObject).

Other properties of the ValueObject of interest are its quality, color, and timestamp.

The value of the incomingValue is accessed using one of these methods: getBoolValue(), getIntValue(), getLongValue(), getFloatValue(), getDoubleValue(), and getStringValue(), unless the incomingValue is an ArrayValueObject. Elements of an ArrayValueObjects are ValueObjects. In other words, incomingValue.elementAt(0) will return the first ValueObject of the array, the value of which can be accessed using one of the get methods listed above.

Bean Scripting

Data Source beans, such as PLC beans or sample data sources such as Random Data, will have a Script property. Here javascript may be entered which will effect the raw data before it is sent to the connection to the target.

As an example, to scale the original data, you may enter something such as:

output=incomingValue.getFloatValue()*2.1 + 19.7

Using the JavaScript Bean

Scripts may be entered in the editor for the JavaScript Bean. The JavaScript bean is only available for non-HMI versions of MIStudio (MIStudio with the Diagram Window). IncomingValue for this bean is the value of the data source via the incoming connector. More information on using the JavaScript bean can be found by pressing the “F1” key while the JavaScript bean is selected in the Diagram Window.

  • mistudio_scripting.txt
  • Last modified: 2020/05/12 19:15
  • by wikiadmin