API functions

The following API functions are available in JavaScript:

mainInterface.getProperty
mainInterface.setProperty
mainInterface.getVariable
mainInterface.setVariable
mainInterface.setVariableSync
mainInterface.log
mainInterface.playAudio
mainInterface.openView

mainInterface.getProperty

This function returns the value of a property of a component.

mainInterface.getProperty(property)

Parameter

  • property
    The property parameter specifies the name of a property.

A property name must always correspond to one of the following syntaxes: pagename.componentname.propertyname

For example, to read the text of a text box with the name edit1 on the main page , the following parameter must be passed: “Mainpage.edit1.Text


mainInterface.setProperty

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

mainInterface.setProperty(property, value)

Parameter

  • property
    Name of the property to be set.

A property name must always correspond to one of the following syntaxes: pagename.componentname.propertyname

For example, to read the text of a text box with the name edit1 on the main page , the following parameter must be passed: “Mainpage.edit1.Text

  • value
    The value to be assigned to the property

mainInterface.getVariable

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

mainInterface.getVariable(variable)

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

This must be taken into account when working 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 first.

Example: DataSourceName.VariableName


mainInterface.setVariable

Function for asynchronous writing of a variable.

mainInterface.setVariable(variable, value, checkValueIsDifferent = true)

This process runs asynchronously. This means that retrieving the variable with “getVariable” in the following code does not necessarily have to return the updated value.

The best solution for this is to temporarily store the value in a local variable beforehand so that it does not have to be queried again.

If the value must be available immediately afterwards, the “setVariableSync” function can be used.

However, this is not recommended as this function call blocks the interface for a short period of time. This is not noticeable when called once. However, if this function is called at intervals or often in succession, this will have a noticeable effect on the interface.

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 first.

Example: DataSourceName.VariableName

  • value
    The value to be assigned to the variable
  • checkValueIsDifferent (as of QuickHMI 14.4.1)
    If true (default value): New value is checked against the current value before being sent to the data source. The value is only sent to the controller if there is a deviation.
    If false: New value is sent to the controller regardless of the current value.

mainInterface.setVariableSync

Function for synchronous writing of a variable.

mainInterface.setVariableSync(variable, value, checkValueIsDifferent = true)
Note: Only use this function if absolutely necessary. (See previous note on the "setVariable" function).


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 first.

Example: DataSourceName.VariableName

  • value
    The value to be assigned to the variable
  • checkValueIsDifferent (as of QuickHMI 14.4.1)
    If true (default value): New value is checked against the current value before being sent to the data source. The value is only sent to the controller if there is a deviation.
    If false: New value is sent to the controller regardless of the current value.

mainInterface.log(logtype, message)

This function writes a log entry. The log can be opened at runtime using thebutton. A log is also written to the browser console at the same time. In Chrome, for example, this can be opened with F12.

Parameter

  • logtype
    The constants “I” for Information, “W” for Warning and “E” for Error are available as log types. These are displayed in different colors in the log.
  • message
    The message to be logged.

mainInterface.playAudio

This function plays back an audio file in the viewer.

mainInterface.playAudio(filename)

Parameter

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

mainInterface.openView

This function opens a page or a view.

mainInterface.openView(viewname)

Parameter

  • viewname
    The name of a page or view.

If a view is to be displayed, the syntax is as follows: Pagename.viewname