Executing Instruction once every second 
Author Message
 Executing Instruction once every second

Using tcl 7.5 (as it is expect that we have).

Suppose I have a loop (in  a proc)

while { $i <=100 } {
   instruction1
   instruction2
       :
       :
   instructionN

Quote:
}

I want instruction1...instructionN only run once every second. I can't put a
sleep 1 as that puts the loop time to over a sec as
instruction1...instructionN take some time to execute (always observed to be
< 1sec). So, it's almost like I want to be able to time
instruction1...instructionN and sleep for (1 - time for
instruction1...instructionN ) each loop.

Knowing tcl there usually is a better, cleaner way of doing things.

Thanks for your help.



Sun, 25 Apr 2004 21:57:46 GMT  
 Executing Instruction once every second

Quote:

> Using tcl 7.5 (as it is expect that we have).

> Suppose I have a loop (in  a proc)

global MoveOn

Quote:
> while { $i <=100 } {

after 100 set MoveOn 1

Quote:
>    instruction1
>    instruction2
>        :
>        :
>    instructionN

vwait MoveOn

Quote:
> }

or

Quote:
> while { $i <=100 } {

set res [time {

Quote:
>    instruction1
>    instruction2
>        :
>        :
>    instructionN
}]

after [expr 1000 - [lindex $res 0]]

Quote:
> }

depending on the remainder of your script (i.e. other event handlers present)
one method may be preferable to the other

Bruce

PS - one of those instructions better be increasing i   8^)



Sun, 25 Apr 2004 22:54:18 GMT  
 Executing Instruction once every second
I tried this. I get an error when I use the after command (tcl 7.4). Looking
at the tcl man pages, it looks like you need to have events enabled to use
after. So I tried using update and vwait (per the main page) to enable
events, but that didn't work either.

Using the method you described below I can determine how many microseconds
the loop body takes to execute. Now, I can't get it to sleep for the
remainder of the second.


Quote:




Quote:
> > Using tcl 7.5 (as it is expect that we have).

> > Suppose I have a loop (in  a proc)

> global MoveOn

> > while { $i <=100 } {

> after 100 set MoveOn 1

> >    instruction1
> >    instruction2
> >        :
> >        :
> >    instructionN

> vwait MoveOn

> > }

> or

> > while { $i <=100 } {

> set res [time {

> >    instruction1
> >    instruction2
> >        :
> >        :
> >    instructionN

> }]
> after [expr 1000 - [lindex $res 0]]

> > }

> depending on the remainder of your script (i.e. other event handlers
present)
> one method may be preferable to the other

> Bruce

> PS - one of those instructions better be increasing i   8^)



Mon, 26 Apr 2004 00:59:27 GMT  
 Executing Instruction once every second

Quote:

> I tried this. I get an error when I use the after command (tcl 7.4). Looking
> at the tcl man pages, it looks like you need to have events enabled to use
> after. So I tried using update and vwait (per the main page) to enable
> events, but that didn't work either.

> Using the method you described below I can determine how many microseconds
> the loop body takes to execute. Now, I can't get it to sleep for the
> remainder of the second.

Your original post claimed version 7.5 and those man pages say that after/vwait exist
I don't have access to 7.4 pages but it appears they don't have them
You mention that you are using expect ? if so, it has a sleep command
that takes decimal seconds so
use the time method, followed  by
    sleep [expr (1000.0 - [lindex $res 0]) / 1000.0]
instead of the "after" command

Bruce



Mon, 26 Apr 2004 01:28:11 GMT  
 Executing Instruction once every second
I get an error saying sleep expected an integer.


Quote:




Quote:
> > I tried this. I get an error when I use the after command (tcl 7.4).
Looking
> > at the tcl man pages, it looks like you need to have events enabled to
use
> > after. So I tried using update and vwait (per the main page) to enable
> > events, but that didn't work either.

> > Using the method you described below I can determine how many
microseconds
> > the loop body takes to execute. Now, I can't get it to sleep for the
> > remainder of the second.

> Your original post claimed version 7.5 and those man pages say that
after/vwait exist
> I don't have access to 7.4 pages but it appears they don't have them
> You mention that you are using expect ? if so, it has a sleep command
> that takes decimal seconds so
> use the time method, followed  by
>     sleep [expr (1000.0 - [lindex $res 0]) / 1000.0]
> instead of the "after" command

> Bruce



Mon, 26 Apr 2004 08:34:16 GMT  
 Executing Instruction once every second
Are you SURE you are running expect ?
Quote:

> I get an error saying sleep expected an integer.





> > > I tried this. I get an error when I use the after command (tcl 7.4).
> Looking
> > > at the tcl man pages, it looks like you need to have events enabled to
> use
> > > after. So I tried using update and vwait (per the main page) to enable
> > > events, but that didn't work either.

> > > Using the method you described below I can determine how many
> microseconds
> > > the loop body takes to execute. Now, I can't get it to sleep for the
> > > remainder of the second.

> > Your original post claimed version 7.5 and those man pages say that
> after/vwait exist
> > I don't have access to 7.4 pages but it appears they don't have them
> > You mention that you are using expect ? if so, it has a sleep command
> > that takes decimal seconds so
> > use the time method, followed  by
> >     sleep [expr (1000.0 - [lindex $res 0]) / 1000.0]
> > instead of the "after" command

> > Bruce



Mon, 26 Apr 2004 19:13:04 GMT  
 Executing Instruction once every second


Quote:
> Are you SURE you are running expect ?


>> > use the time method, followed  by
>> >     sleep [expr (1000.0 - [lindex $res 0]) / 1000.0]
>> > instead of the "after" command

>> > Bruce

there is a good chance he does.

man expect:
EXPECT(1)                                               EXPECT(1)

NAME
       expect  -  programmed  dialogue with interactive programs,
       Version 5
....
       sleep seconds
             causes the script to sleep for the given  number  of
             seconds.   Seconds  may be a decimal number.  Inter-
             rupts (and Tk events if you are using  Expectk)  are
             processed while Expect sleeps.
....
                        29 December 1994                      31

G!
UK
--

KLEIN MESSGERAETE Habertwedt 1
D-24376 Groedersby b. Kappeln, GERMANY
phone: +49 4642 920 123 FAX: +49 4642 920 125



Mon, 26 Apr 2004 20:52:01 GMT  
 Executing Instruction once every second


Quote:
> Are you SURE you are running expect ?

Yes. Version 5.2

expect1.2> puts $tcl_version
7.4
expect1.3> sleep .1
expected unsigned integer but got ".1"
    while executing
"sleep .1"
expect1.4>

Quote:




Quote:
> > I get an error saying sleep expected an integer.





> > > > I tried this. I get an error when I use the after command (tcl 7.4).
> > Looking
> > > > at the tcl man pages, it looks like you need to have events enabled
to
> > use
> > > > after. So I tried using update and vwait (per the main page) to
enable
> > > > events, but that didn't work either.

> > > > Using the method you described below I can determine how many
> > microseconds
> > > > the loop body takes to execute. Now, I can't get it to sleep for the
> > > > remainder of the second.

> > > Your original post claimed version 7.5 and those man pages say that
> > after/vwait exist
> > > I don't have access to 7.4 pages but it appears they don't have them
> > > You mention that you are using expect ? if so, it has a sleep command
> > > that takes decimal seconds so
> > > use the time method, followed  by
> > >     sleep [expr (1000.0 - [lindex $res 0]) / 1000.0]
> > > instead of the "after" command

> > > Bruce



Mon, 26 Apr 2004 23:37:31 GMT  
 Executing Instruction once every second

Quote:



> > Are you SURE you are running expect ?

> Yes. Version 5.2

> expect1.2> puts $tcl_version
> 7.4
> expect1.3> sleep .1
> expected unsigned integer but got ".1"
>     while executing
> "sleep .1"
> expect1.4>

Expect's sleep command do accept decimal values -- don't know about
expect5.2 version though. Also, Tclx's sleep command accepted only
integer values (until very recently). So, if you are also using Tclx
package, it is possible that you are invoking Tclx's sleep command. To
be sure that you are invoking expect's sleep command, try with exp
prefix:

  exp_sleep .1

If this still fails, then most probably expect version 5.2 didn't
support this.

Hemang.



Tue, 27 Apr 2004 00:45:56 GMT  
 Executing Instruction once every second


<delete>

Quote:
>   exp_sleep .1

> If this still fails, then most probably expect version 5.2 didn't
> support this.

> Hemang.

That did the trick. Thanks to both you and Bruce.


Thu, 29 Apr 2004 06:52:34 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Running a proc once every n seconds

2. every so-many seconds execute?

3. update every second or every resched()?

4. view data continuously but only record every x seconds

5. How to update a texture every second?

6. script for every few seconds

7. Every 10 seconds?

8. execute code every set time

9. Execute code after every tcl command?

10. AI Read is executing only once in a while loop instead of continuously scanning the channels

11. How Can I Ensure a Script Only Executes Once

12. How to execute multiple tcl scripts at once

 

 
Powered by phpBB® Forum Software