Hi,
open Configure/Plugins/ESS and on the Pins Config page give the input pin, port1,pin10 for example, used for the button of interest a suitable alias, and maybe an active low status.
While still within the ESS configuration screen open the Input Signals page and scroll down and enable one of the general purpose inputs Input10 say, and attach the pin alias
you have allocated to that button. Hit <apply> so that the changes are save to the .ini file.
You can then enter some code into the SigLib table at the top of the Screen Load script, if you follow this example:
[mc.ISIG_INPUT10]=function(state)
if (state=1) then
CycleStart()
end
end
It may not be clear how this simple statement can effect what you wish.
In Mach3 the program would occasionally, every 25ms or so, interrogate all its input signals to see if any had activated. This is called polling. Its not very efficient, it checks each input in turn whether it needs
it or not and then waits for a long time before it checks it again. Mach4 is much better. Whenever ANY signal, input or output changes state it runs the signal script. It doesn't wait until some sampling time
it acts as soon as a signal changes. If for instance one of Machs internal signals changes, say AXIS0_STOPPED the the signal script will run. We are not interested in this signal so we don't act on it. If however
ISIG_INPUT10 changes we are interested in doing something. This is how Mach goes about it:
It runs the Signal Script as per usual and the standard script is:
if SigLib[sig] ~= nil then
SigLib[sig](state);
end
I know....so simple ...how can such a simple three lines do anything useful?
All Mach knows at this point is that signal number <sig> has changed to <state>.
What happens is that Mach looks into the SigLib table, a Lua data structure to see if there is an entry in the table that matches <sig>. In our case there is in the form of ISIG_INPUT10.
Given that the test is affirmative Mach now executes the function associated with that entry and passes the variable <state> to the function. Mach now executes the function if <state>=1,
which in our case is yet another function called CycleStart() which is already in the screen load script.
This is an example of two important principles and concepts in Lua. The first is the table. Lua has ONLY one data structure, the table. The individual elements of the table may be arranged
in numerical order 1,2,3 etc. like we would an array in more familiar computer languages, but they can also be named out of order with positive AND negative arguments OR with STRING
arguments. Thus we could have a table:
MyFictiousTableInLua {
[1]='my first entry'
[2]='my second entry'
[2.345]= 'my third entry but note the real as opposed integer argument, perfectly legal in Lua'
[ARG4]='my fourth entry but with a string argument, again perfectly legal in Lua, even a mixed one like this'
[5] = function('it is also legal to have numbers , strings, functions and even a whole other table as an entry')
}
This is just an example of how flexible tables can be in Lua. As often happens in Lua what appears to be a very simple idea has remarkable flexibility and can
convey properties and possibilities well beyond what the simple idea would indicate.
The second principle is a 'function as a first class value'. Thus you can see the last entry in my nonsense example table is a function whereas all the previous entries were
numbers or strings. A function can be treated just as another number...very simple and clever and allows Lua to perform great feats of computing despite being such a simple
language.
The upshot is that SigLib, a simple table in Lua, is in fact a table that contains functions, one function for each of the signals that we are interested in. Very clever, simple,
elegant and very lean computationally.
Lua is a real eye opener, I thought NFS had made a mistake when I first started to use it but these deceptively simple ideas mean that Lua is very powerful indeed. I
have very much changed my mind. C/C++ can do just about anything but is tightly typed and you have to manage your own memory. Lua is almost type free and
memory management is automatic such a boon to Mach4
When coding I have this link open pretty much permanently:
https://www.lua.org/manual/5.2/Craig