Problems using constructor and distructor to save current...

This is where you talk about Macros, show examples of your macro scripting and SHARE handy segments of script code as examples.

Problems using constructor and distructor to save current...

Postby kig23 » Sat Apr 21, 2018 1:55 pm

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
kig23
 
Posts: 158
Joined: Sat Mar 31, 2018 6:58 am
Location: Italy

Re: Problems using constructor and distructor to save curren

Postby dezsoe » Sat Apr 21, 2018 2:13 pm

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";

// ================================================================================================
dezsoe
 
Posts: 2049
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Problems using constructor and distructor to save curren

Postby kig23 » Sat Apr 21, 2018 2:29 pm

Thank you. What do you think, maybe there is another solution to modify m6 macro to avoid using macroloop.
kig23
 
Posts: 158
Joined: Sat Mar 31, 2018 6:58 am
Location: Italy

Re: Problems using constructor and distructor to save curren

Postby dezsoe » Sat Apr 21, 2018 2:55 pm

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.
dezsoe
 
Posts: 2049
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Problems using constructor and distructor to save curren

Postby kig23 » Sat Apr 21, 2018 3:44 pm

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")));
}
kig23
 
Posts: 158
Joined: Sat Mar 31, 2018 6:58 am
Location: Italy

Re: Problems using constructor and distructor to save curren

Postby dezsoe » Sat Apr 21, 2018 4:22 pm

Nice! But, instead of "False" use "0", because "False" cannot be converted to Int32.
dezsoe
 
Posts: 2049
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Problems using constructor and distructor to save curren

Postby kig23 » Sat Apr 21, 2018 4:37 pm

Thanks.
kig23
 
Posts: 158
Joined: Sat Mar 31, 2018 6:58 am
Location: Italy

Re: Problems using constructor and distructor to save curren

Postby dezsoe » Sat Apr 21, 2018 7:58 pm

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. :)
dezsoe
 
Posts: 2049
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Problems using constructor and distructor to save curren

Postby ger21 » Sat Apr 21, 2018 8:56 pm

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.
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2663
Joined: Sat Sep 03, 2016 2:17 am

Re: Problems using constructor and distructor to save curren

Postby ger21 » Sat Apr 21, 2018 10:03 pm

No, but if UCCNC didn't allow me to do what it does, I'd be using something else that does.
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2663
Joined: Sat Sep 03, 2016 2:17 am

Next

Return to Macros

Who is online

Users browsing this forum: Bing [Bot] and 9 guests