Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: lcs226 on April 22, 2019, 10:16:13 PM

Title: Switching tabs
Post by: lcs226 on April 22, 2019, 10:16:13 PM
How can you switch between G CODE tab and MDI tab on screen with use of an input?

Thanks.
Title: Re: Switching tabs
Post by: joeaverage on April 23, 2019, 05:40:13 AM
Hi,
I haven't tried so I don't know.

This is how I would go about it:
If you open the screen editor and look at the 'On Enter' event script for the MDI tab, it is but one line:

Code: [Select]
scr.SetProperty('btnCycleStart', 'Label', 'Cycle Start\nMDI');

What I propose is that you connect a physical button to your controller, connect that input to a spare Mach input signal,
ISIG_INPUT5, say, and when that signal activates run the line of code above. For this purpose you would
make an additional entry in the SigLib table. Are you familiar with the SigLib table and how it works? If not this may help:

https://www.machsupport.com/forum/index.php?topic=40051.msg267764#msg267764 (https://www.machsupport.com/forum/index.php?topic=40051.msg267764#msg267764)

Let us know if you need more help.

Craig

Title: Re: Switching tabs
Post by: jbuehn on April 23, 2019, 11:49:10 AM
I've never tried it using an input to trigger the tab change, but in the screen editor the notebook containing those tabs has a property called "Current Tab"...that will work to swap tabs using the scr.SetProperty screen API call Craig listed above. It should call the On Enter and On Exit scripts doing it that way too.
Title: Re: Switching tabs
Post by: lcs226 on April 27, 2019, 06:40:51 PM
Thanks for the reply, but unfortunately not much help as I am new to Mach4 and I am still trying to get my head around its programming structure and syntax. Any help in expounding on the correct procedure would be helpful in accomplishing the task.

I am trying to switch from GCode to MDI and back via push button signals from my PLC

Thanks.
Title: Re: Switching tabs
Post by: joeaverage on April 28, 2019, 01:43:20 AM
Hi,
have you read the SignalScrpit.pdf file that I linked you to?

Craig
Title: Re: Switching tabs
Post by: SwiftyJ on April 28, 2019, 06:53:02 AM
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.

Code: [Select]
---------------------------------------------------------------
-- 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.
Code: [Select]
scr.SetProperty("nbGCodeMDI1", )Then we enter the name of the property we want to change as a string
Code: [Select]
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.
Code: [Select]
scr.SetProperty("nbGCodeMDI1", "Current Tab", "1" )
Now combine the two things above,

Code: [Select]

[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,