Create Background Operation

Last modified by writer on 2023/06/07 16:29

Attention!

Before starting work, make sure that the “Background operations” feature is active.

For many tasks of controlling the CNC system, it is necessary to run macros in the background, in which certain parameters of the system are monitored and the necessary actions are performed (for example, output control).

Macro code can be written in any text editor (standard Notepad, Notepad ++ and others). The list of functions in the API for developing background macros is given in the section "Functions for developing background macros". Please note that the set of available functions differs in the API of background macros and classic macros.

To create a background operation use the "Macros and Background Operations Manager" window: click the "Create" button and enter a name for the background operation. Go to edit mode (standard text editor window) to add code after the new background operation appears in the list. Select a background operation in the list and click the "Run" button to start it.

At startup, the PUMOTIX server starts executing each background macro in a separate thread. At the same time, a function is called inside the macro - a handler with an interval of 100 ms (the interval between calls to the handler may vary depending on certain conditions, use the GetSystemTickCount function to accurately measure elapsed time).

Background Macro Example
function handle()
local x = AxisGetMachinePos(Axis.X)

local new_state_0 = x < 0
local new_state_1 = x >= 0

if (PinGetState(Outputs.UserOutput_0) ~= new_state_0) then
  PinSetState(Outputs.UserOutput_0, new_state_0)
end

if (PinGetState(Outputs.UserOutput_1) ~= new_state_1) then
  PinSetState(Outputs.UserOutput_1, new_state_1)
end
end