Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: $cott on September 19, 2016, 03:58:18 PM

Title: Loading G54.1 P1-P120 Automatically
Post by: $cott on September 19, 2016, 03:58:18 PM
Is there a way to load G54.1 P1-P120 locations automatically when G-Code is loaded?

Scott
Title: Re: Loading G54.1 P1-P120 Automatically
Post by: joeaverage on October 01, 2016, 11:11:20 PM
Hi Scott,
I believe it is possible but being new to M4 cannot say exactly how.

I guess you wish to load your fixture offsets from your last session?

In order to do that you must 'remember' those offsets and in M4 that occurs in the
'screen unload' script that ocurrs at shutdown. It has the effect of storing certain data
variables that you nominate typically to your .ini file.

When you start M4 the first script to run is the 'screen load' script and in that script you
would write code to retrieve that offset data from your .ini file to the new offset variables.

The second script to run is the PLC script which of course runs at intervals throughout your
session. I have seen instances where M4 experts have done things like loading offsets only
on the first run of the PLC script. My understanding is that this ensures all the M4 variables
and GUI components have completely loaded before you try to update them with new data.

You can view the current scripts by going to the 'operator' tab and checking 'edit screen'. In the
'screen tree manager' highlight 'wx4' and click the 'events' button in the properties window below.
If you highlight the event your interested in, say 'unload script' you can view and edit the code
stored there. The version I have for instance has no code in the unload script yet but no doubt
will as I transition to using M4 on my machine.

Hope this will get you started.

Craig
Title: Re: Loading G54.1 P1-P120 Automatically
Post by: joeaverage on October 02, 2016, 12:06:32 AM
Hi Scott,
some of the stuff I read has actually stuck....shame I didn't think or remember berfore I opened
my gob!

Look in the 'help docs', easiest access is the 'help docs?' button on the M4 screen.
Open the scripting manual pdf, section 4 is about registers and 4.4 and 4.5 about
saving and retrieving them.

Also have a look in the Mach4 Toolbox child board of this board and find poppabears
post on enums.....I took a little chunk so you could see:

Fixture offsets, G54, 55, 56 etc. have a Gap of 20 between them.
fixture offset values start with G54 at #5221
G54 X = #5221
G54 Y = #5222
G54 Z = #5223
G54 A = #5224
G54 B = #5225
G54 C = #5226
--20 point gap between G54 and G55, i.e. 522x to 524x
G55 X = #5241
G55 Y = #5242
G55 Z = #5243
G55 A = #5244
G55 B = #5245
G55 C = #5246

So the basic process is in the screen unload script:

Save those registers that you want, say
#5221, #5222, #5223, the xyz of G54

And in the first run of the PLC script:

restore #5221, #5222, #5223

Sorry I don't know enuf about coding to give any more but the luaexamples in the
Mach4 folder will no doubt have some examples to follow.

Craig