Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: dibor on December 26, 2024, 04:21:39 PM
-
Hello to ALL.
I'd like to engage some pin of motion controller only while probing process.
How can I do this?
Script, LUA ??
Thank U
-
Scripting. Place probeon.lua and probeoff.lua files in the Mach profile's macro directory. They are just like M code scripts. Meaning the file name and the function name inside them need to match. Case matters. Make the names all lower case for zero confusion.
in probeon.lua:
function probeon(probenumber)
-- script any signal or I/O functions here.
end function
in probeoff.lua:
function probeoff(probenumber)
-- script any signal or I/O functions here.
end function
Steve
-
Thank a lot Steve.
Will try this way :)
These functions will be usable for the "Touch" process?
Best Wishes.
-
Doesn't work :(
function probeon(G31)
local inst = mc.mcGetInstance()
mc.mcCntlSetPokeysOutput(inst, 45, 1)
end
Do not understand :(
-
This code also doesn't work :(
function probeon(G31)
local inst = mc.mcGetInstance()
local hSig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT45)
mc.mcSignalSetState(hSig, 1)
end
Anybody can kick me to the right direction? ;D
-
Hello to ALL.
I see nobody has anything to say :(
So, after head crash and putting out some part of the hair and taking chat GPT for assistant I got working script.
Have save it as M101.mcs
I have use SMART.MER/2 – signal merger with probe guard function by topcom, he is able to generate ESTOP signal, when connected probe is triggered in the
unexpected moment. It can protect a probe from damage.
This board has inputs that blocks guard function, so I need to provide high level from motion controller while probing process.
Here my script, maybe will useful for somebody else :)
local inst = mc.mcGetInstance() -- Get the Mach4 instance
local outputSig = mc.OSIG_OUTPUT45 -- Define OUTPUT45 signal
local prevState = -1 -- Variable to store the previous state
-- Function to check probing state and control OUTPUT45
function CheckProbingState()
local state = mc.mcCntlGetState(inst) -- Get the current system state
-- Check if the state has changed
if state ~= prevState then
mc.mcCntlSetLastError(inst, "Current State Changed: " .. tostring(state)) -- Log state change
-- Get the handle for OUTPUT45 signal
local hSig = mc.mcSignalGetHandle(inst, outputSig)
if state == 202 then
mc.mcSignalSetState(hSig, 1)
mc.mcCntlSetLastError(inst, "PoKeys57CNC: Probing Active, OUTPUT45 ON!")
else
mc.mcSignalSetState(hSig, 0)
mc.mcCntlSetLastError(inst, "PoKeys57CNC: Probing Completed, OUTPUT45 OFF!")
end
-- Update the previous state
prevState = state
end
end
-- Timer checks state but only updates OUTPUT45 on change
wxTimer = wx.wxTimer()
wxTimer:Start(100, wx.wxTIMER_CONTINUOUS)
wxTimer:Connect(wx.wxEVT_TIMER, function(event)
CheckProbingState()
end)
• OUTPUT45 turns on only when probing starts (state == 202).
• OUTPUT45 turns off when probing stops.
• The signal only changes when the state actually changes.
Best Wishes.
-
Hi to ALL.
Possible to run as PLC script:
if not inst then inst = mc.mcGetInstance() end
if not outputSig then outputSig = mc.OSIG_OUTPUT45 end
if not prevState then prevState = -1 end
function CheckProbingState()
local state = mc.mcCntlGetState(inst)
if state ~= prevState then
mc.mcCntlSetLastError(inst, "State: " .. tostring(state))
local hSig = mc.mcSignalGetHandle(inst, outputSig)
if hSig ~= 0 then
if state == 202 then
mc.mcSignalSetState(hSig, 1)
mc.mcCntlSetLastError(inst, "PoKeys57CNC: Probing Active, OUTPUT45 ON!")
elseif prevState == 202 then
mc.mcSignalSetState(hSig, 0)
mc.mcCntlSetLastError(inst, "PoKeys57CNC: Probing Completed, OUTPUT45 OFF!")
end
end
prevState = state
end
end
CheckProbingState()
All the best to ALL
-
Script is WORK!
Here small video: https://www.youtube.com/shorts/a8wUrA06kIQ (https://www.youtube.com/shorts/a8wUrA06kIQ)