Solved

DoEvents, CPU Time, MsComm, and (Timer, Pause, Sleep, Wait)

Posted on 2006-11-08
7
468 Views
Last Modified: 2007-12-19
When using the MsComm control, it's often necessary to send commands to the modem and then wait for a response.

I'm really really confused. In order to better manage my code, I'm using functions and sub programs that get called from here and there. (Sounds like managed code?) But sometimes the results are most unexpected. The problem is that you must pause to wait for responses from the modem, but while pausing, you must accept OnComm events and handle them. After the pause is over, my code checks to the state of some variables that get set during OnComm events.  Am I making sense? So, yes, we need to pause but continue to handle OnComm events. But I don't want any other functions runnning away.

Here's the code I'm using. It is working but the CPU does run high. And I'm not really understanding where I should use DoEvents and where I shouldn't.  Does DoEvents ever need to be run more than one time inside a single procedure?

        'Should I have DoEvents up here?

        comm1.Output = "AT+VCID=1" + vbCr
        subPause (1)



Private Sub subPause(lngHowLong As Long)  
        Dim lngStart As Long
        lngStart = Timer
        DoEvents
        Do While Timer < lngStart + lngHowLong
        Loop
End Sub
0
Comment
Question by:HKComputer
7 Comments
 
LVL 18

Expert Comment

by:Data-Man
ID: 17901270
I normally put the DoEvents inside my loops.

        Do While Timer < lngStart + lngHowLong
             DoEvents
        Loop

Mike

0
 
LVL 39

Expert Comment

by:stevbe
ID: 17907156
the Sleep api works much better than an internal VBA loop

http://www.mvps.org/access/api/api0021.htm
0
 
LVL 4

Author Comment

by:HKComputer
ID: 17907598
I've tried using the Sleep API. But there's something I don't really understand.

        comm1.Output = "AT+VCID=1" + vbCr
        Sleep (1000)

       If bleOK = True Then bleCallerID = True


bleOK will get set to tru if the AT+VCID=1 command returns true from the modem. But in order for this to happen, my comm1.OnComm event must fire and be able to call my ProcessEvent function to read the event data and set variables to true or false accordingly.  But in my tests, when I ran Sleep, my modem events failed to fire until Sleep was finished. At this point, bleOK was always false even if the modem returned an "OK".

Am I missing something here?
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 18

Expert Comment

by:Data-Man
ID: 17909206
I've never worked with modems...you've exceeded my knowledge base.

Mike
0
 
LVL 4

Author Comment

by:HKComputer
ID: 17932032
I stopped using the sleep function because it didn't work as I needed.  It seemed that the Sleep function kept my modem events from ocurring.

I wrote my own pause function. Please see:
http://www.experts-exchange.com/Databases/MS_Access/Q_22050442.html


I'm going to request a close and refund unless there are any objections. -HK
0
 
LVL 1

Accepted Solution

by:
kodiakbear earned 0 total points
ID: 17975471
Closed, 500 points refunded.
kb
Experts Exchange Moderator
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now