Dro on screen and macroloop

If you have a question about the software please ask it here.

Dro on screen and macroloop

Postby mark4 » Sun Sep 18, 2022 11:51 pm

Hello
I have been trying to get this piece of code to work.
This is going to be a tool changer script but i cant get out of the barn
first i need a dro on the screen. I went into screen editor and made this
screen editor.png


Then i made a Macro. Actually i recieved some help and didnt write the macro
I tried very hard to make it work.

It is saved as m20800
while(loop)
{
int toolno = Getfield(20800); // Get current value of field

if GetLED(503); // If the LED for the sensor input is active...
{
SetLED(true,504);
toolno = toolno + 1; // When the sensor is triggered, add 1 to the tool number.
AS3.Setfield( toolno, 20800);
AS3.Validatefield (20800);
}
Thread.Sleep(50);
}

The goal is to have the dro count one when led 503 goes on.
Instead all i get is a compiler error.
here is where I am lost.
1st what number should the field for this type of dro be?
The number cannot be a defined field as far as I know. and that means user number. I have read nothing to suggest what that range is or should be
Do I name the macro the same number as the dro ?
I have tried many different combinations with no progress.
All I get is
UCCNC macro compiler error log file
--------------------------------------
Last error dated: 9/18/2022 9:39:13 AM
In macro: M30000
--------------------------------------
CS1003 | in line: 19 | error text: Syntax error, '(' expected
CS1026 | in line: 19 | error text: ) expected

not one thing i have done has made this go away. Please help
Thank you
Mark
mark4
 
Posts: 26
Joined: Tue May 24, 2022 3:55 am

Re: Dro on screen and macroloop

Postby Battwell » Tue Sep 20, 2022 9:09 am

toolno = toolno + 1;

change to

toolno = (toolno + 1);
Uc300eth on router and mill.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 867
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: Dro on screen and macroloop

Postby dezsoe » Tue Sep 20, 2022 6:34 pm

There's no problem with that line. The problem is that you must use () after the if statement and do not use ; at the end of that line. I made some other changes too:

Code: Select all
int toolno = AS3.Getfieldint(20800); // Get current value of field

if (exec.GetLED(503)) // If the LED for the sensor input is active...
{
  exec.SetLED(true,504);
  ++toolno; // When the sensor is triggered, add 1 to the tool number.
  AS3.Setfield((double)toolno, 20800);
  AS3.Validatefield(20800);
}

You don't need the while(loop) in a macroloop, because your macro is compiled into a while(loop) cycle. You also don't need the 50 ms sleep, because the macroloop sleeps 50 ms itself. AS3.Getfieldint returns an integer and after you change it you have to set the field as a text or a double, so I casted the int to double in the Setfield line.

However, this macroloop will not do what you want. This will increase your field in every 50 ms while the input is active, so you have to program a trigger to detect the level change:

Code: Select all
int toolno = AS3.Getfieldint(20800); // Get current value of field

bool currentstate = exec.GetLED(503);

if (currentstate != laststate)
{
  // The state changed here
  if (currentstate) // If the LED for the sensor input is active...
  {
    // The input changed and is on -> off to on trigger
    exec.SetLED(true,504);
    ++toolno; // When the sensor is triggered, add 1 to the tool number.
    AS3.Setfield((double)toolno, 20800);
    AS3.Validatefield(20800);
  }
  laststate = currentstate; // Save current state for later compare
}

#Events

bool laststate = false;
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Dro on screen and macroloop

Postby mark4 » Thu Sep 22, 2022 1:26 am

Thank you!!
I have tried many many things to make that work.
Finally this morning it counted.
now i have to make it into a tool Changer
Mark
mark4
 
Posts: 26
Joined: Tue May 24, 2022 3:55 am

Re: Dro on screen and macroloop

Postby mark4 » Thu Oct 27, 2022 4:17 pm

Hello
The Dro now reads out from 1 to 22
And i figured out how to make it count down with --
The next thing i need it to do is count from 1 to 22 then start over from 1
or if it is counting 22 to 1 to start over at 22

Count direction needs to change with output
if output y305 is on when the prox X411 triggers the dro counts up 1
if output y306 is on when the prox x411 triggers the dro counts down 1

I do not know how to add that condition
Thank you
Mark
mark4
 
Posts: 26
Joined: Tue May 24, 2022 3:55 am


Return to Ask a question from support here

Who is online

Users browsing this forum: No registered users and 46 guests