Back to the NetworkViewer Page
Qt 4.7 as a javascript engine called QScriptEngine that is well integrated with Qt. QScriptEngine allows an easy interface with C++ objects and offers great flexibility. Using javascript, we can then interact with the variables on the CAN bus. Function generators, variable conversions and complex logic can then be implemented in javascript for testing before the complete implementation in the embedded microcontroller. Test scripts can also be created to interact with multiple modules at once. The complete documentation of the QScriptEngine is available on the Qt/Nokia web site.
Specialized javascript functions and variables are available on the main context for easy access to NetworkModule, NetworkVariable C++ objects. Next sections describe the built-in variables and functions available.
TABLE 1 - ScriptEngine - Variables
Variable Description
time
Elapsed time since we started the script (seconds)
period
The selected period for the script execution. 0 = single shot.
cycle
The cycle counter [0..N]
modules[id]
Map of CAN modules/nodes on the bus. It is a NetworkModule (QObject). Each module has the following functions :
modules[id].variables[j]
Variable array.It is a mapping of javascript objects and ModuleVariable (QObject). Each variable has the following functions :
TABLE 2 - ScriptEngine - Functions.
Function Description
print(...);
Redirection to the graphical console.
* Ex : print("Hellow World!");
addToPlot(module_id,variable_id);
Add a variable to the scope.
Ex : addToPlot(1,"SetPoint");
createPseudoModule(module_id);
addPseudoModule(module_id);
Virtual module creation. module_id must be > 255 to avoid confusion with physical modules;
addScriptVariable(module_id,"Variable Name", "Variable Description");
add a variable to a module, can be a physical or pseudo module.
stop();
Stop the execution of the script (within the script).
(BETA) addSliderControl(module_id,variable_id,min_value,max_value);
create a slider to control a variable with min and max value.
if (cycle == 0)
{
addPseudoModule(500);
addScriptVariable(500,"Sinus1","Sinus1 value");
addToPlot(500,modules[500].Sinus1.index);
addScriptVariable(500,"Sinus2","Sinus2 value");
addToPlot(500,modules[500].Sinus2.index);
addScriptVariable(500,"Sinus3","Sinus3 value");
addToPlot(500,modules[500].Sinus3.index);
freq = 0.1;
amplitude = 100;
}
SinValue1 = amplitude * Math.sin(2 * Math.PI * freq * time);
SinValue2 = 2 * amplitude * Math.sin(4 * Math.PI * freq * time);
SinValue3 = 3 * amplitude * Math.sin(6 * Math.PI * freq * time);
modules[500].Sinus1.setUserValue(SinValue1);
modules[500].Sinus2.setUserValue(SinValue2);
modules[500].Sinus3.setUserValue(SinValue3);
true;