DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3
  1. #1
    JeffT Guest

    Independent timer/dwell within an object

    I have created an AXIS object in my motion control project. I am commanding
    an axis to move to a certain position. I need to asynchronously dwell for
    some period of time then check to make sure the axis is were it should be.
    If not, I need to post a "time out" alarm. I will command multiple axis'
    to move at once and, depending on the distance to move, they will have different
    time out values. How can I start a timer within an object without blocking
    the processor. I tried a loop with DoEvents and sleep but this didn't work.
    The last axis commanded to move needs to finish before previous axis' can

  2. #2
    Dick Grier Guest

    Re: Independent timer/dwell within an object


    What you want to do is to use a Timer (object). If the standard VB Timer
    resolution (55 mS) is sufficient, then you can place on a form, instantiate
    it from within your class, and use the Timer event that it generates

    However, you may get more out of using a high-resolution timer like Karl
    Peterson's (www.mvps.org/vb and www.mvps.org/ccrp -- these are two different
    implementations, based on the same basic concepts).

    Richard Grier (Microsoft Visual Basic MVP)
    Hard & Software
    12962 West Louisiana Avenue
    Lakewood, CO 80228
    303-986-2179 (voice)
    303-986-3143 (fax)
    Author of Visual Basic Programmer's Guide to Serial Communications, 2nd
    Edition ISBN 1-890422-25-8 (355 pages).
    For information look on my homepage at http://www.hardandsoftware.net.
    Use the Books link to order. For faster service contact the publisher at

  3. #3
    martin.rydman Guest

    Re: Independent timer/dwell within an object

    Hi Jeff!

    You can also use this technique (I've got it from Dan Appleman)

    In a bas-module, put this:

    Attribute VB_Name = "mdlTimer"
    '****** Project FileListServer ActiveX EXE ***********
    ' mdlTimer.bas
    ' (Thanks do Dan Appleman)
    'This is how we can launch a long operation. We use a Win32 timer, set it
    'trigger a call to a callback procedure after 1 millisecond, and in the
    'callback procedure (TimerProc in this example), we launch the actual
    'long operation.
    'The StartTimer sub takes an object on which the long operation
    'is called (mobjCallingObject.GetFileArray).

    Option Explicit

    Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal
    nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
    Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal
    nIDEvent As Long) As Long

    Private mobjCallingObject As CFileList
    Private TimerID&

    Public Sub StartTimer(CallingObject As CFileList)
    Set mobjCallingObject = CallingObject
    TimerID = SetTimer(0, 0, 1, AddressOf TimerProc)
    End Sub

    'This is the callback procedure that sets of the parser
    Public Sub TimerProc(ByVal hwnd&, ByVal msg&, ByVal id&, ByVal currenttime&)
    Call KillTimer(0, TimerID) 'This is for one-off launching
    'You might want to keep the timer
    'return here regularly
    TimerID = 0
    Set mobjCallingObject = Nothing
    End Sub

    In your calling class (the one to containing the asynchronous method):

    'This is the trigger for the asynchronous service. It only sets of a
    'Win32 timer that in turn will set of the actual parser
    Public Sub GetAsynchFileArray(Path As String)
    mstrPath = Path
    StartTimer Me
    End Sub

    'This method is called from the callback-procedure in mdlTimer
    Friend Function GetFileArray()
    'Your asyncronous operation
    End Function

    This way, you won't have to add a form to your server to hold the timer.
    Otherwise it's the sam idea as the previous posters.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center