Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

Timing between events

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-25-2008, 11:16 PM
Basic4ppc Veteran
 
Join Date: May 2008
Location: Newcastle Upon Tyne - England
Posts: 271
Awards Showcase
Beta Tester 
Total Awards: 1
Default Timing between events

I'm using the Com port as a crude digital input device. I want to time between raising DSR and raising CTS; to an accuracy of 10ms. The time interval may be anything between one and 500 seconds. I'm trying to use the code below with timers to avoid burning CPU cycles but I'm losing track of what I'm doing(!)

Timer 2 and Timer 3 are set to 1ms.
Code:
#Region Timer
Sub TimeEvent
    Port.DTREnable=
True
    WatchDog=HW.GetTickCount
    Timer2.Enabled=
True
    Timer3.Enabled=
True
End Sub

Sub Timer2_Tick
    
If Port.DSR=True Then
        DSRtime=HW.GetTickCount
        Timer2.Enabled=
False
        
Return
    
End If
    
If (HW.GetTickCount-WatchDog)>500 Then
        Timer2.Enabled=
False
        Timer3.Enabled=
False
        Port.DTREnable=
False
        
Msgbox("DSR has not responded; check cable and connections.","Error",cMsgBoxOK,cMsgBoxHand)
    
End If
End Sub

Sub Timer3_Tick
    
If Port.CTS=True Then
        CTStime=HW.GetTickCount
        Timer3.Enabled=
False
        Port.DTREnable=
False
        
Return
    
End If
    
If (HW.GetTickCount-WatchDog)>500000 Then
        Timer2.Enabled=
False
        Timer3.Enabled=
False
        Port.DTREnable=
False
        
Msgbox("CTS has not responded; Check cable and connections.","Error",cMsgBoxOK,cMsgBoxHand)
    
End If
End Sub
#End Region
The time interval is then CTStime-DSRtime, but I don't know where to put it. Ideally, I would also like to be able to call the routine five times with a two second interval between, but because each sequence may be upto 500 seconds long, the CPU has to be free.

Am I missing the point here and be better using:
Code:
Do Until Port.DSR=True
    Sleep(
1)
Loop
But that will lock into that loop for the duration; and I will not be able to update the elapsed time on screen (thats what I'm doing with Timer1)

I hope this makes sense as I'm tying myself in knots as I'm trying to get my problem across.

Last edited by Zenerdiode : 08-25-2008 at 11:19 PM.
Reply With Quote
  #2 (permalink)  
Old 08-26-2008, 06:34 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,733
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

I'm not sure that I understood your program.
However 1ms interval is too short. The tick event is only fired when the cpu is free.
The events will be accumulated and not timed properly.

Can't you update the screen inside the 'Do until' loop?
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
textBox : add TextChanged events or other events abys Code Samples & Tips 1 09-01-2008 06:41 PM
Timing issues leestevens Questions (Windows Mobile) 1 08-08-2008 06:22 PM
rapi events stbi Questions (Windows Mobile) 4 10-22-2007 11:55 AM
more events Sven Kommers Basic4ppc Wishlist 3 06-08-2007 09:53 AM
Image Mouse events LineCutter Basic4ppc Wishlist 1 05-19-2007 10:24 AM


All times are GMT. The time now is 10:18 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0