Page 1 of 1

Interrupting a counter

Posted: Mon May 11, 2009 12:02 am
by Glenn Boyce
I have set up a counter and I want to be able to to click on a button and get the count whilst it is still running. at the moment I have to stop the counter. Is there a way I can set the counter to run in the background so that I can still complete other tasks while it is running?

Code: Select all

put "" into tQty
  put "" into gN
  put fld "QTY" - 1 into tqty
  
  if gCompleted <> "" then
    put gCompleted + 1 into tcounter
    else
  put 1 into tcounter
  end if
  set the ustopped of me to false
  --put tqty - gCompleted
  repeat tqty - gCompleted times 
    put "" into gCompleted
  add 1 to tcounter
  wait 0.25 seconds
  put tcounter into N
  
   send "tmUpdateGauge N" to group g6
   put (N / tqty)*100 into gN
  
   send "tmUpdateGauge gN" to group g2
  wait 10 milliseconds with messages
  if the uStopped of me is true then
    put N into gCompleted
  exit repeat
end if
end repeat

Posted: Mon May 11, 2009 7:23 pm
by Mark Smith
If your waits are 'with messages', and it looks like 'gCompleted' is a global, you could put a function in your script:

Code: Select all

function getNumberCompleted
  return gCompleted
end getNumberCompleted
Then, in your button script, you could have

Code: Select all

on mouseUp
  put getNumberCompleted()
end mouseUp
which would put the value into the message box.

Best,

Mark

Posted: Mon May 11, 2009 9:51 pm
by Glenn Boyce
Hi Mark

I tried putting that code into my script and I get an error. Doesn't want to accept it for some reason. Also using gCompleted variable will only work if the counter is stopped. I use that variable to mark the point where I want the counter to restart again. I want to be able to click on a button and take the count as it is at that instant. That number would be in tCounter. I want to do it again a little later so that I am marking the beginning and end of an event. I want to store both numbers in a table and put the difference between them into another column. In the real world the count would be supplied by a machine and the tags represent "bad work" or waste. I want the operators to able to mark this bad work on the fly.
kind regards Glenn

Posted: Mon May 11, 2009 10:59 pm
by bn
Glenn,

if you global tCounter (call it gCounter then)
add with messages to your wait 0.25 seconds
and use Mark's script in a button

Code: Select all

global gCounter
on mouseUp
   put getNumberCompleted() 
end mouseUp

function getNumberCompleted 
  return gCounter 
end getNumberCompleted
it should work. I tried it with a stripped down version of your repeat loop and it worked.
regards
Bernd

Posted: Thu May 14, 2009 2:23 am
by Glenn Boyce
Thank you