Global Array

SetGlobalArrayFloat('demo.global.array', i, LocalArrayOut.asArray(i));
GlobalArrayIn.asArray(i, GetGlobalArrayFloat('demo.global.array', i));
Procedure Description
function GetGlobalArraySize(name: string): integer; Get the size (number of elements) of a global array
function GetGlobalArrayFloat(name: string; index: integer): single; Get the float value of a global array element at the given index
procedure SetGlobalArrayFloat(name: string; index: integer; v: single); Set the float value of a global array element at the given index
////////////////////////////////////////////////////////////////////////////////
// Global Array Demo - showcases how to populate and read Usine global arrays.
// Press "write array" to push local values to the global store, then use
// "read array" to inspect the global array contents.
////////////////////////////////////////////////////////////////////////////////

const GLOBAL_ARRAY_NAME = 'demo.global.array';
const LOCAL_SIZE = 8;

var
  WriteBtn      : TParameter;
  ReadBtn       : TParameter;
  LocalArrayOut : TParameter;
  GlobalArrayIn : TParameter;
  InfoText      : TParameter;

procedure PushLocalToGlobal;
var
  i: integer;
begin
  for i := 0 to LOCAL_SIZE - 1 do
    SetGlobalArrayFloat(GLOBAL_ARRAY_NAME, i, LocalArrayOut.asArray(i));

  InfoText.asString('Wrote ' + IntToStr(LOCAL_SIZE) + ' elements to "' + GLOBAL_ARRAY_NAME + '".');
end;

procedure PullGlobalToLocal;
var
  globalSize: integer;
  i: integer;
  value: single;
begin
  globalSize := GetGlobalArraySize(GLOBAL_ARRAY_NAME);
  GlobalArrayIn.Length(globalSize);
  for i := 0 to globalSize - 1 do
  begin
    value := GetGlobalArrayFloat(GLOBAL_ARRAY_NAME, i);
    GlobalArrayIn.asArray(i, value);
  end;

  InfoText.asString('Loaded global array "' + GLOBAL_ARRAY_NAME + '" size=' + IntToStr(globalSize) + '.');
end;

procedure Init;
var
  i: integer;
begin
  ModuleColor($FF455A64);

  WriteBtn      := CreateParam('write array', ptButton, pioInput);
  ReadBtn       := CreateParam('read array',  ptButton, pioInput);
  LocalArrayOut := CreateParam('local array', ptArray,  pioInput);
  GlobalArrayIn := CreateParam('global array',ptArray,  pioOutput);
  InfoText      := CreateParam('info',        ptTextField, pioOutput);

  LocalArrayOut.Length(LOCAL_SIZE);
  GlobalArrayIn.Length(0);
  for i := 0 to LOCAL_SIZE - 1 do
    LocalArrayOut.asArray(i, i * 0.1);  // seed local array with simple ramp values

  InfoText.asString('Use "write array" to push the local ramp into the global array.');
end;

procedure Callback(N: integer);
begin
  if N = WriteBtn then
    PushLocalToGlobal;

  if N = ReadBtn then
    PullGlobalToLocal;
end;

GetGlobalArraySize

function GetGlobalArraySize(name: string): integer;

Returns the length of a named global array.

size := GetGlobalArraySize('spectrum');

GetGlobalArrayFloat

function GetGlobalArrayFloat(name: string; index: integer): single;

Reads a value from a global array at a given index.

energy := GetGlobalArrayFloat('spectrum', bin);

SetGlobalArrayFloat

procedure SetGlobalArrayFloat(name: string; index: integer; v: single);

Set a value to a global array at a given index.

SetGlobalArrayFloat('spectrum', bin, analyzerBuffer[bin]);

more about scripts

version 7.0.250121

Edit All Pages