Code Snippets >> Save & Restore Parameters #VARS 500 to 999

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.

Code Snippets >> Save & Restore Parameters #VARS 500 to 999

Postby Robertspark » Mon Jan 14, 2019 3:00 pm

Permanent common variables (stored values in these variables #500 to #999 are not meant to be cleared by reset or power cycle, these code snippets added to the M99998.txt and M99999.txt macros allow you to emulate the saving and restoring of variables #vars #500 to #999 so they act as persistent).

You will need to add the following code snippet into you Constructor Macro M99998.txt for your profile.
Code: Select all
// LOADS #vars (PARAMETERS) #500 to #999 from profile at machine startup.
// save code snippet to Constructor Macro M99998.txt
for (var x = 500; x < 1000; x++)
{
   exec.Setvar(Convert.ToDouble(exec.Readkey("PARAMETERS", "#" + x + "", "0")), x );
}


You will need to add the following code snippet into you Destructor (Deconstructor???) Macro M99999.txt for your profile.
Code: Select all
// SAVES #vars (PARAMETERS) #500 to #999 to profile at machine shutdown.
// save code snippet to Destructor (Deconstructor??) Macro M99999.txt
for (var x = 500; x < 1000; x++)
{
    exec.Writekey("PARAMETERS", "#" + x + "", "" + exec.Getvar(x) + "");
}



Note..... If you have a power loss or your force a shutdown of UCCNC then the destructor macro M99999.txt will not run so the values for vars #500 to #900 will not be saved.

If you want more persistent saving you could run a macroloop at say a 1 minute interval to save these values to the profile or you could run a longer time period between saves as this saving of ~500 vars will add some overhead ..... so you probably don't want to do it too often..... {20Hz is probably a bit pointless given how much you may use / change these #vars......
Option A) use the Destructor Macro M99999.txt
Option B) if you want the saving to be more frequent.... use a macroloop

Macroloop code as follows:
Code: Select all
// MACROLOOP to periodically save VARIABLES (PARAMETERS) #500 to #900 for UCCNC to Profile for restore at restart (M99998.txt)
// 14/01/2019
//Robertspark

while(loop)
{
   // SAVES #vars (PARAMETERS) #500 to #999 to profile at machine shutdown.
   // save code snippet to Destructor (Deconstructor??) Macro M99999.txt
   for (var x = 500; x < 1000; x++)
   {
      exec.Writekey("PARAMETERS", "#" + x + "", "" + exec.Getvar(x) + "");
   }
    Thread.Sleep(60000);  // 1 minute save loop cycle {could increase to 5 mins (300000)  or 10 mins (600000)}
}


happy coding .... :geek:
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Return to UCCNC TOOL BOX

Who is online

Users browsing this forum: No registered users and 1 guest