Page 1 of 3

Problems using constructor and distructor to save current...

PostPosted: Sat Apr 21, 2018 1:55 pm
by kig23
I've some problems to save and read the current tool value. Here is the code in constructor macro,
Code: Select all
exec.Setcurrenttool (Convert.ToInt32 (exec.Readkey ("MyCNC", "CurrentTool", "False")));

and here the code in desrtuctor macro.
Code: Select all
exec.Writekey ("MyCNC", "CurrentTool", Convert.ToString(exec.Getcurrenttool ()));

When set current tool in UCCNC and then close it, in the .pro file i have the value of the set current tool. But when i start UCCNC the value of the current tool is 0. Am'i missing something. Thanks

Re: Problems using constructor and distructor to save curren

PostPosted: Sat Apr 21, 2018 2:13 pm
by dezsoe
You cannot change the tool number while in reset state. Here is a macroloop that sets F and S default value on the first time reset is pressed. I copied your code with a little correction into this macro. Save it and set in macroloops to autorun.

Code: Select all
// ================================================================================================
// First run tasks v1.0
// ================================================================================================

bool ResetNow = exec.GetLED(ResetLED);

if (FirstRun && !ResetNow)
{
  while (!exec.GetLED(ResetLED))
    Thread.Sleep(10);
  ResetNow = exec.GetLED(ResetLED);
}

FirstRun = false;

if (NeedCheck && !ResetNow)
{
  NeedCheck = false;
  Thread.Sleep(100);
  exec.Code(CommandLine);
  AS3.Additemtolistbeginning(CommandLine + " is set", 2);
  int NewTool = Convert.ToInt32(exec.Readkey("MyCNC", "CurrentTool", "0"));
  exec.Setcurrenttool(NewTool);
  AS3.Additemtolistbeginning("Tool " + NewTool.ToString() + " is set", 2);
}

// ================================================================================================

#Events

// ================================================================================================

const int ResetLED = 25;

static bool FirstRun = true;
static bool NeedCheck = true;

const string CommandLine = "F100 S250";

// ================================================================================================

Re: Problems using constructor and distructor to save curren

PostPosted: Sat Apr 21, 2018 2:29 pm
by kig23
Thank you. What do you think, maybe there is another solution to modify m6 macro to avoid using macroloop.

Re: Problems using constructor and distructor to save curren

PostPosted: Sat Apr 21, 2018 2:55 pm
by dezsoe
I don't understand your question. You can change M6 to do what you want, but the job was to restore the last tool number on startup. You can do it only with macroloop. What's the problem with macroloops? Many people are afraid of using macroloops, but if the macroloops are written well, then there's no problem with them. The only thing that you must keep in mind is that never do anything that overloads the CPU and/or UCCNC. This macroloop is optimized to do the less that's needed. Try to check the CPU usage while you start and stop it. Only the first run will be visible when .Net compiles the macro.

Re: Problems using constructor and distructor to save curren

PostPosted: Sat Apr 21, 2018 3:44 pm
by kig23
Thanks for your help. I'm not afraid of using macroloops, but instead of writing two macros, because i need that the constructor macro loads some other values, not only the current tool. I create a thread in the constructor macro that do the job. Here is the code.
Code: Select all
new Thread(delegate () {
    ChangeCurrTool ();
   }).Start();

#Events

private void ChangeCurrTool ()
{
   while (AS3.GetLED (25));
   exec.Setcurrenttool (Convert.ToInt32 (exec.Readkey ("MyCNC", "CurrentTool", "False")));
}

Re: Problems using constructor and distructor to save curren

PostPosted: Sat Apr 21, 2018 4:22 pm
by dezsoe
Nice! But, instead of "False" use "0", because "False" cannot be converted to Int32.

Re: Problems using constructor and distructor to save curren

PostPosted: Sat Apr 21, 2018 4:37 pm
by kig23
Thanks.

Re: Problems using constructor and distructor to save curren

PostPosted: Sat Apr 21, 2018 7:58 pm
by dezsoe
Hi Terry, thanks for the explanation. I think, creative users can destroy anything, so there's no reason to limit the possibilities... :) Even commercial manufacturers are unable to make the users use their brain. :)

Re: Problems using constructor and distructor to save curren

PostPosted: Sat Apr 21, 2018 8:56 pm
by ger21
dezsoe wrote:Hi Terry, thanks for the explanation. I think, creative users can destroy anything, so there's no reason to limit the possibilities... :) Even commercial manufacturers are unable to make the users use their brain. :)


Yes, the rewards far outweigh the risks.

If everyone were to document and provide all the info, that would go a long way. In the manual for my screenset, I list the numbers of every field, checkbox, button and LED that I use. So if someone needs to change something, it's relatively painless.

I guess the biggest issue is when you don't know that there's a conflict.

Re: Problems using constructor and distructor to save curren

PostPosted: Sat Apr 21, 2018 10:03 pm
by ger21
No, but if UCCNC didn't allow me to do what it does, I'd be using something else that does.