Hello Guest it is October 18, 2019, 10:55:45 PM

Author Topic: G-code execution from screen button.  (Read 2363 times)

0 Members and 1 Guest are viewing this topic.

Re: G-code execution from screen button.
« Reply #10 on: October 09, 2017, 01:39:17 PM »
Hi,
set up the buttons and a folder and the rest I can help with.

Craig
My wife left with my best friend...
     and I miss him!
Re: G-code execution from screen button.
« Reply #11 on: October 10, 2017, 03:36:20 AM »
Good Morning. Created three buttons, attachment  below. Also have a folder at C:\Mach4Hobby\Button Codes

Thank you for your help, much appreciated.
Re: G-code execution from screen button.
« Reply #12 on: October 10, 2017, 04:15:59 AM »
Hi,
very low temperature Musa acuminate (kool bananas).

I'm going to suggest a wee work-around which will allow some flexibility and yet still remain fairly simple.
As it turns out initialising a string variable in Lua is not that easy because \ is an escape character. So the Lua interpreter is reading a line of text,
it encounters a \ and then treats the remainder of the line of text as an escape sequence. You can get around it by having two \\ in a row, its a bit
confusing and cumbersome.

Instead I'm going to suggest using Machs registers, means its easy to add a line of text with \ in it and also means its a simple edit if you wish to
change the name and/or file path to the Gcode files.

Fire up Mach go to Configure/Plugins/Regfile and click the wee green cross to add a new register. Give it a name like Button1
and as its initial value put C:\Mach4Hobby\Button Codes\Button1.tap You can expand the width of the column to see it if it makes it clearer. Ensure that the 'persistent'
option is checked. Likewise add two new registers Button2 and Button3 with the path and file as initial value. The description is optional and for your use. Hit <apply>

These registers now hold the path and filename, easy. Check now Diagnostic/Regfile and expand iRegs0 and your new registers should be there and if you
click on them you can edit them right there without delving into the GUI event scripts, nice.

I'm dreaming this up as I go...I would normally have a cigarette and a cup of coffee now while I thought some more....but I given up cigarettes...they were
damn handy at times like this.

Craig
My wife left with my best friend...
     and I miss him!
Re: G-code execution from screen button.
« Reply #13 on: October 10, 2017, 04:42:13 AM »
Hi,
think I've got some code, I haven't tested it...maybe you can do it, I cant really be bothered cluttering up my screen with more buttons to test your
code...

For the Left Up Script for Button1:
Code: [Select]
local inst=mc.mcGetInstance();
mc.mcCntlCloseGCodeFile(inst);
local hreg=mc.mcRegGetHandle(inst,"iRegs0/Button1");
local filename=mc.mcRegGetValueString(hreg);
mc.mcCntlLoadGcodeFile(inst,filename);

Pretty simple and straight forward. Where it might come unstuck is if the file is not where it supposed to be or is null or corrupt etc.
If you have a look at the API for CntlLoadGcodeFile you will find 9 exceptions as return code. If you wish you could test for each
of the return codes to trap errors rather the crash Mach because you left the file empty for instance.

In the mean time go and put a legitimate Gcode file called Button1.tap in your folder and try out the button.

Haven't added any operation codes like <cycle start> yet but we'll get there.

Craig

My wife left with my best friend...
     and I miss him!
Re: G-code execution from screen button.
« Reply #14 on: October 10, 2017, 04:54:43 AM »
WOW! This is so cool. It works! I am so thankful. I cannot wish it to be better. Thank you, thank you!
Re: G-code execution from screen button.
« Reply #15 on: October 10, 2017, 05:11:09 AM »
Hi,
kool, I didn't expect it to work straight off. I'm almost disappointed, it could've thrown a few challenges!

I think some error trapping would be a good idea, if its to operate in a production or semi production environment its highly desirable
that a small mistake or oversight not crash Mach.

Also do you wish to have execution automatic? Do you wish to have some 'safe' moves when a file is closed so the tool doesn't run into the jig
or a clamp on its way to the next lot of code?

Craig
My wife left with my best friend...
     and I miss him!
Re: G-code execution from screen button.
« Reply #16 on: October 10, 2017, 05:30:18 AM »
Yeah, safe moves always are good, especially as for first time we made so powerful machine. Spindle power is enormous.

Oh, and some visual stuff would be great next to buttons, to see witch one is pressed.
« Last Edit: October 10, 2017, 05:35:53 AM by zarsss »
Re: G-code execution from screen button.
« Reply #17 on: October 10, 2017, 05:47:38 AM »
Hi,
yes I thought they might be useful. I would suggest something like:
1) <feedhold>
2) Retract spindle to safe height
3) move to an XY location such that any subsequent move by the first Gcode in any of the three files is safe
4) close old file
5) load new file
6) <cycle start>

The few lines of code to enact 2) and 3) could be done  with CntlGcodeExecuteWait
1) and 5) could just be regular function calls to the functions in the screen load script.

As far as error trapping goes maybe it sufficient just to ensure an MEROR_NOERROR as a return code and call all other return codes as faults
and cease WITHOUT crashing Mach. Good trick if you can do it, my exception trapping and handling skills in Lua are very so so...

Craig
My wife left with my best friend...
     and I miss him!
Re: G-code execution from screen button.
« Reply #18 on: October 10, 2017, 06:43:56 AM »
So i made up some toggle buttons with visual display, witch one is pressed. Each button loads a gcode at on stage, closes gcode at off stage. Is there a way to turn off other buttons while one is at on stage?
Re: G-code execution from screen button.
« Reply #19 on: October 10, 2017, 07:28:19 AM »
.... an ran into a problem...

error 1006: The volume for a file has been externally altered so that the opened file is no longer valid. 

Some buttons showing this.