Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: Cbyrdtopper on March 16, 2018, 03:34:23 PM
-
Once Mach4 Lathe is opened; I have a Dialogue Box that pops up asking the operator which tool in the turret is active.
We don't have any gang style tools so our offsets are straight forward. T101 T202 .... T606. What I need to do is go ahead and set the current offset active to whatever tool is active. How can I do this in the PLC Script.
I found this in the PLC Script: m_currentOffset = mc.mcCntlGetPoundVar(inst, mc.SV_CUR_LENGTH_INDEX)
I changed it to "SetPoundVar" and it did change the Active Offset Number that is on the screen. But it didn't update the current offset position like I thought it would.
I could probably call a tool change to T101 .... T606, but now I'm curious to see if I can do this in code.
-
This will work.
But I am still want to know if you are able to do this another way.
Here is the macro for proof of concept.
function m202()
local inst = mc.mcGetInstance()
local ActualTool = wx.wxGetNumberFromUser("What tool is in the turret?", "Tool # ","Current Tool", 1, 1, 6) -- Default, Min, Max.
local rc = ActualTool
if rc == -1 then
wx.wxMessageBox("Set the current tool to the actual tool.")
else
mc.mcToolSetCurrent(inst, ActualTool)
mc.mcCntlSetLastError(inst, "T" .. tostring(ActualTool) .. "0" .. tostring(ActualTool))
mc.mcCntlGcodeExecute(inst, "T" .. tostring(ActualTool) .. "0" .. tostring(ActualTool)) --This uses the Tool Number that was entered into the Dialogue Box and pieces together a T### Command real fast.
end
end --m202
if (mc.mcInEditor() == 1) then
m202()
end
-
So..
This works in a macro.
It doesn't work when it is run from the Screen Script.
I have this function in the Screen Load script. The PLC Script calls this function on its 25th run. It will Set the current tool and give me a message. But it does not run the GcodeExecute or the MDIExecute. I tried it with both.
-
It doesn't work because the machine is not enabled. I wonder if there is a way to capture the first instance the machine is enabled so it can run the SetCurrentToolFunction()
-
Anyone has any ideas about this?
-
Hi,
this pretty much sums up what I know about it:
http://www.machsupport.com/forum/index.php/topic,36855.0.html (http://www.machsupport.com/forum/index.php/topic,36855.0.html)
Could you use a signal and the testcount increment to determine when to run the script?
Craig
-
Hey Craig,
Just to let you know what I'm doing...
I'm having my PLC Script run my SetCurrentTool() function on the 25th run. This way the operator can tell Mach what tool is in the turret.
I need to activate the tool offset while I'm doing this.
I've used the OSIG_MACHINE_ENABLED output handle before.
.......................
While writing this post I thought of a possibility. I remember a register I can access.
There is a register counting how many times the Mach has been enabled and disabled. I can just grab the first instance of this in the PLC Script and run my Function.
Craig,
Do you know the command to get the core registers? I've only gotten Var# and Registers I've made.
-
Here is a screenshot of the register I can use.
-
Alrighty,
I've found a solution.
This snippet of code gets the core/inst register of CmdEnable count.
When it is "1" then it will run my SetCurrentTool() function and adds 1 to the CmdEnable register so it doesn't keep looping.
Here is the Screen Load Script and the PLC Script that I'm using to accomplish this task.
--Set Current Tool Screen Load Script.
function SetCurrentTool()
local inst = mc.mcGetInstance()
local ActualTool = wx.wxGetNumberFromUser("What tool is in the turret?", "Tool # ","Current Tool", 1, 1, 6) -- Default, Min, Max.
local rc = ActualTool
if rc == -1 then
wx.wxMessageBox("Set the current tool to the actual tool.")
else
mc.mcToolSetCurrent(inst, ActualTool)
mc.mcCntlSetLastError(inst, "T" .. tostring(ActualTool) .. "0" .. tostring(ActualTool))
mc.mcCntlGcodeExecute(inst, "T" .. tostring(ActualTool) .. "0" .. tostring(ActualTool)) --This uses the Tool Number that was entered into the Dialogue Box and pieces together a T### Command real fast.
end
end--SetCurrentTool()
--Set Current Tool PLC Script
local hReg = mc.mcRegGetHandle(inst, "core/inst/CmdEnable");
local EnableCount = mc.mcRegGetValue(hReg)
if EnableCount == 1 then
SetCurrentTool()
mc.mcRegSetValue(hReg, 2)
end