Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: KatzYaakov on August 15, 2019, 04:59:52 PM

Title: stop while Mfuncion run
Post 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
Title: Re: stop while Mfuncion run
Post by: smurph on August 16, 2019, 12:04:52 AM
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
Title: Re: stop while Mfuncion run
Post by: KatzYaakov on August 16, 2019, 03:54:32 AM
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::)
Title: Re: stop while Mfuncion run
Post by: Chaoticone on August 16, 2019, 09:55:28 AM
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

Title: Re: stop while Mfuncion run
Post by: KatzYaakov on August 16, 2019, 11:38:30 AM
thanks alot got it
but where can i find the  mcErrorCheck.lua module to get the return list?
Title: Re: stop while Mfuncion run
Post by: Chaoticone on August 16, 2019, 12:42:52 PM
C:\Mach4Hobby\Modules
Title: Re: stop while Mfuncion run
Post by: KatzYaakov on August 17, 2019, 04:52:18 PM
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


Title: Re: stop while Mfuncion run
Post by: smurph on August 18, 2019, 02:51:19 PM
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
Title: Re: stop while Mfuncion run
Post by: KatzYaakov on August 18, 2019, 04:04:02 PM
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));

}
Title: Re: stop while Mfuncion run
Post by: smurph on August 18, 2019, 11:49:20 PM
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
Title: Re: stop while Mfuncion run
Post by: KatzYaakov on August 18, 2019, 11:53:58 PM
thanks alot ill try