If you want something to happen when the state of an output or input changes, the Signal Library is the place to do it. The signal library already exists in the default Mach4 Screen Load Script.
---------------------------------------------------------------
-- Signal Library
---------------------------------------------------------------
SigLib = { --<Start of signal library
[mc.ISIG_INPUT0] = function (state)
--Code here executes when Input 0 changes state, either high to low, or low to high
--We can check the state of the input/output by using the 'state' variable that is passed into the function.
if (state == 1) then
--Do something when Input 0 is active
end
end, -- Don't forget to put a comma here.
} --<End of signal library
Any Mach4 inputs or outputs can be added to the signal library in the same format as above, just change the input/output name in the square brackets.
For changing the properties of screen controls there is the scr.SetProperty API call. The tab control has a 'Current Tab' property which we can use to change the tab that is shown.
First we get the name of the control from the Screen Tree Manager, in this case it's "nbGCodeMDI1". See the attachment for info on where to get this.
scr.SetProperty("nbGCodeMDI1", )
Then we enter the name of the property we want to change as a string
scr.SetProperty("nbGCodeMDI1", "Current Tab", )
Finally, the value we want to change it to. For the Current Tab property, the value of the first tab is "0", second tab is "1" etc.
scr.SetProperty("nbGCodeMDI1", "Current Tab", "1" )
Now combine the two things above,
[mc.ISIG_INPUT0] = function (state)
if (state == 1) then
--Change to MDI tab when Input 0 is high.
scr.SetProperty("nbGCodeMDI1", "Current Tab", "1" )
else
--Change to GCode tab when Input 0 is low.
scr.SetProperty("nbGCodeMDI1", "Current Tab", "0" )
end
end,