Please see this overview page first to understand some basic principles about using scripting functions in SIGVIEW.


Custom display window processes input from one or more signal or instrument windows (parent windows) and produces the content of a new signal windows as a ready-to-use image, usually produced by using Julia plotting functions.


Julia includes comprehensive graphical capabilities by using various plotting packages. You will have to add these packages to Julia before using them with SIGVIEW. For example, to add Plots package, you would open Julia console and type 


using Pkg; Pkg.add("Plots"); using Plots


Instead of adding packages manually, you can also use a built-in function to add most needed packages at once. See Basic principles chapter for details.

How to create Custom display window


  1. If your new window should have only one source/parent window, then just click on the parent window and select Scripts/New custom display window main menu option.
  2. 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 custom display script window... menu option from the context menu of the Control Window.


In both cases, a new 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 be blank, showing only "No data to display" message.


The script template will already contain some content: In the upper part, you will find some help text and in the lower part you 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} )

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 this chapter for a reference about the struct types which can be included in this array. 
  • you should create a plot object in Julia by using any of the included plotting modules and functions. After the plot is ready, you can transfer it into the SIGVIEW window by using a function "displayPlotInSigview"



Let's show how this works on an example. We will use a boxplot function of a StatsPlots module to generate a display a Box-Plot from the input signal (parameter checking omitted for simplicity):


using StatsPlots

function process( input_windows::Array{SigviewWindow} )

 plot = boxplot(input_windows[1].samples)

 displayPlotInSigview( plot )

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 window. You can keep editing the script - each time you save it, SIGVIEW will execute it again and update the content of a window.



For information about Julia plotting capabilities, see https://docs.juliaplots.org/latest/tutorial/. There are many other internet resources which cover this topic and provide numerous script examples. Many Custom tools in SIGVIEW also use Julia plotting. You can inspect or modify the source code of these tools, for example Box plot/Violin plot, Scatter and Orbit plots, Bode and Polar plot / Polar plot etc.

Handling errors and displaying text


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 window in its upper left corner:




If you would like to report an error of your own from the script, you can define a corresponding text message to be displayed and return false from the process function. For example, if your script expects to have exactly two parents, you can check it and display appropriate error like this:


  if length( input_windows ) != 2

     output_signal.textToDisplay = "Error:\nThis script can process only 2 inputs signals"

     return false

  end



Even if you provide the content of the window, i.e. return true from the process function, you can still use textToDisplay variable to display a text in the result window, for example for debugging purposes.


Further reading


See scripting examples in this help and this chapter for some additional advanced functions you can implement in your script.