% example marking task
clear all;
close all;

% load the required DLLs
try
	asmpath = '<Image Folder>\ClientLib\';
    dllImport = NET.addAssembly(fullfile(asmpath,'\RAYLASE\RAYLASE.SPICE3.dll'));
    dllImport = NET.addAssembly(fullfile(asmpath,'\RAYLASE\RAYLASE.SPICE3.Utils.dll'));
    dllImport = NET.addAssembly(fullfile(asmpath,'\RAYLASE\RAYLASE.SPICE3.ClientLib.dll'));
catch ex
    ex.ExceptionObject.LoaderExceptions.Get(0).Message;
    rethrow(ex);
end

% SP-ICE-3 card's IP address - please change to your card's IP address
ipAddress = '169.254.0.254';

% obtain a 'ClientAPI' instance and connect to card
client = RAYLASE.SPICE3.ClientLib.ClientAPI(ipAddress);

% query the scanner's current field size
sizeX = client.Scanner.GetConfig().FieldSize.X;
sizeY = client.Scanner.GetConfig().FieldSize.Y;

% calculate the square's coordinates based on the field size
maxX =  0.5*sizeX;
maxY =  0.5*sizeY;
minX = -0.5*sizeX;
minY = -0.5*sizeY;

% define jump and mark speed
jumpSpeed = 1;
markSpeed = 1;

% create a list, which will mark the square then jump back to the center
listID = 10;
list = RAYLASE.SPICE3.ClientLib.CommandList();

list.AppendJumpSpeed(jumpSpeed);
list.AppendMarkSpeed(markSpeed);
list.AppendJumpAbs( minX, minY );
list.AppendMarkAbs( maxX, minY );
list.AppendMarkAbs( maxX, maxY );
list.AppendMarkAbs( minX, maxY );
list.AppendMarkAbs( minX, minY );
list.AppendJumpAbs( 0, 0 );

% send this list to the card and execute the list
client.List.Set(listID, list);
client.List.Execute(listID);

% calculate an appropriate timeout value (adds 2000ms fudge factor) and wait for the completion of the list
timeoutMs = 1e-3*(((2*(maxX-minX)) + (2*(maxY-minY)))/markSpeed) + 2000;
if ( ~client.List.WaitForListDone(timeoutMs))
    disp("Timed out waiting for ListDone." );
end

% finally disconnect from card
client.Disconnect();
