This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

New JavaScript API in the upcoming firmware
#1
We've added several JavaScript functions to simplify object access in visualization.
Let us know about any functionality that you are missing on the JavaScript side.

Docs

Alias is either object group address or object name. (e.g. '1/1/1' or 'My object').
If object is not found you will get a warning in JavaScript console.

grp.all()
Returns all known objects.

grp.tag(tags[, mode = 'or'])
Returns objects matching the given tags. Tags parameter can be either an array or a string. Mode parameter can be either 'or' (default — returns objects that have any of given tags) or 'and' (return objects that have all of given tags).

grp.find(alias)
Returns single object for the given alias.

grp.getvalue(alias)
Returns value for the given alias or undefined when object cannot be found.

grp.gettags(alias)
Returns an array with all tags that are set for the given alias or false when object is not found.

grp.write(alias, value)
grp.update(alias, value)
Sends group write request to the given alias.

grp.listen(alias, callback[, all=false])
Executes callback when the given alias value changes, only when new value is different, unless all is set to true (Note: in this case callback might get called when no value change occured, for example, when values are re-read after lost connection).
Callback receives two parameters - object reference and state. State can be either 'init' (called when callback is registered) or 'value' (called when value changes).

grp.taglisten(tag, callback[, all=false])
Same as grp.listen but listens for all objects with matching tags.

Code:
grp.listen('My object', function(object, state) {
  console.log('New object value', object.value, state);
});
Reply


Messages In This Thread
New JavaScript API in the upcoming firmware - by admin - 13.06.2016, 08:46

Forum Jump: