Custom Instrument Tutorial - Writing the Script

Frozen Content

Before we look at the script itself, let's recap what we want to have happen, in relation to the data output from our custom instrument:

  • In normal operation, the output should be placed under the control of the Numeric Panel control.
  • If either the 'DAUGHTER BD TEST/RESET' button on the Desktop NanoBoard, or the SOFTWARE OVERRIDE button on the instrument panel is pressed, the Numeric Panel should be overriden. The value output should be zero, and the corresponding message appear on the instrument panel, to alert the user to which override has been engaged.

Click on the Code tab at the bottom of the Custom Instrument Configuration dialog. You will be presented with a blank page on which to write the content of your script (Figure 1).


Figure 1. Code tab - providing an area to develop your DelphiScript code.

Note: Only DelphiScript is supported when writing script for a custom instrument. Should you wish to write your script within the comfort of a code-aware editor within Altium Designer, simply click the Open in Code Editor button at the bottom of the dialog. This allows you to take advantage of the syntax highlighting and related code-based features available in the editor, that are not available in the Code tab of the dialog. If you use the Code Editor to write your script, simply save the file when done and the code will be available in the dialog when next accessed.

Type the following script. The comments can of course be omitted, but it is always good practice to comment code and, for the purposes of this tutorial, highlight what the script is being used to achieve.

//The following procedure is entered when a read or write event occurs within the area of the
//designed panel

procedure TDesignedAreaPanel.DesignedAreaPanelReadWrite(Sender: TObject);
begin

//Initialize override captions

         NB_Override.Caption := '';
         Panel_Override.Caption := '';

//SignalManager is a global function that allows you to get and set values

         if SignalManager.GetSignalByName('Override').Value = 1 then

//If the test button on the NB2DSK01 is pressed, display related caption and set output signal
//to zero

         begin
                NB_Override.Caption := 'Hardware Override Engaged!';
                SignalManager.GetSignalByName('Data_Out[7..0]').Value := 0;
         end
         else if Panel_Override_Button.Down then

//If the Software Override button is pressed, display related caption and set output signal to
//zero

         begin
                Panel_Override.Caption := 'Software Override Engaged!';
                SignalManager.GetSignalByName('Data_Out[7..0]').Value := 0;
         end
         else

//In the absence of any overrides, set output to value currently defined for the control named
//Output_Data

         begin
                SignalManager.GetSignalByName('Data_Out[7..0]').Value := Output_Data.Value;
         end;
end;

//The following procedure is entered if the user clicks on the Software Override button

procedure TDesignedAreaPanel.Panel_Override_ButtonClick(Sender: TObject);
begin
         Panel_Override_Button.Down := not Panel_Override_Button.Down;
end;


You are reporting an issue with the following selected text and/or image within the active document: