1
Mach4 Toolbox / Lua coding for External Controls
« on: September 09, 2015, 08:21:08 AM »
Hi all,
This is the first post on the forum (so please go easy on me).
I am currently building an external control panel (Buttons and lots of wire) to link in with Mach4 and have a question or two about the coding.
Below is a copy of the code for the first 3 inputs I have placed in wxMach screen set under the Screen Loan Script.
As you can see I have placed display outputs in the code for debugging.
The output from the running code is as follows:
The layout of the output is
Button Number - Button Name - state
In total I will have 19 switches, 2 panel mount Joysticks and other stuff on the panel.
My current PC setup is listed below
The code I have written is working once it comes to rest BUT....
Questions,
1. Why dose M4 magically change "state" to true, yet no button has been pressed?
2. Why dose it loop 4 times before coming to rest?
3. What is the use of the ";" at the end of some lines?
Cheers and thanks for all the fish
Greg
PS. I have attached a full copy of the code and History files FYI
This is the first post on the forum (so please go easy on me).
I am currently building an external control panel (Buttons and lots of wire) to link in with Mach4 and have a question or two about the coding.
Below is a copy of the code for the first 3 inputs I have placed in wxMach screen set under the Screen Loan Script.
Code: [Select]
SigLib = {
-- Enable
[mc.OSIG_MACHINE_ENABLED] = function(state)
machEnabled = state
end,
-- Enable Button
[mc.ISIG_INPUT1] = function(state)
mc.mcCntlSetLastError(mc.mcGetInstance(), "1 - M4 Enable NOT YET - " .. state)
if (state == 1) then
local inst = mc.mcGetInstance()
local reg = mc.mcSignalGetHandle(inst, mc.OSIG_MACHINE_ENABLED)
machine_active = mc.mcSignalGetState(reg)
if (machine_active == 1) then
input_on_off = 0
mc.mcCntlSetLastError(inst, "1 - M4 Enable Pressed (OFF)")
else
input_on_off = 1
mc.mcCntlSetLastError(inst, "1 - M4 Enable Pressed (ON)")
end
mc.mcCntlEnable(inst, input_on_off)
end
end;
-- Cycle Start
[mc.ISIG_INPUT2] = function(state)
mc.mcCntlSetLastError(mc.mcGetInstance(), "2 - Cycle Start NOT YET - " .. state)
if (state == 1) then
local inst = mc.mcGetInstance()
mc.mcCntlSetLastError(inst, "2 - Cycle Start Pressed - " .. state)
mc.mcCntlCycleStart(inst)
end
end;
-- Feed Hold
[mc.ISIG_INPUT3] = function(state)
mc.mcCntlSetLastError(mc.mcGetInstance(), "3 - Feed Hold NOT YET - " .. state)
if (state == 1) then
local inst = mc.mcGetInstance()
mc.mcCntlSetLastError(inst, "3 - Feed Hold Pressed")
mc.mcCntlFeedHold(inst)
end
end;
As you can see I have placed display outputs in the code for debugging.
The output from the running code is as follows:
The layout of the output is
Button Number - Button Name - state
Code: [Select]
1 - M4 Enable NOT YET - 0
2 - Cycle Start NOT YET - 0
3 - Feed Hold NOT YET - 0
1 - M4 Enable NOT YET - 0
1 - M4 Enable NOT YET - 1
1 - M4 Enable Pressed (ON)
2 - Cycle Start NOT YET - 0
2 - Cycle Start NOT YET - 1
2 - Cycle Start Pressed - 1
3 - Feed Hold NOT YET - 0
3 - Feed Hold NOT YET - 1
3 - Feed Hold Pressed
1 - M4 Enable NOT YET - 0
2 - Cycle Start NOT YET - 0
3 - Feed Hold NOT YET - 0
In total I will have 19 switches, 2 panel mount Joysticks and other stuff on the panel.
My current PC setup is listed below
- Intel Pentium4 dual 3.00Ghz CPU
1.0Gb RAM
64 Bit Windows 7
On board video (will be upgrading)
Mach4 Ver. 4.2.0.2673
Build 2673
PoKeys 57U (upgraded 56U) as my interface to the control panel (with the latest plugin)
The code I have written is working once it comes to rest BUT....
Questions,
1. Why dose M4 magically change "state" to true, yet no button has been pressed?
2. Why dose it loop 4 times before coming to rest?
3. What is the use of the ";" at the end of some lines?
Cheers and thanks for all the fish
Greg
PS. I have attached a full copy of the code and History files FYI