Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: Overloaded on May 08, 2014, 08:40:34 AM

Title: Disable button unless Idle
Post by: Overloaded on May 08, 2014, 08:40:34 AM
Hey folks,
 I inadvertently hit my G28 button WHILE GCode was running .... disastrous results. Blew its mind and locked up.

--G28 "Go to Machine Zeros, Z First"
        local inst = mc.mcGetInstance()
        local code = "G0 G53 Z0.0\n"
        code = code .. string.format("G0 G53 X0 Y0 A0\n")    
        mc.mcCntlGcodeExecute(inst, tostring(code))


Looking for an example of how, where and what to do to isolate, or disable a button while it should NOT be allowed to execute.

Looked through the sc script but am not sure what I'm looking for or where a lot of it is editable.

Add something to the button script ? or ?

Clues, hints or examples appreciated.

Thanks folks,
Russ
 :)
Title: Re: Disable button unless Idle
Post by: Ya-Nvr-No on May 08, 2014, 09:06:52 AM
might try something like this in the PLC script, just change the button name to what yours  is named

if (mc.mcCntlIsInCycle(inst) == 1) then
      scr.SetProperty('btnGotoZero', 'Enabled', '0');
else
      scr.SetProperty('btnGotoZero', 'Enabled', '1');
end
Title: Re: Disable button unless Idle
Post by: Overloaded on May 08, 2014, 10:16:27 AM
Hi Craig,
  Can't seem to get this to work.
Is there a difference between a custom button and what looks like "assigned function" buttons/labels ?
Thanks,
Russ
Title: Re: Disable button unless Idle
Post by: Ya-Nvr-No on May 08, 2014, 10:42:12 AM
I did put that above code in the (if statement below) and it worked fine for that button
you might start with that first to prove that one works
what is your button Name? make sure you typed it the same, it is case sensitive.
 
other than that, not quite following you on the custom button and assigned function reference.

There are lots of tidbits to glean from by looking at the PLC script and the Cycle start Button Script

The only other thing is to post the whole "Lua Script" and we can look at it.
You can to use the right mouse button to select all and copy or Ctrl-A Ctrl-C
paste and save as a text file.

if ((machState ~= machStateOld) or (machEnable ~= machWasEnabled)) then

Title: Re: Disable button unless Idle
Post by: Overloaded on May 08, 2014, 11:37:35 AM
Hey, that graphic cleared it right up !
I had G28 as the Name AND the Label, but had btnG28 in your script.
Changed the Name to btnG28 and all is well ... Great, Thanks !

I thought maybe certain button names were reserved and already had associated functions assigned to them, but looks like you just make them up as you go. (just don't "mix n' match")

I'll try to figure this out on my own, but next I'd like to add isolation for when the control is Disabled. Like the Go to Zero and the Jogging.

Thanks a bunch !
Russ  8)
Title: Re: Disable button unless Idle
Post by: Overloaded on May 08, 2014, 01:34:59 PM
There are several buttons/ops that will jam up the works if hit while the file is runnung.
I guess they could all be stacked like this ?

--From Craig to isolate G28 button, and others
    if (mc.mcCntlIsInCycle(inst) == 1) then
      scr.SetProperty('btnG28', 'Enabled', '0');
      scr.SetProperty('btnGotoZero', 'Enabled', '0');
      scr.SetProperty('tabFileOps', 'Enabled', '0');
    else
      scr.SetProperty('btnG28', 'Enabled', '1');
      scr.SetProperty('btnGotoZero', 'Enabled', '1');
      scr.SetProperty('tabFileOps', 'Enabled', '1');
    end

I wanted to try....   if ((mc.mcCntlIsInCycle(inst) == 1) or (mc.mc Call for Enabled or Disabled (inst) == 1(or0)) then .....
but could not determine what would go here --------------------------------------^
IsInCycle, IsStill, State .... I found. Is there one appropriate for this ?

Turns out, the axis' are disabled when in reset anyway, so that part is OK, just wondering what to call in tha case above.
Cool, thanks again Craig,
Russ

Title: Re: Disable button unless Idle
Post by: Ya-Nvr-No on May 08, 2014, 01:46:39 PM
Notice in the included photo that what your addressing is a field in the button options your just changing the state of it.
the checked box = 0 when not checked, and 1 when checked.
you could use the Hidden option

So Good job Russ that's kind of what I'd had planned too about the buttons
Title: Re: Disable button unless Idle
Post by: Overloaded on May 08, 2014, 01:56:54 PM
Well I'll be ding danged, right there under my nose, just couldn't smell it.
(wondered what they were for ::) )

I'm anxious to get a manual on this ...... before pestering you folks to the point of being qualified to author it.  ;D

Thanks once more,
Russ
Title: Re: Disable button unless Idle
Post by: Overloaded on May 08, 2014, 02:23:32 PM
I'll clarify...
 (mc.mcCntlIsInCycle(inst) == 1)   a file is running, ==0 would be not running   right ?

if so, what is the call for the following ?
 (mc.mc__________(inst) == 1)   control is enabled, ==0 control is disabled
or is there one?
Russ
Title: Re: Disable button unless Idle
Post by: BR549 on May 08, 2014, 04:51:18 PM
HIYA guys these are things that should be fixed in the core.

(;-) TP
Title: Re: Disable button unless Idle
Post by: Overloaded on May 08, 2014, 06:20:38 PM
HIYA guys these are things that should be fixed in the core.

(;-) TP

Come to think of it, I'll agree with that.
Makes sense that some thing should never be allowed to happen under any circumstance.

Steve did say that G28 isn't implemented yet, so it'll probably be taken care of when it is.

Russ
Title: Re: Disable button unless Idle
Post by: Ya-Nvr-No on May 08, 2014, 08:51:10 PM
I'll clarify...
 (mc.mcCntlIsInCycle(inst) == 1)   a file is running, ==0 would be not running   right ?

if so, what is the call for the following ?
 (mc.mc__________(inst) == 1)   control is enabled, ==0 control is disabled
or is there one?
Russ

(mc.mcCntlIsInCycle(inst) == 1)   a file is running, ==0 would be not running   right ?      -- Correct


Try this;
To use a button to toggle Enable and Disable

--put this in the Screen Load Script
a = 0 -- set a variable

--Place under a button
local inst = mc.mcGetInstance();
if (a == 0) then   --look for the value of a
    a = 1;             --set the value of a
    mc.mcCntlEnable(inst, 1);  -- Enable
elseif (a == 1) then
    a = 0;
    mc.mcCntlEnable(inst, 0);  --Disable
end

Nothings really broke, just needs to be understood, and new code written to do what you want.
Don't expect this to be something your going to learn overnight, Long learning curve
I think I saw the light bulb from here when you seen how to use the Enable property.
I struggle everyday with one thing or another. But I Ain't dead yet.
don't give up

Learn to use the History / Error display to view code when your debugging an issue
This is over kill but it gives you an idea of how to look before and after something you expect to happen or do
the history button shows you the output and you can see what works and whats not. Clear, Close and try it again

local inst = mc.mcGetInstance();
    mc.mcCntlSetLastError(inst, 'mc.mcCntlEnable 1? = ' .. tostring(mc.mcCntlEnable));
    mc.mcCntlSetLastError(inst, 'a1? = ' .. tostring(a));
if (mc.mcCntlEnable ~= 0 and a == 0) then
    mc.mcCntlSetLastError(inst, 'mc.mcCntlEnable 2? = ' .. tostring(mc.mcCntlEnable));
    mc.mcCntlSetLastError(inst, 'a2? = ' .. tostring(a));
     a=1;
    mc.mcCntlEnable(inst, 0);
    mc.mcCntlSetLastError(inst, 'mc.mcCntlEnable 3? = ' .. tostring(mc.mcCntlEnable));
    mc.mcCntlSetLastError(inst, 'a3? = ' .. tostring(a));
elseif (mc.mcCntlEnable ~= 0 and a == 1) then
    mc.mcCntlSetLastError(inst, 'mc.mcCntlEnable 4? = ' .. tostring(mc.mcCntlEnable));
    mc.mcCntlSetLastError(inst, 'a4? = ' .. tostring(a));
     a=0;
    mc.mcCntlEnable(inst, 1);
    mc.mcCntlSetLastError(inst, 'mc.mcCntlEnable 5? = ' .. tostring(mc.mcCntlEnable));
    mc.mcCntlSetLastError(inst, 'a5? = ' .. tostring(a));
end
Title: Re: Disable button unless Idle
Post by: Overloaded on May 08, 2014, 10:46:08 PM
All good info, thanks again for another fine tutorial.
Saved to my study book. ;)
Learning curve ? ? ? ? Andromeda is the radius point of mine !  ::)

I understand the toggle example, excellent explanation.
The History / Error display will take some practice and memorizing, I'll plan to use it.
I can't seem to debug in the editor, f5, then f11 to step through, then crashes every time. Mentioned it to Steve but he never got back. Afraid to use it now. ::)

Thanks Craig,
Russ
 :)

Title: Re: Disable button unless Idle
Post by: BR549 on May 08, 2014, 10:59:20 PM
HIYA Ross same problem here with Lua editor . Today has been nothing but a crash fest can't get anything done for it.

OH well there is always tomorrow, (;-) TP
Title: Re: Disable button unless Idle
Post by: smurph on May 08, 2014, 11:43:28 PM
Guys...  don't waste too much time on this button enabling and disabling.  I have just added a new property to all of the GUI objects.  "Enabled State"  You can choose which states the button (or other control) is enabled in with a click of a few check boxes!!!  It will be in the next update.

The Lua editor has a problem with Windows XP.  I have yet to fix that.  But it is on my list.  It is just that XP is not what I develop with so it doesn't get as much love.  XP's GUI event timings are different that the newer OSes.  It has been a real pain.  It would be much simpler for me if all of you guys running XP would just upgrade.  So how about it guys?  How about upgrading for a poor beat up programmer?  :)

Steve
Title: Re: Disable button unless Idle
Post by: Overloaded on May 09, 2014, 12:04:53 AM
Cool, I'll just consider it an exercise in basic scripting, valuable none the less.
More check boxes ... I like check boxes.

I can dump XP shortly, its the least I could do being I'm probably one of the few stuck with my very first computer.
 Is 7-32 compatible ? Or is 64 bit req./preferred ?

Thanks,
Russ


Title: Re: Disable button unless Idle
Post by: smurph on May 09, 2014, 12:20:17 AM
HIYA guys these are things that should be fixed in the core.

(;-) TP

Just to clarify, the GUI has nothing to do with the core.  It is not like Mach 3.  There is a GUI (could be anything AND written with just about anything), the core, and plugins.  All three are separate.  In fact, we have two GUIs that can be used, Mach4GUI and wxMach.  And I have actually written C# and VB GUIs (for grins) that run the core.  The core is the interpreters, trajectory planners, and signals manager.

Steve
Title: Re: Disable button unless Idle
Post by: smurph on May 09, 2014, 12:34:53 AM
Is 7-32 compatible ? Or is 64 bit req./preferred ?

Thanks,
Russ

Both work well.  I use Win7-32 on my Matsuura.  Works fine.  If you want to EVER run the parallel port, you have to choose Win7-32.  Otherwise, I would go Win7-64.  It seems to be bit more stable.  Win7-32 isn't bad, just that Win7-64 NEVER seems to have an issue.  That's just my experience.

The upgrade thing was just a joke.  While I would really just love to be done with XP and never have to see it again, I do understand that people want to get the most out of their investment.  We are trying REALLY hard to support XP.  It was a good OS.  It is just that it is getting a bit long in the tooth as far as programming for it goes. 

But don't go upgrading if your compy only has 2 Gig of mem or less.  Win7 does require more system resources (memory for sure!).  If you put it on a 2 Gig system, you will end up buying memory sticks too.  The price of the memory plus the price of the Win7 OS may get very close to a new system's price!!  Do your homework.

Steve
Title: Re: Disable button unless Idle
Post by: per-dk on May 24, 2014, 07:47:10 AM
Hi All
Okay you can change proberty of a button like this: :D

scr.SetProperty('btnGotoZero', 'Enabled', '0');

But I can not understand why you can not change color.?  ???
Is there anyone who can help then it will just be super.

I've tried several combinations also this:

scr.SetProperty('button109', 'Bg Color', '(254,180,175)');
Title: Re: Disable button unless Idle
Post by: ger21 on May 24, 2014, 08:15:10 AM
Looks like colors need to be in hex, not rgb.

scr.SetProperty('btnEnable', 'Bg Color', '#00FF00')
Title: Re: Disable button unless Idle
Post by: per-dk on May 24, 2014, 04:30:12 PM
Many many thanks ger21 this I had never found out. :)
Title: Re: Disable button unless Idle
Post by: MojsterMiha on July 14, 2014, 04:09:36 AM
Hi
I read the whole post and nowhere I detect exactly how to get to the sc script in Mach3.
What is Lua Editor and where do I get it?
The same thing (Disable buttons When running) I would like  to make in the Mach3 ...
Can anyone help me?

Thanks!
Title: Re: Disable button unless Idle
Post by: smurph on July 14, 2014, 05:55:53 PM
We are talking about Mach 4 demo here.  Mach 3 can't disable any buttons.  :(

Steve