datasourceconnectionsinmistudio
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| datasourceconnectionsinmistudio [2024/02/23 13:46] – [Scripting Input Value] amyw | datasourceconnectionsinmistudio [2024/02/23 16:50] (current) – [Debugging JavaScript] amyw | ||
|---|---|---|---|
| Line 25: | Line 25: | ||
| To get data flow from the Increment Server (data source) to the annunciator (target), | To get data flow from the Increment Server (data source) to the annunciator (target), | ||
| + | < | ||
| - Right click on the Increment Server and select " | - Right click on the Increment Server and select " | ||
| - Right click on " | - Right click on " | ||
| - Click on "Add Targets" | - Click on "Add Targets" | ||
| - | - Select Target. Find the target entry of your intention (The annunciator), | + | - Select Target. Find the target entry of your intention (The annunciator), |
| + | | ||
| + | </ | ||
| To check if the Increment server output is connected to the input of the target com (annunciator), | To check if the Increment server output is connected to the input of the target com (annunciator), | ||
| Line 42: | Line 44: | ||
| JavaScript is used as a manipulator in MIStudio. JavaScript could get data by referencing data source and scripting input value, and pass data by scripting output value, and sending data to manupulator inputs. | JavaScript is used as a manipulator in MIStudio. JavaScript could get data by referencing data source and scripting input value, and pass data by scripting output value, and sending data to manupulator inputs. | ||
| - | === JavaScript Referencing Data Source === | ||
| - | === Scripting Input Value === | ||
| - | === Scripting Output Value === | ||
| - | === Sending Data to manupulator Inputs === | ||
| - | ===JavaScript | + | |
| + | |||
| + | |||
| + | |||
| + | === JavaScript | ||
| All components in the Diagram Window of MIStudio have names. For example when you add a new Increment Server to the logic its name will automatically be set to " | All components in the Diagram Window of MIStudio have names. For example when you add a new Increment Server to the logic its name will automatically be set to " | ||
| Line 61: | Line 63: | ||
| Here are some conversions for the simple Increment Server example: | Here are some conversions for the simple Increment Server example: | ||
| + | |||
| + | < | ||
| + | intValue = IncrementServer -> getIntValue(); | ||
| + | longValue = IncrementServer -> getLongValue(); | ||
| + | floatValue = IncrementServer -> getFloatValue(); | ||
| + | doubleValue = IncrementServer -> getDoubleValue(); | ||
| + | stringValue = IncrementServer -> getStringValue(); | ||
| + | boolValue = IncrementServer -> getBoolValue(); | ||
| + | </ | ||
| + | |||
| + | **Note: Be sure to pay attention to the spelling of the data source names and be aware that these names are case sensitive. If you edit the name of the data source in your logic, you must make the same change in your script.****Bold Text** | ||
| + | |||
| + | |||
| + | You can also get Array Value Objects from the server (if it is generating Array Value Objects) and get any data value from the individual elements of the array or other properties such as the size of the array. To test the script below add an Array Data Source (called " | ||
| + | |||
| + | < | ||
| + | avo = ArrayDataSource-> | ||
| + | value1 = avo.elementAt(0); | ||
| + | </ | ||
| + | |||
| + | Arrays are indexed starting at 0, so some of the elements of the array would be: | ||
| + | < | ||
| + | value2 = avo.elementAt(1); | ||
| + | value3 = avo.elementAt(2); | ||
| + | </ | ||
| + | |||
| + | etc. | ||
| + | |||
| + | You can also get an element of an AVO using getValue(). For example, to get the 4th element of the array (array indexes are zero based): | ||
| + | < | ||
| + | value4 = avo.getValue(3); | ||
| + | </ | ||
| + | |||
| + | Here is a small script that accesses a variable element of an input array: | ||
| + | |||
| + | < | ||
| + | array = TestArray-> | ||
| + | index = Index -> getIntValue(); | ||
| + | test = array.getValue(index); | ||
| + | </ | ||
| + | |||
| + | |||
| + | === Scripting Input Value === | ||
| + | |||
| + | When a script is used in a Manipulator, | ||
| + | |||
| + | The Value Object that was used to trigger the script can be accessed using " | ||
| + | |||
| + | For example: in your application you need to use the time from the incomingValue which triggers the script, it is like this: | ||
| + | |||
| + | < | ||
| + | |||
| + | To get the String Value of the Value Object, | ||
| + | |||
| + | < | ||
| + | |||
| + | To get the Long (or integer) value of a numeric input, | ||
| + | |||
| + | < | ||
| + | |||
| + | === Scripting Output Value === | ||
| + | |||
| + | The last line of the script will generate the output of the script. For example, if the following were the last line of the script a String Value Object would be automatically generated with the value " | ||
| + | |||
| + | < | ||
| + | output = " | ||
| + | </ | ||
| + | |||
| + | You may explicitly create other types of Value Objects and use them for the output. In this next script the Double Value Object " | ||
| + | |||
| + | < | ||
| + | output = " | ||
| + | svo = new StringValueObject(output); | ||
| + | dvo = new DoubleValueObject(43.128); | ||
| + | output = dvo; | ||
| + | </ | ||
| + | |||
| + | And the next script does the same thing (no need to use " | ||
| + | |||
| + | < | ||
| + | output = " | ||
| + | svo = new StringValueObject(output); | ||
| + | dvo = new DoubleValueObject(43.128); | ||
| + | </ | ||
| + | |||
| + | which is also equivalent to: | ||
| + | < | ||
| + | output = " | ||
| + | svo = new StringValueObject(output); | ||
| + | new DoubleValueObject(43.128); | ||
| + | </ | ||
| + | === Sending Data to manupulator Inputs === | ||
| + | |||
| + | In many cases, you may want to send values in Javascript to another named manipulator (or Broadcast Server) in your project' | ||
| + | |||
| + | < | ||
| + | Value1 = IncrementServer-> | ||
| + | </ | ||
| + | |||
| + | assume there is a " | ||
| + | |||
| + | < | ||
| + | sql = " | ||
| + | sql = sql + "'" | ||
| + | BCS -> setStringValue(sql); | ||
| + | sql; | ||
| + | </ | ||
| + | |||
| + | When the BCS connects to the DatabaseRawWrite component ( the component writes to the database), the BCS should handle the SQL statement first, then trigger the write. Therefore, right click on the DatabaseRawWrite to bring up “Expose properties”, | ||
| + | |||
| + | If the data source, or the target | ||
| + | |||
| + | For example: | ||
| + | < | ||
| + | DataValue=/ | ||
| + | </ | ||
| + | |||
| + | In this script: | ||
| + | < | ||
| + | / | ||
| + | </ | ||
| + | |||
| + | The above example creates a Value Changed Event to send the Value Object " | ||
| + | |||
| + | Similarly to this, “Manage Connections” has the same function. You could set up a Broadcast Server to receive data from another application, | ||
| + | |||
| + | === Debugging JavaScript === | ||
| + | |||
| + | When you trigger the JavaScript bean to start its script, you can easily determine whether a mistake has been made in the JavaScript program because the connection line between the trigger data source and the JavaScript bean will be red. If it was successful, the line would be green. This does not mean that your program is correct, but that there were no errors. | ||
| + | |||
| + | If the connection line is red, select the connection and look at the description line at the bottom of the Diagram Window to get some information about the problem. | ||
| + | |||
| + | **Syntax Errors** | ||
| + | |||
| + | The script is interpreted in two passes. The first pass checks the syntax of the program lines (does not try to evaluate any statements). In this pass, the script will stop immediately if there is an error and produce an error line that has " | ||
| + | |||
| + | You have to go to the 35th line in the JavaScript code and find that you forgot to enclose a boolean condition statement with parentheses. Sometimes it is easier to find the nth line in the code by copying the JavaScript into a text editor that will display line numbers. | ||
| + | |||
| + | Another common syntax error is forgetting a quote on a String. If you see | ||
| + | < | ||
| + | look on line 12 of the script and make sure you have quotes around the string in the line. For example, | ||
| + | |||
| + | < | ||
| + | |||
| + | **Execution Errors** | ||
| + | |||
| + | Once the interpreter gets past the syntax check, it will try to execute the code, top down. Functions are not evaluated until called. Typical errors at this stage do not tell you any line numbers. Here are some examples and causes. | ||
| + | |||
| + | |||
| + | **TypeError: | ||
| + | |||
| + | < | ||
| + | |||
| + | When you get a " | ||
| + | |||
| + | 1. Referencing graphical objects | ||
| + | |||
| + | < | ||
| + | |||
| + | This will cause an error because " | ||
| + | |||
| + | 2. Referencing beans that do not exist (wrong name) | ||
| + | |||
| + | < | ||
| + | |||
| + | if there is no logic component named " | ||
| + | |||
| + | |||
| + | **TypeError: | ||
| + | |||
| + | This error will say | ||
| + | |||
| + | < | ||
| + | |||
| + | This will happen if you are calling a server method such as < | ||
| + | |||
| + | < | ||
| + | Ivo = IncrementServer-> | ||
| + | test = lvo.getLength(); | ||
| + | </ | ||
| + | |||
| + | because getLength() does not exist as a method for a Value Object. | ||
| + | |||
| + | Unfortunately for this error there is no indication of what the faulty method name is so you have to study your JavaScript carefully to see the problem. | ||
| + | |||
| + | **ReferenceError: | ||
| + | |||
| + | If you reference a variable that does exit you will get an | ||
| + | < | ||
| + | |||
| + | For example, if your code says: | ||
| + | |||
| + | < | ||
| + | vo = new StringValueObject(stateString); | ||
| + | </ | ||
| + | |||
| + | and the variable " | ||
| + | < | ||
| + | |||
| + | | ||
| + | < | ||
| + | stateString = CombineStrings -> getStringValue(); | ||
| + | </ | ||
| + | |||
| + | or | ||
| + | |||
| + | < | ||
| + | stateString = " | ||
| + | </ | ||
| + | |||
| + | **ReferenceError: | ||
| + | |||
| + | This error is caused by referencing a defined function called " | ||
| + | |||
| + | |||
| + | ((**A DataSourceConnections.frx file is attached for you to download and add to your applications directory. You could open the DataSourceConnections application to see the examples. The Design Window has descriptions and the Diagram window is the place to see all the connections and data flows.** | ||
| + | )) | ||
| + | |||
| + | |||
| + | |||
| + | |||
datasourceconnectionsinmistudio.1708713992.txt.gz · Last modified: by amyw
