CompuServe Thread

#Arexx timer help

11 messages in this thread
#43102From: Charles CollinsonOct 13, 1994 7:36 AM
I'm looking for some help with AREXX. As of yet I've not tried anything with AREXX but now find I'm in need of a script or some help in knowing which commands I want. What I need is a script that counts seconds and for every second do a loop. Has anyone got a script that counts time (seconds) or can anyone point me in the right direction for commands to write this myself. Finally, are there any AREXX script files/program to be found in the Libs. I've looked here to no avail so they must be somewhere else – but where? Thanks for any help. Charles Collinson – Co-ordinated Computer Integration Thirsk – North Yorkshire – UK
#43104From: Jim ButterfieldOct 13, 1994 8:34 AM
A little more information about your objective could be useful. Is the ARexx program to run free-standing? (That is, not connected to any other application's ARexx port)? How precise is the 1-second timing to be? Couuld it be allowed to drift a little, so that you might have, say, 58 or 62 events in a minute, or must it be locked to a timer? Anyway, here are some of the tools you will find useful for the activity you describe: Built-in function TIME(): when used in the form t=time('r') or t=time('e'), will report time elapsed in seconds/hundredthseconds (s.cc) since the last reset [last call to time('r')]. You can get quite precise timing from this, but if you wait in a loop [ DO WHILE time('e') < 1 ] you will be wasting the Amiga's processing time as you do so. You can also hook TIME() to the real-time clock: TIME('s') will return the integer number of seconds elapsed since midnight. Support function DELAY(): will 'sleep' the ARexx application for a selected number of 'ticks' (a tick being 1/50 second). Thus, CALL DELAY(50) will sleep this application for 1 second. Note that if you do significant processing work after awakening, a following DELAY(50) will make the total timing somewhat over 1 second. –Jim
#43108From: Charles CollinsonOct 13, 1994 6:15 PM
The reason for using ARexx is that the authoring system I'm using doesn't have a timer that works for my needs. In short, it halts whenever I do anything else in the program. I was thinking that an ARexx script could cover this area somehow, it may also help me overcome the problem from within the authoring system. Initially, as I haven't really sat down on this one, I was looking to have an ARexx script/program running counting the seconds (for elapsed time), from this I would somehow run a script on every second to update the authoring program. I'm aware of the time delays due to the script execution and this would have to be worked so the time was something like precise, I'm looking to time an hour on average so the time could only be out by a few seconds, certainly not a whole minute. I would assume by hooking the TIME() to the built-in clock it would cover the time loss but only update every few seconds due to the "loop" execution, which isn't a great loss. I'm also unsure as to whether an ARexx script accessing a application port slows the script down much – does it (arexx script) wait for some unseen return message everytime it executes an application command line from within the arexx script? I hope this helps a little further. I haven't sat down and looked at it as I haven't got any commands for ARexx to try. I'm just looking for a timer that outputs a value to an application port and/or also tells the apllication to do something etc. By "loop" I'm meaning send application port commands on every second (or measured time). Thanks for your help I'll look closer at the commands you've given me. Charles Collinson – Co-ordinated Computer Integration Thirsk – North Yorkshire – UK
#43112From: Bill HawesOct 14, 1994 6:57 AM
Charles, When ARexx sends a command to an application, it waits for a reply so it can report success/failure and take appropriate action. For your timing program you'll probably want to comute the slepp interval for the delay() function based on how long the application commands typically take. After the applciation script returns, you can check the current time and then compute how many ticks remain to until the next planned application command. This will keep your timing loop from drifting to far from schedule. (As long as the application script takes only a brief amount of time to run.) -Bill
#43119From: Charles CollinsonOct 14, 1994 5:35 PM
Bill, Thanks for the help, I think your suggestion is the one to go for if I can't get the systems timers to work better for my purposes. In truth I'm really trying to count a minute so I could quite easily use an equal amount of seconds to complete the timer update. It is food for thought. I also think a good book on ARexx is another good move. Charles Collinson – Co-ordinated Computer Integration Thirsk – North Yorkshire – UK
#43127From: Charles BlaquiereOct 15, 1994 1:07 PM
Jim, to follow up on your idea, I do the following: Initialization: use TIME() and store the last digit into X loop until last digit of TIME() <> X /* this means you just started a brand new second */ Main loop: use DELAY() to wait, ohhh, .8 second or so store the last digit of TIME() into X loop until last digit of TIME() <> X do your processing Basically, you want to trim the .8 seconds to ensure the rest of the loop can execute every single time without making an entire loop iteration last more than 1 second. A smaller DELAY() value would help if the other instructions took up too much time. Blaq!
#43167From: Bill HawesOct 17, 1994 7:23 AM
Looping until a certain time() value comes around will burn processor cycles. It would be preferable to calculate a delay value (ticks = seconds * 50) and call delay() instead of looping. -Bill
#43178From: Charles BlaquiereOct 17, 1994 8:25 PM
I agree that looping would burn some time, which is why I would use delay() for most, but not all, of the delay. I assumed a more general case, where processing time for each iteration could not be precisely specified. The CPU load might be higher or lower, causing processing (not delay()) to take more time, and throw off the timing. This is why, every time the loop iterates, I start with a gross delay(), followed by fine-tuning in the form of a "wait until _exactly_ one second since last loop". Blaq!
#43471From: Ken CooperOct 24, 1994 5:17 AM
Hi Charles, Here's an Arexx program I wrote that might help you. Put a line in your program such as: "run Clock.rexx". Also add a few setclip()'s for various items (see the ERROR section). Edit the Clock program to send whatever command to your 'PORT' name… —————- /* Clock.rexx by Ken Cooper Sep-18-1994 */ options results signal on ERROR call setclip('ClockStatus','Waiting') WaitMin = getclip('ClockTime') WaitSec = WaitMin * 60 if WaitMin > '0' then do forever if getclip('Clock') ~= 'Run' then break LastSec = getclip('ClockLast') if LastSec = '' then break if LastSec + WaitSec > time('s') then , call delay(((LastSec + WaitSec) – time('s')) * 50) LastSec = getclip('ClockLast') if LastSec = '' then break if LastSec + WaitSec > time('s') then call delay(WaitSec * 50) else do if show("P","HOST") then do if getclip('Clock') = 'Run' then do call SendParsed('PORT','ClockSave') call setclip('ClockLast',time('s')) end else signal ERROR end else signal ERROR end end ERROR: call setclip('ClockStatus') call setclip('ClockTime') call setclip('ClockLast') call setclip('Clock') exit
#43183From: Jim ButterfieldOct 18, 1994 8:48 AM
Just out of curiosity: would ADDRESS COMMAND 'WAIT UNTIL 21:15' .. sleep the process correctly? –Jim
#43234From: Bill HawesOct 19, 1994 7:03 AM
Jim, Yes, ARexx waits until the command returns in order to provide an RC value. Thus an external WAIT command will suspend execution without burning CPU cycles. There's a little more overhead to issuing an external command, so the delay() function is preferable for short timing intervals. -Bill