Solved

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

Posted on 2006-11-08
7
463 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
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
WebBrowser Control - ms/ACCESS 9 34
Dateadd 3 22
Search field on a form 7 17
Language DLL error in Access 2010 2 12
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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…

746 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

12 Experts available now in Live!

Get 1:1 Help Now