Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: KatzYaakov on August 15, 2019, 04:59:52 PM
-
hi
i always have this issue cant real solve
if i press stop while machine run Mfunction(can be long m function with many works and movement ,not only open valve)
the function never stop ,its continue until its finish the M function only axis movement are stoped
also if i put
mc.mcCntlCycleStop(0)
command in the function also same problem only movement stop but all other like open valve ,close...
continue to run
-
It is up to you, the script writer/programmer, to catch the stop condition and abort the rest of the script. This is mainly done with checking the return codes from the API functions. e.g. If the return code is not mc.MERROR_NOERROR, abort the script.
Steve
-
i try use the return id but it always give me Unexpected value
for example:
local dhs= mc.mcSignalWait(0, mc.ISIG_INPUT14, 1, 2);
this gave me the value 40.0 if no any signal change
second question is how i abort?
i try with "goto exit" but it always not find the label ( i put the label ::exit::)
-
Get the return codes. Look at the mcErrorCheck.lua module. It is all the return codes and examples of how to use it are commented out at the top. The return code you got was not 40. It was -40. Instead of using the mcErrorCheck module you can also use the API call mcCntlGetErrorString as in the example below.
This is an example of what has worked well for me. I'm not going to a label. I run a function that does what I want and immediately after returning to the calling function I exit (return) that function. At that point there is nothing else in that script executed. But everything after that is wrapped in functions so something has to call them for them to run. If I had lines of code after that function that were not in a function, they would be executed.
if (rc ~= 0) then
msg = mc.mcCntlGetErrorString(inst, rc) --Get the returned error string
errorOut(msg)
return --Exit the function
end
local function errorOut(msg)
local inst = mc.mcGetInstance()
mc.mcSpindleSetDirection(inst, mc.MC_SPINDLE_OFF)
mc.mcCntlMacroAlarm(inst, 3, msg)
end
-
thanks alot got it
but where can i find the mcErrorCheck.lua module to get the return list?
-
C:\Mach4Hobby\Modules
-
i understand about the :
mc.mcSignalWait
i test and its ok
but when i have also :
mc.mcSignalSetState
then what can i do? i have only 2 return rc options not one of them will handle stop option
and again ,when i press stop that m function not stop its continue to run only movement stop
-
Checking the state of the control, mcCntlGetState(), looking for a non running state could be used. You would need to check the state after every call that does not return an error when the control is stopped. For example, mcSignalSteState(). It is perfectly fine to set a signal state when the control is stopped. So you MUST use some other method to check for a stop condition with those types of API calls.
Steve
-
steve
i real thanks for yours kindly help
but according instruction i cant get the machine state
i try copy the instruction but its cant compile
always compilation error
MINSTANCE mInst = 0;
mcState state;
char stateName[80];
int rc = mcCntlGetState(mInst, &state);
if (rc == MERROR_NOERROR) {
// Success!
rc = mcCntlGetStateName(mInst, state, stateName, sizeof(stateName));
}
-
Look at the LUA syntax. It is different than the C syntax you posted.
state, rc = mc.mcCntlGetState(inst)
if (state == mc.MC_STATE_IDLE) then
-- We are no longer running because of a stop or e-stop.
end
Here are some interesting control state constants:
mc.MC_STATE_IDLE
mc.MC_STATE_JOG -- manual jogging
mc.MC_STATE_DRYRUN --dry run
mc.MC_STATE_HOME
mc.MC_STATE_FRUN -- running a G code file.
mc.MC_STATE_MRUN -- running MDI G code.
Steve
-
thanks alot ill try