Home

Flexs Q5 Logic Scripting

Overview

Flexs Logic Script provides the ideal solution for remote site automation of routine tasks including

  • Automatic Battery Run-Time Testing
  • Automatic Generator Starting
  • SCADA Automation, Pump Control, Etc.
  • Remote Site Load Control
  • HVAC and Environmental Control

Built-in API

A wide array of functions are built in allowing for access to the various onboard peripherals including the analog inputs, relays, power metrics etc.

Examples for almost all the functions are contained in the Flexs Q5 web interface, you can refer to the function documentation on the right for additional information.

// Example code

/*
This example demonstrates how to access the analog input values from a logic script.
To check the operational status of the analog conversion check the reading of the __status().adc_sps variable.
*/

// binding the loop to the run() function allows the Flexs Q5 to stop the script during configuration updates,prevents unexpected behaviour
while(run()){

  let input1 = inputs(1);

  print(JSON.stringify(input1)); // Print all the possible options for this object
  //{"ripple":0.001878,"state":false,"max":0.001997,"min":-0.000126,"inst":0.001106,"avg":0.000976}
  print('Input 1 Avg: ',input1.avg);

  waitMS(1000); // wait 1 second (1000ms)
}

Usage and Syntax

Flexs Logic Script is based on mJS which implements a strict subset of ES6 (JavaScript version 6):

  • Any valid mJS code is a valid ES6 code.
  • Any valid ES6 code is not necessarily a valid mJS code.

All logic scripts must exit or return within 4 seconds of run() becoming false. This allows scripts to stop gracefully during configuration changes.

Using the waitMS() for delays longer than 4 seconds is permitted however since waitMS() will return immediately if the script is told to stop.

Correct (Preferred):

// binding the loop to the run() function allows the Flexs Q5 to stop
// the script during configuration updates,prevents unexpected behaviour
while(run()){

}

Correct:

while(true){

if(!run())
{
return 0;
}

}

Incorrect:

while(true){

}

Restrictions

  • No standard library. No String, Number, RegExp, Date, Function, etc.
  • JSON.parse() and JSON.stringify() are available.
  • No closures, only lexical scoping (i.e. nested functions are allowed).
  • No exceptions.
  • No new. In order to create an object with a custom prototype, use Object.create(), which is available.
  • Strict mode only.
  • No var or const only let.
  • No for..of, =>, destructors, generators, proxies, promises.
  • No getters, setters, valueOf, prototypes, classes, template strings.
  • No == or !=, only === and !==.
  • mJS strings are byte strings, not Unicode strings: 'ы'.length === 2, 'ы'[0] === '\xd1', 'ы'[1] === '\x8b'. mJS string can represent any binary data chunk.