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: 57
Joined: Sat Mar 31, 2018 6:58 am

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: 477
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: 57
Joined: Sat Mar 31, 2018 6:58 am

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: 477
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: 57
Joined: Sat Mar 31, 2018 6:58 am

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: 477
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: 57
Joined: Sat Mar 31, 2018 6:58 am

Re: Problems using constructor and distructor to save curren

Postby Vmax549 » Sat Apr 21, 2018 6:45 pm

HI Dezoe, The FEAR of macroloops goes back to the mach3 macropump. Flags were used to activate a function scripted in teh macropump. The fear was something like a wizard or a macro or other script would set teh same flag and cause an unitended action that could crash or damage teh machine or users.

AND teh fear was well earned in later years when there was so much Mach3 code floating around teh web that users could try. Just when you thought you had a idea to set a special flag that no one else would think of using you found something that set teh same flag (;-). It was teh same with DROs and LEDs.

In it's current state UCCNC will not be any different.

It is also one of the reasons that commercial controllers do not let you play in this area :o of the control process. Bad things can happen.

(;-) TP
Vmax549
 
Posts: 1043
Joined: Sun Nov 22, 2015 3:25 am
Location: USA

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

Next

Return to Macros

Who is online

Users browsing this forum: No registered users and 2 guests