Instrument windows
Please see this overview page first to understand some basic principles about using scripting functions in SIGVIEW.
Script instrument window processes input from one or more signal or instrument windows (parent windows) and produces a single numeric value as a result, displayed in an instrument window. For example, you would use it if you want to implement your own measurement or calculation which produces a single number from one or more input signals.
How to create Script Instrument Window
If your new window should have only one source/parent window, then just click on the parent window and select Scripts/Instrument window main menu option.
If your new window should have multiple source/parent windows, you can create it from a Control Window. Just select all parent windows in the Control Window and select New script instrument window... menu option from the context menu of the Control Window.
In both cases, a new instrument window will open. At the same time a source code editor will open, opening script template and allowing you to edit a script to define the content of your window. Until you write and save your script, window will show the default value of 0.
The script template will already contain some content: In the upper part, you will find some help text and in the lower part a short reference of all important types you can use. The important part is in the middle - it is the process(...) function:
function process( input_windows::Array{SigviewWindow}, output_instrument::SigviewInstrumentWindow )
#write your code here
return false
end
This is the only function you have to fill with content.
input_windows is an array containing all parent/source windows of your new window. See Data types chapter for a reference about the struct types which can be included in this array.
output_instrument is the instrument result of your new window. You have to set its value (and optionally its unit) in this function.
The function should return true if the content of output_instrument is valid and should be displayed, false otherwise.
For detailed description of SigviewWindow and SigviewInstrumentWindow struct types, see Data types chapter.
Let's show how this works on an example. If we would like to create an instrument which calculates the mean value of its (first) parent signal, the process function would look like this:
function process( input_windows::Array{SigviewWindow}, output_instrument::SigviewInstrumentWindow )
output_instrument.value = sum(input_windows[1].samples) / length(input_windows[1].samples)
output_instrument.unit = input_windows[1].yAxisUnit
return true
end
As soon as you save the script from your editor, SIGVIEW will detect that the script has changed, the script will be executed and the result will be displayed in a SIGVIEW instrument window. You can keep editing the script - each time you save it, SIGVIEW will execute it again and update the displayed value.
If your process(...) script returns false, the instrument will keep showing the last valid value.
You can explicitly execute the script again by selecting Execute script... context menu option.
Setting the instrument name
You can optionally define a toolName() function in your script to set the name displayed in the title bar of the instrument window. For example:
function toolName()
return "Mean value"
end
Handling errors
If you make an error in your script, for example syntax error, using unknown function or variable etc., you will see the corresponding Julia error message in your SIGVIEW instrument window.
You can copy the displayed error text to the clipboard by using Copy text output to clipboard context menu option.
Further reading
See scripting examples in this help and Advanced topics chapter for some additional advanced functions you can implement in your script.