Hello Guest it is March 28, 2024, 03:03:09 PM

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

0 Members and 1 Guest are viewing this topic.

G-code execution from screen button.
« on: October 06, 2017, 11:28:48 AM »
Hi. Me again. Looking for any advice, how to create three buttons on the screen, and when i click any of them each one executes different g-code. Thank you.
Re: G-code execution from screen button.
« Reply #1 on: October 06, 2017, 02:16:13 PM »
Hi,
what sort of Gcode? Is it one  or two lines of code or is it a complete Gcode file? Does the code change?

If each piece of code you wish to execute is reasonably small and is fixed then
Quote
LUA Syntax:
rc = mc.mcCntlGcodeExecute(
      number mInst,
      string commands)
will be very useful to you. You can use it in the left-up button event script to execute small batches of code.

Craig

'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: G-code execution from screen button.
« Reply #2 on: October 07, 2017, 04:47:17 AM »
My target is to machine a part from 3 sides. The jig is coming up, to clamp three parts on the bed the same time. But each part is being machined at different stage. Ideally i would like to have three buttons on the screen: Do Stage 1, Do Stage 2, Do Stage 3. So  i dont know, can small batches of code classify 2000 lines. Also i have to admit, that i am hardware person, and absolutely noob in lua coding.
Re: G-code execution from screen button.
« Reply #3 on: October 07, 2017, 04:51:57 AM »
Here is a baby.

« Last Edit: October 10, 2017, 02:22:55 AM by Tweakie.CNC »
Re: G-code execution from screen button.
« Reply #4 on: October 07, 2017, 05:16:14 AM »
Hi,
that API call is useful for Gcode snippets of two-three-four lines... not 2000.

The way to do that is to have a button call a Gcode file, three buttons, three files. To my knowledge the Gcode interpreter can only have one
active Gcode job. So if you hit button #2 the code which had been running will be closed and the file associated with button #2 loaded and then run.

Another possibility it to have one large file with three sections, one section associated with one button. This would mean that just the one Gcode file
would be loaded and it would not be necessary to unload between buttons. It might be possible to have yet other sections that control the jig and/or
clamping of the part.

Just exactly how you go about indentiying your part zero for the three different operations would require some thought.

Are the Gcode chunks likely to change often?

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: G-code execution from screen button.
« Reply #5 on: October 08, 2017, 09:08:38 AM »

The way to do that is to have a button call a Gcode file, three buttons, three files. To my knowledge the Gcode interpreter can only have one
active Gcode job. So if you hit button #2 the code which had been running will be closed and the file associated with button #2 loaded and then run.

How this can be done, please? Gcode files will be changing at the beginning  till we happy with results. After that it will be semi mass production.
Re: G-code execution from screen button.
« Reply #6 on: October 08, 2017, 12:17:05 PM »
Hi,
two preliminary things to be done.

1) Set up a folder somewhere on your machine that will have the three Gcode files. Your buttons will be calling these files so they will
need a fixed filepath and the files themselves need a unique name.

2) You need to set up three buttons on your screen. Exactly where you put them is up to you. If you are not familiar with editing the screen
then you need this:
http://www.machsupport.com/wp-content/uploads/2014/05/Mach4%20Screen%20Editor%20V1.0.pdf
For ease I would put them in the same 'container', means that you don't have to chase all around looking for the code. Given that you are
modifying the screen you should save it as a unique file so when you update Mach the standard screen set doesn't get overwritten.

Once you have these two items in hand then the event script of each button will be populated. Two instructions likely to be of use are:
Code: [Select]
rc = mc.mcCntlCloseGCodeFile(
number mInst)
and:
Code: [Select]
rc = mc.mcCntlLoadGcodeFile(
number mInst,
stringFileToLoad)

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: G-code execution from screen button.
« Reply #7 on: October 08, 2017, 11:51:57 PM »
Hi zarass,
had a couple more thoughts that may help you along. I don't know what screenset you are using, my one is now somewhat personalised but is
still very close to wx4.set which is  one of the standard sets that ships with Mach. Given that it is personalised I've given it a new name.

If you note the five buttons just below the DRO block <DeRef All Axes>,<GoTo Work Zero>,<blank>,<Machine Coords>,<Distance To Go>. I don' know about you
but I only use <GoTo Work Zero> and <Machine Coords>. Because the screen is that full of stuff already what I would do is reuse the unused buttons and
the one unassigned one for the three buttons you require. Cheap and Cheerful, Down and Dirty is my motto!

Actually adding buttons and LEDs and things is quite fun but you don't really have much room to play with. I've found you have to shrink a lot of existing
buttons and other elements just to squeeze in another button or whatever it is that you want.

If that sounds Like a reasonable idea to you then its just a case of using the screen editor to change two buttons to your preferred name and assigning a name
for the one unused button. You would need to clear any event script or functionality of the two buttons you are re-purposing.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: G-code execution from screen button.
« Reply #8 on: October 08, 2017, 11:58:38 PM »
Hi zarass,
just one other thing....your machine pics are great but because they are embedded in the text they open and download each and every time
the post is opened.

A better method for pictures, particularly detailed high resolution pictures is to add them as an attachment. They show up then as thumbnails and the
reader of the post can download and view as he wishes or not as the case may be.

When posting with the text window open you'll see 'Additional Options...' to the lower left of the panel, click on it and you can browse to any file
including jpegs that you wish to attach.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: G-code execution from screen button.
« Reply #9 on: October 09, 2017, 08:44:45 AM »
Hi. Sorry about pictures, not using forums a lot. Unfortunally i cannot edit my post to fix this.

Also thank you for button advice.  I just don`t know, how use those scripts. Where i should put filenames and file path in? Actually i know nothing about it. I was struggling with M6 script until i found one in samples.