User Tools

Site Tools


datasourceconnectionsinmistudio

This is an old revision of the document!


Data Source Connections in MIStudio

In MIStudio, a data source refers to any component that sends out the data output, including but not limited to just the database servers.

Data source connections allow data flow from a data source to a target component. There are several ways to make data source connections.

Use Wired Connection

A data source could be connected by graphically drawing a connection wire to a target component. When connected, the data source’s output becomes the target component’s input.

In the diagram window, connect the data source output to the target input, by simply drawing a connector line.

The connection wire can be different colors in the Diagram Window depending on if data has been sent through it or not, or if there was an error.

A gray connector indicates that no Value Objects have been sent through since the application was loaded. A green connector indicates that a Value Object was sent successfully to its target. A red connector indicates an error.

Use "Manage Connections"

A data source and the target component also have “Manage Connections” to allow setting up connections. Right click on the component to bring up “Manage Connections”. How to set up connections in this method see below “Using Manage Connections” section.

As an alternative to drawing connections in the Diagram Window, connections can be added to and from components by using the Name of the source or target or. This is done by using “Manage Connections” on a component.

For example, assume that your data source is an Increment Server, and the target is an annunciator. Your intention is to have the annunciator receive and display the data sent out from the Increment Server, and you’ve already have these two components in the Diagram Window.

To get data flow from the Increment Server (data source) to the annunciator (target),

  1. Right click on the Increment Server and select “Manage Connections''.
  2. Right click on “output” and you will be able to “Add Targets”.
  3. Click on “Add Targets” and you will be shown another panel with all the available targets for the Increment Server.
  4. Select Target. Find the target entry of your intention (The annunciator), click on it and you will see the “Input” for data input. Select it and click. Press “Done” and Close the Select Target window.

To check if the Increment server output is connected to the input of the target com (annunciator), right click on the annunciator, select “Manage Connections”, you will see that the input is the output of the Increment Server, even though there is no connector line wired them together. You could also look at the Test Frame, seeing the output of the Increment Server is displaying and updating in the annunciator.

Use Scripts

A data source could also be connected in scripting, e.g. adding scripts to the server, or using the JavaScript bean, for calculations or situations needing more manipulations, where above connections can not handle.

“Data Flow/Scripts” are manipulators in MIStudio, they could get data from data sources, do calculations or other manipulations, and pass data to a target. How to use, and in which condition to use each and every “Data Flow/Scripts” manipulator is in another wiki.

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

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 “IncrementServer”. You can change the name to be more descriptive to your application.

All named data sources can be accessed in Javascript by using the syntax “ServerName →” where the name of the data source is “ServerName”. For example, to get the current value of the Increment Server called “IncrementServer”, you would add this line to the script:

 newValue = IncrementServer->getLongValue();

The ”→“ syntax gets you a reference to the server to the left of the ”→“. With this reference you can get a value from the server and assign it to a script variable “newValue”.

You can get integers (long), floats (doubles), booleans, and Strings from the server. Please make sure that the value converts to the type you intend or you will get a Java exception logged every time the JavaScript bean is triggered.

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 “ArrayDataSource”) to your Diagram Window.

avo = ArrayDataSource->getValueObject();
value1 = avo.elementAt(0); //this gets the first element of the array

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->getValueObject();
index = Index -> getIntValue();
test = array.getValue(index);

Scripting Input Value

Scripting Output Value

Sending Data to manupulator Inputs

datasourceconnectionsinmistudio.1708714435.txt.gz · Last modified: by amyw

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki