Page 1 of 1

Dro on screen and macroloop

PostPosted: Sun Sep 18, 2022 11:51 pm
by mark4
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

Re: Dro on screen and macroloop

PostPosted: Tue Sep 20, 2022 9:09 am
by Battwell
toolno = toolno + 1;

change to

toolno = (toolno + 1);

Re: Dro on screen and macroloop

PostPosted: Tue Sep 20, 2022 6:34 pm
by dezsoe
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;

Re: Dro on screen and macroloop

PostPosted: Thu Sep 22, 2022 1:26 am
by mark4
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

Re: Dro on screen and macroloop

PostPosted: Thu Oct 27, 2022 4:17 pm
by mark4
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