#Events: a little surprise from UCCNC

Here is where you can drop off Examples of WORKING macros,plugins,Gcode programs , macro Wizards etc.
Please give a brief description of what it is and how it works.

#Events: a little surprise from UCCNC

Postby dezsoe » Mon May 29, 2017 11:00 am

Over the development of UCCNC, first came the #Events tag in macros. This was made for putting special code in macros to handle forms events or other functions/subroutines. An other development was about the macro compilation. In the past every time a macro was called, it was first compiled. It was very slow. Now if Precompile switch is on the macros are compiled on program startup, or if not, they are compiled on first run. Of course, if a macro is changed, it will be compiled again.

These two developments have a little but very useful side-effect: we can use static variables after the #Events tag. These variables store their values until the macro is recompiled or UCCNC exits. A small example:

Code: Select all
AS3.Additemtolistbeginning("Value: " + value, 2);
++value;

#Events

static int value = 0;

Running this macro more times you can see in the status window the increasing value.

Now we have unlimited possibilities. :) Let's make a tri-state button: every press executes the next function in cycle:

Code: Select all
switch (state)
{
  case 1:
    AS3.Additemtolistbeginning("First state", 2);
    ++state;
    break;
  case 2:
    AS3.Additemtolistbeginning("Second state", 2);
    ++state;
    break;
  case 3:
    AS3.Additemtolistbeginning("Third state", 2);
    state = 1;
    break;
}

#Events

static int state = 1;

In the past you had to use #variables or - as the worst way - you could write values to the profile and read back. The first was only for numeric values and could interfere with the running g-code, the second is slow and messes up the profile file.
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: #Events: a little surprise from UCCNC

Postby Battwell » Sat May 22, 2021 12:04 pm

This looks like a great method to use for a hot swap tool changer.
Where full list of tools can be read in from the start of the file. Then the changer can have the next tool ready for instant swap.
Uc300eth on router and mill.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 860
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk


Return to UCCNC TOOL BOX

Who is online

Users browsing this forum: No registered users and 2 guests