|
| Author |
Message |
Nikolaos Skordos
Joined: 04 Oct 2007 Posts: 10
|
Posted: Wed Jun 09, 2004 4:35 pm Post subject: Timers and DoEvents |
|
|
Hello all!
Can someone please help me with this:
When my application loads, it starts a timer (Timer1). This timer procedure
checks for inputs with an interval of 10. In my PC I have a digital I/O
card, which offers controls for VB programming. So as to give you an example
the Timer procedure looks something like:
Private Sub Timer1_Timer()
....
if Di1.ByteInput = 8 Then '---Digital Input port 1---
etc. (A)
End If
....
End Sub
Now, in another part of my code I have a 'wait' condition, implemented like:
Do
DoEvents
Loop Until EOF(1)
My question is...When the program gets into that Loop (in which it may stay
for a while), will the Timer keep working? Will the program be able to
execute the code marked with (A) or will it wait for the loop to finish?
Thank you very much in advance
Nikolaos Skordos
Kouvalias Robotics
Archived from group: microsoft>public>vb>com |
|
| Back to top |
|
 |
J French
Joined: 04 Oct 2007 Posts: 191
|
Posted: Wed Jun 09, 2004 2:31 pm Post subject: Re: Timers and DoEvents |
|
|
Inline :-
On Wed, 9 Jun 2004 12:35:11 +0300, "Nikolaos Skordos"
wrote:
>Hello all!
>Can someone please help me with this:
>
>When my application loads, it starts a timer (Timer1). This timer procedure
>checks for inputs with an interval of 10. In my PC I have a digital I/O
>card, which offers controls for VB programming. So as to give you an example
>the Timer procedure looks something like:
>
>Private Sub Timer1_Timer()
>...
>if Di1.ByteInput = 8 Then '---Digital Input port 1---
> etc. (A)
>End If
>...
>End Sub
>
>Now, in another part of my code I have a 'wait' condition, implemented like:
>
>Do
WaitMessage ' API - reduces CPU waste
> DoEvents
>Loop Until EOF(1)
>
>My question is...When the program gets into that Loop (in which it may stay
>for a while), will the Timer keep working?
Yes
>Will the program be able to
>execute the code marked with (A) or will it wait for the loop to finish?
Once VB is executing a bit of code it doggedly continues doing so, and
blocks all input /unless/ you put in a DoEvents
(There are a few nit picking exceptions to that, but they are only
really things that are putting in a DoEvents behind the scenes)
Also I am not convinced that a Timer interval of 10 will really work
- Timer events are fired with IIRC a granularity of 18 per second as
they work off the historic clock
(please someone correct me if I am wrong)
>Thank you very much in advance
>Nikolaos Skordos
>Kouvalias Robotics
>
> |
|
| Back to top |
|
 |
MikeD
Joined: 04 Oct 2007 Posts: 3348
|
Posted: Wed Jun 09, 2004 12:58 pm Post subject: Re: Timers and DoEvents |
|
|
"Nikolaos Skordos" wrote in message$1gdb$1@ulysses.noc.ntua.gr...
> Hello all!
> Can someone please help me with this:
>
> When my application loads, it starts a timer (Timer1). This timer
procedure
> checks for inputs with an interval of 10. In my PC I have a digital I/O
> card, which offers controls for VB programming. So as to give you an
example
> the Timer procedure looks something like:
>
> Private Sub Timer1_Timer()
> ...
> if Di1.ByteInput = 8 Then '---Digital Input port 1---
> etc. (A)
> End If
> ...
> End Sub
>
> Now, in another part of my code I have a 'wait' condition, implemented
like:
>
> Do
> DoEvents
> Loop Until EOF(1)
>
> My question is...When the program gets into that Loop (in which it may
stay
> for a while), will the Timer keep working? Will the program be able to
> execute the code marked with (A) or will it wait for the loop to finish?
I'm not trying to discourage asking questions, but it seems to me the best
way to get an answer to *this* question would be to just test it, possibly
putting a breakpoint on an appropriate line of code in the Timer event.
Mike
P.S. Verify your cross-post list. You included
"microsoft.public.vb.general", which is not a valid newsgroup name. |
|
| Back to top |
|
 |
MikeD
Joined: 04 Oct 2007 Posts: 3348
|
Posted: Wed Jun 09, 2004 1:24 pm Post subject: Re: Timers and DoEvents |
|
|
"Duane Bozarth" wrote in message@swko.dot.net...
> Nikolaos Skordos wrote:
> >
> ...followups trimmed to at least semi-appropriate groups...
Not usually a good idea unless the newsgroups are totally inappropriate.
Now, anyone that was following this thread in either of the newsgroups
you've omitted (microsoft.public.vb.com and microsoft.public.vb.enterprise)
is following an "incomplete" discussion. And you didn't omit the one
newsgroup that's not even a valid newsgroup.
Mike
P.S. I added the omitted newsgroups back and quoted your entire post so
people reading in those newsgroups can follow.
>
> comments inline...
>
> > When my application loads, it starts a timer (Timer1). This timer
procedure
> > checks for inputs with an interval of 10. ...
>
> See notes on "Using Timer..." quoted at end of response--you'll not
> necessarily get this resolution so if precise timing is significant
> you'll need to use an API, not the Timer control.
>
>
> > Private Sub Timer1_Timer()
> > ...
> > if Di1.ByteInput = 8 Then '---Digital Input port 1---
> ...
>
> I'd suggest you not test for equality here unless you have tied all
> other 7 inputs low...unless of course, you really looking for the
> precise condition of only the one bit set...if you are instead
> interested in when bit 8 is set irrespective of the state of the others,
> use the "And" operator with the mask.
>
> I'd also make a named constant to use in the code for the bit mask so I
> could group them somewhere and then if the hardware wiring changed not
> have to find them everywhere in the code...
>
> Const WidgetWalk = &H8 ' I use hex for bit masks to make them more
> visual
>
> If Di1.ByteInput And WidgetWalk = WidgetWalk Then
>
> or, equivalently from a operational standpoint but a logical test..
>
> If Di1.ByteInput And WidgetWalk Then
>
>
> > Now, in another part of my code I have a 'wait' condition, implemented
like:
> >
> > Do
> > DoEvents
> > Loop Until EOF(1)
> ...
> > My question is...When the program gets into that Loop (in which it may
stay
> > for a while), will the Timer keep working? Will the program be able to
> > execute the code marked with (A) or will it wait for the loop to finish?
>
> I'd recommend another timer as less resource-intensive...but, that
> aside, the timer will fire with the following caveats from the VB help
> files...
>
> · If your application or another application is making heavy demands on
> the system - such as long loops, intensive calculations, or drive,
> network, or port access - your application may not get timer events as
> often as the Interval property specifies.
> · The interval can be between 0 and 64,767, inclusive, which means that
> even the longest interval can't be much longer than one minute (about
> 64.8 seconds).
> · The interval is not guaranteed to elapse exactly on time. To ensure
> accuracy, the timer should check the system clock when it needs to,
> rather than try to keep track of accumulated time internally.
> · The system generates 18 clock ticks per second - so even though the
> Interval property is measured in milliseconds, the true precision of an
> interval is no more than one-eighteenth of a second.
>
> In practice, how well this will work will depend on the system loading
> and how much processing you're doing on each data event and how critical
> precise timing really is. If it's a very tight control loop with
> derivative control, you're probably not going to get great performance.
> If you're just monitoring, it'll probably be fine unless you need the
> absolute granularity for post-processing (as in time-series analysis
> with delay/phase relationships, for example)... |
|
| Back to top |
|
 |
Dick Grier
Joined: 04 Oct 2007 Posts: 272
|
Posted: Wed Jun 09, 2004 12:50 pm Post subject: Re: Timers and DoEvents |
|
|
Hi,
>>
Also I am not convinced that a Timer interval of 10 will really work
- Timer events are fired with IIRC a granularity of 18 per second as
they work off the historic clock
(please someone correct me if I am wrong)
<<
An Interval of 10 will work under Windows XP (and, I suppose Windows Server
2003).
Dick
--
Richard Grier (Microsoft Visual Basic MVP)
See www.hardandsoftware.net for contact information.
Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002. |
|
| Back to top |
|
 |
Peter Young
Joined: 04 Oct 2007 Posts: 28
|
Posted: Wed Jun 09, 2004 2:12 pm Post subject: Re: Timers and DoEvents |
|
|
"MikeD" wrote in message @TK2MSFTNGP11.phx.gbl...
>
> "Duane Bozarth" wrote in message
> @swko.dot.net...
> > Nikolaos Skordos wrote:
> > >
> > ...followups trimmed to at least semi-appropriate groups...
>
>
> Not usually a good idea unless the newsgroups are totally inappropriate.
> Now, anyone that was following this thread in either of the newsgroups
> you've omitted (microsoft.public.vb.com and microsoft.public.vb.enterprise)
> is following an "incomplete" discussion. And you didn't omit the one
> newsgroup that's not even a valid newsgroup.
>
> Mike
>
> P.S. I added the omitted newsgroups back and quoted your entire post so
> people reading in those newsgroups can follow.
Good thinking Mike.
-Pete |
|
| Back to top |
|
 |
Bob O`Bob
Joined: 04 Oct 2007 Posts: 1456
|
Posted: Wed Jun 09, 2004 1:48 pm Post subject: Re: Timers and DoEvents |
|
|
MikeD wrote:
> P.S. I added the omitted newsgroups back and quoted your entire post so
> people reading in those newsgroups can follow.
That's debateable.
Not being on msnews does NOT mean there aren't OTHER servers
carrying "microsoft.public.vb.general"
Bob |
|
| Back to top |
|
 |
Jeff Johnson [MVP: VB]
Joined: 04 Oct 2007 Posts: 1672
|
Posted: Wed Jun 09, 2004 7:26 pm Post subject: Re: Timers and DoEvents |
|
|
"Bob O`Bob" wrote in message@yahoogroups.com...
> Not being on msnews does NOT mean there aren't OTHER servers
> carrying "microsoft.public.vb.general"
Triple negatives make my brain hurt. |
|
| Back to top |
|
 |
Rick Rothstein
Joined: 04 Oct 2007 Posts: 1589
|
Posted: Wed Jun 09, 2004 8:17 pm Post subject: Re: Timers and DoEvents |
|
|
> > Not being on msnews does NOT mean there aren't OTHER servers
> > carrying "microsoft.public.vb.general"
>
> Triple negatives make my brain hurt.
Not that that is not the unintended outcome.
Rick |
|
| Back to top |
|
 |
Larry Serflaten
Joined: 04 Oct 2007 Posts: 2644
|
Posted: Wed Jun 09, 2004 8:41 pm Post subject: Re: Timers and DoEvents |
|
|
"Rick Rothstein" wrote
> > > Not being on msnews does NOT mean there aren't OTHER servers
> > > carrying "microsoft.public.vb.general"
> >
> > Triple negatives make my brain hurt.
>
> Not that that is not the unintended outcome.
That reminds me of a brain teaser I learned as a child:
What grammatically correct sentence can you think of that contains the
greatest number of repetitions of a single word?
Your sentence repeats "that" twice. That "that that" made your sentence
a contender. But my previous sentence included 3....
What is the greatest number you can achieve?
LFS |
|
| Back to top |
|
 |
Gale Green
Joined: 04 Oct 2007 Posts: 136
|
Posted: Thu Jun 10, 2004 2:52 am Post subject: Re: Timers and DoEvents |
|
|
On Wed, 9 Jun 2004 16:41:56 -0500, "Larry Serflaten"
wrote:
> That reminds me of a brain teaser I learned as a child:
>
> What grammatically correct sentence can you think of that contains the
> greatest number of repetitions of a single word?
>
> Your sentence repeats "that" twice. That "that that" made your sentence
> a contender. But my previous sentence included 3....
>
> What is the greatest number you can achieve?
"Please pass the but but but but but butter," stammered Peter.
Gale. |
|
| Back to top |
|
 |
MikeD
Joined: 04 Oct 2007 Posts: 3348
|
Posted: Wed Jun 09, 2004 10:07 pm Post subject: Re: Timers and DoEvents |
|
|
"Larry Serflaten" wrote in message%23mGomTEHA.3332@TK2MSFTNGP12.phx.gbl...
>
> "Rick Rothstein" wrote
> > > > Not being on msnews does NOT mean there aren't OTHER servers
> > > > carrying "microsoft.public.vb.general"
> > >
> > > Triple negatives make my brain hurt.
> >
> > Not that that is not the unintended outcome.
>
>
> That reminds me of a brain teaser I learned as a child:
>
> What grammatically correct sentence can you think of that contains the
> greatest number of repetitions of a single word?
>
> Your sentence repeats "that" twice. That "that that" made your sentence
> a contender. But my previous sentence included 3....
>
> What is the greatest number you can achieve?
Hell, I've probably written hundreds of sentences in newsgroups posts that
could be contenders. In fact, sometimes during proofreading, I
deliberately change wording (and even sentence structure, such as breaking
one long sentence into 2 or more shorter ones) because I think "I've used
such and such word way too many times in that sentence". That's not a joke.
I'm serious.
Actually, Bob's sentence uses "not" 3 times, if you break up the
contraction. It's not grammatically correct, though, so I guess it's
disqualified.
Mike |
|
| Back to top |
|
 |
Karl E. Peterson
Joined: 04 Oct 2007 Posts: 4836
|
Posted: Wed Jun 09, 2004 7:12 pm Post subject: Re: Timers and DoEvents |
|
|
Larry Serflaten wrote:
> Your sentence repeats "that" twice. That "that that" made your sentence
> a contender. But my previous sentence included 3....
>
> What is the greatest number you can achieve?
That "that that" that you cite isn't that bad...
--
[Microsoft Basic: 1976-2001, RIP] |
|
| Back to top |
|
 |
Bob Butler
Joined: 04 Oct 2007 Posts: 2047
|
Posted: Wed Jun 09, 2004 7:28 pm Post subject: Re: Timers and DoEvents |
|
|
"Gale Green" wrote in message@4ax.com
> On Wed, 9 Jun 2004 16:41:56 -0500, "Larry Serflaten"
> wrote:
>
>> That reminds me of a brain teaser I learned as a child:
>>
>> What grammatically correct sentence can you think of that contains
>> the greatest number of repetitions of a single word?
>>
>> Your sentence repeats "that" twice. That "that that" made your
>> sentence a contender. But my previous sentence included 3....
>>
>> What is the greatest number you can achieve?
>
> "Please pass the but but but but but butter," stammered Peter.
I think that that "that that" that that sentence had was a good example.
--
Reply to the group so all can participate
VB.Net... just say "No" |
|
| Back to top |
|
 |
Gale Green
Joined: 04 Oct 2007 Posts: 136
|
Posted: Thu Jun 10, 2004 3:35 am Post subject: Re: Timers and DoEvents |
|
|
On Wed, 9 Jun 2004 15:28:26 -0700, "Bob Butler"
wrote:
> I think that that "that that" that that sentence had was a good example.
>
Very good; I like that.
|
|
| Back to top |
|
 |
|