Hello Guest it is March 28, 2024, 03:20:45 PM

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - smurph

201
Mach4 General Discussion / Re: ShuttlePro Losing Setup
« on: March 29, 2021, 01:16:16 PM »
Yeah, this caught me too.  At first, I just thought it was a problem with my profile.  But I was able to reproduce losing the configuration.  It is fixed it in build 4700.

Steve

202
Mach4 General Discussion / Re: How to Exit Screen Script
« on: March 25, 2021, 03:49:30 AM »
Script instructions continued to execute after the return?  The return keyword has never failed me.  How about posting the entire button script.  We will find the answer. 

Steve

203
Mach4 General Discussion / Re: How to Exit Screen Script
« on: March 24, 2021, 01:47:57 PM »
Yes, return.  All lower case. 

if (condition == true) then
    return
end

It is a dry read, but the LUA manual may be of some use to you.  https://www.lua.org/manual/5.3/

Steve

204
Mach4 Toolbox / Re: Clear history with a screen button
« on: March 24, 2021, 01:40:54 AM »
Unfortunately that is a GUI function and it is not an API call. 

Sorry for the late reply.  But this kind of stuff really needs to be in the Mach 4 General discussion instead of the ToolBox to get seen. 

Steve

205
Mach4 Toolbox / Re: not drilling
« on: March 24, 2021, 01:34:43 AM »
Look at your status history and see if it says anything about capping at a minimum Z level.  If so, with mach closed, adjust parameter 1801 to suit (parameters.ini in Profile directory).

Steve

206
Mach4 General Discussion / Re: How to Exit Screen Script
« on: March 24, 2021, 01:30:56 AM »
Not sure I know what you mean with #1.  Are you talking about a conditional cycle stop? 

But #2 is that the button press is a GUI event.  And the GUI cannot be updated while it is processing a GUI event.  It is the same thread of execution. 

So you have to get creative.  Maybe have a global screen script variable (defined in the screen load script), a string variable that will contain your message.  Than an addition to the PLC script that watches the string variable to become non empty and when so, , uses the string variable in a call to mcCntlSetLastError() and then finally sets the string variable to empty.

screen load script:
Code: [Select]
myMessageVar = ""

PLC script
Code: [Select]
if (myMessageVar ~= "") then
    local inst = mc.GetInstance()
    mcCntlSetLastError(inst, myMessageVar);
    myMessageVar = ""
end

Button script:
Code: [Select]
myMessageVar = "Display this now!!!"

Steve

207
I have put a LOT of love into Lathe.  Maybe not enough.  But at least it has a proper lathe interpreter.  So that was some love there.  :)  I made it do 1 line or 2 line Fanuc G76 formats.  I figured it would be EASY to get a decent post processor vs. Mach 3. 

I do wish Lathe would get more use.  I will finish my lathe conversion one day.  I have been working on it for nearly ten years though!  So it keeps getting shuffled to the back burner.  That would get me more fluent with CNC Lathe operation in general.  But they use it every day at the shop.  So I thought Lathe was pretty flushed out now. 

Send me a list of stuff that is lacking and I will try and educate myself. 

Steve

208
Ahh...  lathe.  :) 

This is what I mean by error checking.  It is verbose and wordy with lots of IF statements.  But with good error checking, there will be no mysteries if something goes wrong.  It will help you 1, 2 or 3 years from now when you are troubleshooting something when a rodent eats through a switch wire, etc...  LOL 

Ideally, you should check the return code of every API call that is critical to the success of the script at hand. 

Code: [Select]
function myHomeC()
local inst=mc.mcGetInstance('myHomeC()') -- this will log all API calls as coming from source "myHomeC()"
local sState
local pos = -1
local hSig
local hSigH
local rc
rc = mc.mcCntlEnable(inst,0)
if (rc ~= mc.MERROR_NOERROR) then
wx.wxMessageBox('myHomeC(): Could not disable the machine.')
return
end

rc = mc.mcCntlConfigStart(inst)
if (rc ~= mc.MERROR_NOERROR) then
wx.wxMessageBox('myHomeC(): Could not command the configuration state.')
return
end

hSigH, rc = mc.mcSignalGetHandle(inst,mc.ISIG_MOTOR3_HOME)
if (rc ~= mc.MERROR_NOERROR) then
wx.wxMessageBox('myHomeC(): Could not get the motor 3 home signal handle.')
return
end

rc = mc.mcSignalEnable(hSigH, 1)
if (rc ~= mc.MERROR_NOERROR) then
wx.wxMessageBox('myHomeC(): Could not enable the motor 3 home signal.')
return
end

rc = mc.mcProfileWriteInt(inst, 'Signal68', 'Enabled', 1)
if (rc ~= mc.MERROR_NOERROR) then
wx.wxMessageBox('myHomeC(): Write the motor 3 home signal state to the profile.')
return
end

rc = mc.mcProfileSave(inst)  -- Do we really need to save the mach config to the profile? 
if (rc ~= mc.MERROR_NOERROR) then
wx.wxMessageBox('myHomeC(): Could not save the Mach config to the profile.')
return
end

rc = mc.mcProfileFlush(inst)
if (rc ~= mc.MERROR_NOERROR) then
wx.wxMessageBox('myHomeC(): Could not flush the profile to disk.')
return
end

rc = mc.mcCntlConfigStop(inst)
if (rc ~= mc.MERROR_NOERROR) then
wx.wxMessageBox('myHomeC(): Could not exit the config state.')
return
end
rc = mc.mcCntlEnable(inst,1)
if (rc ~= mc.MERROR_NOERROR) then
wx.wxMessageBox('myHomeC(): Could not enable the machine.')
return
end

hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INDEX)
if (rc == mc.MERROR_SIGNAL_NOT_FOUND) then
wx.wxMessageBox('myHomeC(): Wrong Signal')
return
end
sState, rc = mc.mcSignalGetState(hSig)
if (rc ~= mc.MERROR_NOERROR) then
wx.wxMessageBox('myHomeC(): Error getting signal state');
return
end
if (sState == 1) then  -- sitting on the slot so move off it
rc = mc.mcCntlGcodeExecuteWait(inst, 'g0 f20000 h15\n')--g1 h366 f5000')
if (rc ~= mc.MERROR_NOERROR) then
wx.wxMessageBox('myHomeC(): Error executing G code.  rc = ' .. tostring(rc) .. ".");
return
end
end
rc = mc.mcAxisHome(inst, mc.C_AXIS)
if (rc ~= mc.MERROR_NOERROR) then
wx.wxMessageBox('myHomeC(): Error homing the C axis.');
return
end
 
--this never gets executed
mc.mcCntlSetLastError(inst, 'Homing')
 
repeat
wx.wxMilliSleep(1000)
rc = mc.mcAxisIsHoming(inst, mc.C_AXIS)
if (rc ~= mc.MERROR_NOERROR) then
wx.wxMessageBox('myHomeC(): Error getting the C axis home state.');
return
end

mc.mcCntlSetLastError(inst,'Homing: '..tostring(rc))
until rc == mc.MERROR_NOERROR

rc = mc.mcSignalEnable(hSigH, 0)
if (rc ~= mc.MERROR_NOERROR) then
wx.wxMessageBox('myHomeC(): Could not disable the motor 3 home signal.')
return
end
rc = mc.mcProfileFlush(inst)
if (rc ~= mc.MERROR_NOERROR) then
wx.wxMessageBox('myHomeC(): Could not flush the profile to disk after home C is complete.')
return
end
end

Steve

209
Put this in your screen load script.  Notice I removed the local keyword from the function definition.  This way, you could have multiple buttons call this function, if you wish. 

Code: [Select]
function myHomeC()
local inst=mc.mcGetInstance('myHomeC()') -- this will log all API calls as coming from source "myHomeC()"
local sState
local pos=-1

mc.mcCntlEnable(inst,0)
mc.mcCntlConfigStart(inst)
local hSigH=mc.mcSignalGetHandle(inst,mc.ISIG_MOTOR3_HOME)
rc = mc.mcSignalEnable(hSigH,1)
mc.mcProfileWriteInt(inst, 'Signal68', 'Enabled', 1)
mc.mcProfileSave(inst)
mc.mcProfileFlush(inst)
mc.mcCntlConfigStop(inst)
mc.mcCntlEnable(inst,1)

local hSig,rc=mc.mcSignalGetHandle(inst, mc.ISIG_INDEX)
if (rc == mc.MERROR_SIGNAL_NOT_FOUND) then
wx.wxMessageBox('wrong Signal')
end
sState = mc.mcSignalGetState(hSig)
if (sState == 1) then  -- sitting on the slot so move off it
mc.mcCntlGcodeExecuteWait(inst, 'g0 f20000 h15\n')--g1 h366 f5000')
end
rc = mc.mcAxisHome(inst, mc.C_AXIS)
 
--this never gets executed
mc.mcCntlSetLastError(inst, 'Homing')
 
repeat
wx.wxMilliSleep(1000)
rc = mc.mcAxisIsHoming(inst, mc.C_AXIS)
mc.mcCntlSetLastError(inst,'Homing: '..tostring(rc))
until rc == mc.MERROR_NOERROR
rc = mc.mcSignalEnable(hSigH, 0)
mc.mcProfileFlush(inst)
end

And then simply put:

myHomeC()

in any button's left up script you want.

I know I harp on error checking, but...  it needs more error checking!  :) 

I also still don't like the G code execute wait that doesn't move.  It may or may not cause problems. 

210
If it is ALL in the left up script, what calls myHomeC()?  I see a function stub a the bottom of the script:

if (mc.mcInEditor() == 1) then
  myHomeC()
end

But that will ONLY call the myHomeC() function IF you are inside the code editor.  That is a M code macro script style function stub.  It isn't needed in a button script. 

Steve