API funtions

The following API functions are available to you in JavaScript:


mainInterface.getProperty(property)

mainInterface.setProperty(property, value)

mainInterface.getVariable(variable)

mainInterface.setVariable(variable, value)

mainInterface.setVariableSync(variable, value)

mainInterface.log(logtype, tag, message)

mainInterface.playAudio(filename)

mainInterface.openView(viewname)



mainInterface.getProperty(property)

This function returns the value of a component property.


Parameter


  • property

The property parameter specifies the name of a property.


A property name always needs to meet one of the following syntaxes:


  • pagename.componentname.propertyname 
  • componentId.propertyname


In order to, for instance, read out the text from a text box with the name edit1 on the main page, the parameter to be transmitted must be: “Mainpage.edit1.Text“  

The syntax including the IDs only comes in to play when using the args-parameter mentioned earlier. (This parameter provides you with the needed IDs, in case you didn’t

specify a name for the questioned component.)



mainInterface.setProperty(property, value)

This function sets the value of a component property to a specific value. To set a value, the component must have a name.  


Parameters


  • property 

The full name of the property to be set. (See function getProperty)


  • value 

The value to be assigned to the property  



mainInterface.getVariable(variable)

This function returns the value of a variable as a string.

So even variables of types like Boolean or Int always return their value as string representation.

This should be taken into account when working further with returned values.


Parameter


  • variable 

The name with which the variable was created.
If the variable name exists in several data sources, the data source name must be specified beforehand.


Example: DataSourceName.VariableName



mainInterface.setVariable(variable, value)

This function sets the value of a variable asynchronously.


This process is asynchrony. This means that a call for “getVariable” immediately afterwards might not return the updated value. Best practice to work with this behavior is to save the

value beforehand in a local JavaScript-Variable to use it later in the script.If, for some reason, you really need the function “getVariable” to return the updated value immediately afterwards

there is a (highly discouraged) way of doing this: Using “setVariableSync” instead of “setVariable”. The big disadvantage of setting a variable synchronously is the impact on the user interface.

If the synchronous function is called frequently it might lead to the user interface freezing for a few seconds.


Parameters


  • variable 

The name with which the variable was created.
If the variable name exists in several data sources, the data source name must be specified beforehand.


Example: DataSourceName.VariableName  


  • value

The value to be assigned to the variable



mainInterface.setVariableSync(variable, value)

This function sets the value of a variable synchronously.  



Parameters


  • variable

The name with which the variable was created.
If the variable name exists in several data sources, the data source name must be specified beforehand.


Example: DataSourceName.VariableName


  • value

The value to be assigned to the variable



mainInterface.log (logtype, tag, message)
This function writes a log entry. The log can be opened in the QuickHMI Desktop Viewer & Web Viewer via the    - button.


Parameters


  • logtype 

As log types, the constants “I” for information, “W” for warning and “E” for error are available. These are displayed in different colors in the log.


  • tag 

Specifies the origin of the log entry


  • message

The message to be logged



mainInterface.playAudio(filename)

This function plays an audio file in the viewer.  


Parameter


  • filename

The name of the audio file (including file extension) that was previously imported in the QuickHMI Editor.




mainInterface.openView(viewname)

This function opens a page or view.  


Parameter


  • viewname 

The name of a page or a view.


If a view (a smaller part of a page) is to be displayed, the syntax for this is as follows: Pagename.Viewname