Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: rhtuttle on January 13, 2018, 03:30:45 PM
-
Just when I think i am starting to understand lua I run into this. The code below is a macro that I have used many times and today I wanted to alter it a bit. When the changes didn't do what I thought it should i started putting in wxMessagBox calls in to see where it was failing. When the first message box didn't pop up I was surprised, but even more surprised that the macro continued to execute including the second popup telling me to switch gearing. What am I missing? I deleted the .mcc and .mcs.bak several times and completely restarted windows with the same results. I am at a total loss on this one.
function m6691(hVars)
local xNow,zNow,maxVal,rc
local ts,tr,te,sCode
local currPos
local plungeFeed=1
local roughDOC=0.018
local roughFeed=18
local roughSpeed=1200
local finishDOC=0.004
local finishFeed=8
local finishSpeed=1800
local endX=.850 --param1()
local inst=mc.mcGetInstance()
wx.wxMessageBox('nil') --HOW IS THIS SKIPPED?
if mc.mcSpindleGetCurrentRange(inst)~=1 then
--rt.rtAudio("notify")
--wx.wxSound('C:\\mach4Hobby\\Sounds\\Notify.wav',0):Play()
wx.wxMessageBox('Set Spindle Gearing to High Speed') --THIS ONE DOES GET EXECUTED!!!
mc.mcSpindleSetRange(inst,1)
end
if (hVars ~= nil) then
local DFlag = mc.mcCntlGetLocalVarFlag(inst, hVars, mc.SV_D)
if(DFlag == 1) then
endX = mc.mcCntlGetLocalVar(inst, hVars, mc.SV_D)
mc.mcCntlSetLastError(inst,"Turning Diameter to "..endX)
end
end
xNow,rc = mc.mcAxisGetPos(inst,0)
zNow,rc = mc.mcAxisGetPos(inst,2)
if xNow<=endX then
rt.rtAudio("chord")
wx.wxMessageBox("start X diameter "..xNow.." is <= to end diameter of "..tostring(endX))
return
end
if zNow<=0 then
rt.rtAudio("chord")
wx.wxMessageBox("start Z is less than or = to 0")
return
end
ts=os.time()
--rough cuts
mc.mcCntlGcodeExecuteWait(inst,"M3 S"..tostring(roughSpeed).."\ng04 p3.0")
currPos,rc=mc.mcAxisGetPos(inst,0)
while ((currPos-2*roughDOC)>(endX+finishDOC*2)) do
maxVal=math.max(endX+2*finishDOC,currPos-roughDOC)
sCode="G01 F"..tostring(plungeFeed).." X"..tostring(maxVal-roughDOC)
mc.mcCntlGcodeExecuteWait(inst,sCode)
currPos,rc=mc.mcAxisGetPos(inst,0)
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(roughFeed).." Z0")
if mc.mcSpindleGetSensorRPM(inst)==0 then
rt.rtAudio("chord")
wx.wxMessageBox("Spindle Stopped")
return
end
currPos,rc=mc.mcAxisGetPos(inst,0)
maxVal=math.max(endX+2*finishDOC,currPos-roughDOC)
if currPos==endX+2*finishDOC then
break
end
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(plungeFeed).." X"..tostring(math.max(endX+2*finishDOC,currPos-roughDOC)))
if mc.mcSpindleGetSensorRPM(inst)==0 then
rt.rtAudio("chord")
wx.wxMessageBox("Spindle Stopped")
return
end
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(roughFeed).." Z"..tostring(zNow))
if (currPos)==endX+2*finishDOC then
break
end
end
tr=os.difftime(os.time(),ts)/60
mc.mcCntlSetLastError(inst,"Roughing Time: "..string.format("%.1f min",tr))
--finish cuts
mc.mcCntlGcodeExecuteWait(inst,"M3 S"..tostring(finishSpeed))
while (mc.mcAxisGetPos(inst,0)>=(endX+finishDOC)) do
currPos,rc=mc.mcAxisGetPos(inst,0)
maxVal=math.max(endX,currPos-finishDOC)
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(plungeFeed).." X"..tostring(maxVal))
if mc.mcSpindleGetSensorRPM(inst)==0 then
rt.rtAudio("chord")
wx.wxMessageBox("Spindle Stopped")
return
end
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(finishFeed).." Z0")
currPos,rc=mc.mcAxisGetPos(inst,0)
if currPos==endX then
break
end
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(plungeFeed).." X"..tostring(endX))
if mc.mcSpindleGetSensorRPM(inst)==0 then
rt.rtAudio("chord")
wx.wxMessageBox("Spindle Stopped")
return
end
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(finishFeed).." Z"..tostring(zNow))
currPos,rc=mc.mcAxisGetPos(inst,0)
if currPos==endX then
break
end
end
mc.mcCntlGcodeExecuteWait(inst,"M5\nM9")
te=(os.time()-ts)/60
mc.mcCntlSetLastError(inst,"Roughing Time: "..string.format("%.1f min",tr).." - Total Time: "..string.format("%.1f min",te))
end
if mc.mcInEditor()==1 then
m6691()
end
TIA
RT
-
Update:
Decided to give up figuring this out for now so I just deleted the wxMessagebox.
THEN, I changed the finishSpeed and finishFeed to be the same as the roughing feed and speed. Saved it and ran it from the MDI: m6691. It ran with the old speed and feed for the finish cycle. Deleted the m6691.mcc and ran it again. Same result. Shut windows down and unplugged the pmdx411, restarted windows and plugged the pmdx back in. Deleted the mcc again and went into the editor checked to make sure that the finish numbers were the same as the roughing and they were, hit compile and the mcc was created again. Ran it but it still ran the finish cycle with the old numbers!!!
I have searched the computer for any old copies of the mcc file and deleted those in a backup directory along with the mcs and removed them from dropbox as well. How is it that it is running a file that no longer exists?
TIA
RT
-
Further update:
copied and saved the m6691.mcs as m7791.mcs
ran m7791 from the mdi and nothing happened.
deleted the m6691.mcc and moved the m6691.mcs to another directory. ran m6691 from the mdi and nothing happened.
copied the m6691.mcs back to the macros directory and ran m6691 from the mdi and it created the new m6691.mcc but still ran with the old finish numbers.
Any ideas?
RT
-
Did you also delete the lua.mcc file? Anytime you update marcos I would close Mach, delete all .mcc and .bak files in the macros directory. Relaunch Mach and test.
-
I did not find a lua.mcc on my machine but I did find a mcLua.mcc. I deleted it, after shutting down m4, and the result was the same. I then deleted all mcc and bak files and restarted m4, the result was the same.
I have searched the computer for any files of m6691* and found only the mcs and new mcc created on reload. I have changed the feeds and speeds in the m6691 script and can confidently state that the file is not being run. It's as if m4 has retained a compiled version somewhere else. I am totally baffled on this one.
-
Just had a quick look at code, are you using the load modules.mcs?? as there is a bit of code looking for a table at line 34 "rt.rtAudio("chord")"
DazTheGas
-
Hi Daz,
Yes I am using it. I have another macro, m6000 that calls one of the functions and it works,
function m6000()
rt = require 'rtMyModule'
if rt== nil then
wx.wxMessageBox('rt==nil')
return
end
local subj='Lathe'
local msg='test m6000'
rt.sendSMS(subj,msg)
end
if mc.mcInEditor()==1 then
m6000()
end
So it seems that rtMyModule located in the profile's 'modules' directory is successfully compiled and loaded by this macro.
Does this help narrow down the problem?
-
Had to go blow some snow for the last hour, going to get to below 0 f here later.
Here now is the sum total of the m6691.mcs. Deleted all bak and mcc in the macro folder and then started m4.
function m6691(hVars)
wx.wxMessageBox('hello')
--[[
local rt = require 'rtMyModule'
if rt== nil then
wx.wxMessageBox('rt==nil')
return
end
local xNow,zNow,maxVal,rc
local ts,tr,te,sCode
local currPos
local plungeFeed=1
local roughDOC=0.018
local roughFeed=18
local roughSpeed=800
local finishDOC=0.018
local finishFeed=18
local finishSpeed=800
local endX=.850 --param1()
local inst=mc.mcGetInstance()
if mc.mcSpindleGetCurrentRange(inst)~=1 then
--rt.rtAudio("notify")
--wx.wxSound('C:\\mach4Hobby\\Sounds\\Notify.wav',0):Play()
wx.wxMessageBox('Set Spindle Gearing to High Speed')
mc.mcSpindleSetRange(inst,1)
end
if (hVars ~= nil) then
local DFlag = mc.mcCntlGetLocalVarFlag(inst, hVars, mc.SV_D)
if(DFlag == 1) then
endX = mc.mcCntlGetLocalVar(inst, hVars, mc.SV_D)
mc.mcCntlSetLastError(inst,"Turning Diameter to "..endX)
end
end
xNow,rc = mc.mcAxisGetPos(inst,0)
zNow,rc = mc.mcAxisGetPos(inst,2)
if xNow<=endX then
rt.rtAudio("chord")
wx.wxMessageBox("start X diameter "..xNow.." is <= to end diameter of "..tostring(endX))
return
end
if zNow<=0 then
rt.rtAudio("chord")
wx.wxMessageBox("start Z is less than or = to 0")
return
end
ts=os.time()
--rough cuts
mc.mcCntlGcodeExecuteWait(inst,"M3 S"..tostring(roughSpeed).."\ng04 p3.0")
currPos,rc=mc.mcAxisGetPos(inst,0)
while ((currPos-2*roughDOC)>(endX+finishDOC*2)) do
maxVal=math.max(endX+2*finishDOC,currPos-roughDOC)
sCode="G01 F"..tostring(plungeFeed).." X"..tostring(maxVal-roughDOC)
mc.mcCntlGcodeExecuteWait(inst,sCode)
currPos,rc=mc.mcAxisGetPos(inst,0)
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(roughFeed).." Z0")
if mc.mcSpindleGetSensorRPM(inst)==0 then
rt.rtAudio("chord")
wx.wxMessageBox("Spindle Stopped")
return
end
currPos,rc=mc.mcAxisGetPos(inst,0)
maxVal=math.max(endX+2*finishDOC,currPos-roughDOC)
if currPos==endX+2*finishDOC then
break
end
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(plungeFeed).." X"..tostring(math.max(endX+2*finishDOC,currPos-roughDOC)))
if mc.mcSpindleGetSensorRPM(inst)==0 then
rt.rtAudio("chord")
wx.wxMessageBox("Spindle Stopped")
return
end
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(roughFeed).." Z"..tostring(zNow))
if (currPos)==endX+2*finishDOC then
break
end
end
tr=os.difftime(os.time(),ts)/60
mc.mcCntlSetLastError(inst,"Roughing Time: "..string.format("%.1f min",tr))
--finish cuts
mc.mcCntlGcodeExecuteWait(inst,"M3 S"..tostring(finishSpeed))
while (mc.mcAxisGetPos(inst,0)>=(endX+finishDOC)) do
currPos,rc=mc.mcAxisGetPos(inst,0)
maxVal=math.max(endX,currPos-finishDOC)
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(plungeFeed).." X"..tostring(maxVal))
if mc.mcSpindleGetSensorRPM(inst)==0 then
rt.rtAudio("chord")
wx.wxMessageBox("Spindle Stopped")
return
end
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(finishFeed).." Z0")
currPos,rc=mc.mcAxisGetPos(inst,0)
if currPos==endX then
break
end
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(plungeFeed).." X"..tostring(endX))
if mc.mcSpindleGetSensorRPM(inst)==0 then
rt.rtAudio("chord")
wx.wxMessageBox("Spindle Stopped")
return
end
mc.mcCntlGcodeExecuteWait(inst,"G01 F"..tostring(finishFeed).." Z"..tostring(zNow))
currPos,rc=mc.mcAxisGetPos(inst,0)
if currPos==endX then
break
end
end
mc.mcCntlGcodeExecuteWait(inst,"M5\nM9")
te=(os.time()-ts)/60
mc.mcCntlSetLastError(inst,"Roughing Time: "..string.format("%.1f min",tr).." - Total Time: "..string.format("%.1f min",te))
local subj='Lathe'
local msg='Roughing Complete'
rt.sendSMS(subj,msg)
--]]
end
if mc.mcInEditor()==1 then
m6691()
end
Guess what, it still ran the old macro code that doesn't exist!!!
-
I may have an answer for you. I just figured out a similar problem I had on my computer. I had named a file "write_test" or something, but inside that file I had an old macro function name (M91050) that I forgot to delete, and it screwed everything up until I happened to find it. Go through all your lua files and look for an m6691 somewhere.
Fingers crossed.
-
dbt3000files,
I thought you were on to something so I checked my macros directory and I had saved a copy of m6691.mcs as test.mcs. So I changed it to test.sav so it wouldn't get compiled and deleted all mcc and bak files and fired up mach.
Ran m6691 in the mdi and same old s..t!! Drat.
I have a ticket in with MFS and James has been able to duplicate it with my package so hopefully they will find where I screwed up.
-
ALL of the files in the marcos directory get compiled. Get rid of any file in that directory with a m6691() function. Move then into a "save" child directory or something.
Steve
-
Exited mach, removed the 'test.sav' which had the m6691() defined, deleted all mcc and bak files and started mach4, ran m6691 in the mdi and still same result.
-
There is a file in that directory with m6691() defined, trust me. :)
You can open the mcLua.mcc file with an editor and search on m6691 and it will be in there. How did it get there? Some source file had it in there!
If you delete all of the mcc files, this should rebuild mcLua.mcc from scratch (from the source files) the first time Cycle Start is pressed. Then search the mcLua.mcc and see if m6691 is in there. If it is, then some source file is causing it to appear, guaranteed. Nothing else will insert that function into the mcLua.mcc. That directory is the whole playground and nothing else is cached anywhere.
You can verify this by creating a new profile. Not a copy of this profile, but a new one. Then check its' mcLua.mcc and there will be no reference to m6691 at all in it.
Steve
-
Steve,
I totally believe you.
Attached is the actual file m6691.mcs as it stands now.
When I remove this from the macros directory, delete all mcs and bak files, load mach and run m6691 from the mdi, nothing happens as expected.
Copy the m6691.mcs back into the macros directory, go into the operator->edit/debug scripts and select m6691.mcs the file opens, F7 to compile, save, close, run m6691 from the mdi... and... the spindle starts, the x moves in and then travels the Z just as in the code from my first entry here.
I know it is not possible... but it is happening.
RT
-
Ok, try this... save all of the files in the macro directory to another directory for safe keeping. Then put that slimmed down version of m6691.mcs in there. It should be the only file in the macros directory. No mcLua.mcc or anything else. Then launch Mach and do a do nothing command, such as G91 X0, and press cycle start. At this point, you should have three files in the profile's macro directory; m6691.mcs, m6691.mcc, and mcLua.mcc. Then MDI the m6691 and see what you get.
Steve
-
As usual you are correct ::)
Adding back one macro at a time I found one m7791 that had the m6691 defined in it. Right about now I wish I had remembered about those utilities to scan all files for a string. That probably should have been one of the first attacks. Guess I need to brush up on my ms-dos skills again.
Thank you for your patience Steve.
RT
-
I glad you got it solved. Now it is onward and upward!
I use a file manager called Servant Salamander. It is a Norton Commander clone for Windows and it has a recursive search for strings in files. A really nice tool.
Steve