FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Pocket PC How to stop en endless loop ?
Posts: 48
Joined: Sun Oct 30, 2005 09:29 AM
How to stop en endless loop ?
Posted: Tue Jun 06, 2006 06:52 PM

Hello,

Let me expose the situation of what I need to do:

By pressing on a button, the user will ask the program to start to read the data from a GPS device.

The program then enters into an endless loop that will do the following:
- read the GPS data
- save the data into a file
- wait a few seconds
- loop

To stop the loop, the user will push another button.

How can this be done?

Thanks for any hint.

Best regards, Raymond

Raymond Fischbach
www.mouches.org
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to stop en endless loop ?
Posted: Tue Jun 06, 2006 08:16 PM

Just put something like

IF lStop; EXIT; ENDIF

inside the loop and

ACTION lStop := .T.

in the stop button action.

EMG

Posts: 42
Joined: Sun Oct 09, 2005 11:47 AM
How to stop en endless loop ?
Posted: Wed Jun 07, 2006 12:10 PM

Raymond,
My suggestion is to use a timer function to control the polling of the GPS and read data available. Use a suitable control to enable or disable the timer so as to stop and start the read cycle and a variable to set the timer period.
hth

Posts: 48
Joined: Sun Oct 30, 2005 09:29 AM
How to stop en endless loop ?
Posted: Wed Jun 07, 2006 04:37 PM

Enrico,

I tried your suggestion but I cannot make it work.
As soon as the loop is running, the "Stop" button is disabled.

Jon,

Thank you for the idea.
My problem is that I am NOT
a clipper programmer
a fivewin user
Therefore my knowledge is very poor :(

How can I control a timer? How can I start it? How can I stop it?
Could you please share some code to get me started?

Many thanks in advance.

Raymond

Raymond Fischbach
www.mouches.org
Posts: 42
Joined: Sun Oct 09, 2005 11:47 AM
How to stop en endless loop ?
Posted: Thu Jun 08, 2006 01:12 AM

Raymond,
Thanks to Enrico for his suggestion! - see Enrico's post 'Serial Port' of 16 January for some nice code samples. Use 'activate' and 'deactivate' methods to start and stop the timer and hence the serial read function. Let me know if you need a fully working sample...
hth

Posts: 42
Joined: Sun Oct 09, 2005 11:47 AM
How to stop en endless loop ?
Posted: Thu Jun 08, 2006 04:33 AM

Raymond,
The sample program 'BlueTime' illustrates the timer function. This example just reads 20 chs each time - you'll need to work out when your GPS data message is complete. You'll need the Mobile 2005 emulator for comms to work reliably...

// BlueTime

include "FWCE.ch"

define GENERIC_READ 0x80000000

define GENERIC_WRITE 0x40000000

define GENERIC_REWRITE 0xC0000000

define OPEN_EXISTING 3

define FILE_ATTRIBUTE_NORMAL 0x00000080

function Main()

local oWnd, oTimer, oChk
local hPort
local nPollTime := 1000
local lOnOff := .T.

hPort := CreateFile( "COM1:",GENERIC_REWRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL )

if hPort == -1
MSGALERT("Cannot open port")
return -1
endif

DEFINE WINDOW oWnd TITLE "BlueTime"

@ 2, 2 BUTTON "GPS On/Off" SIZE 80, 30 ACTION (lOnOff := OnOff( hPort, oTimer, lOnOff ), oChk:refresh)

@ 10, 2 CHECKBOX oChk VAR lOnOff PROMPT "On/Off" OF oWnd SIZE 80, 20

if hPort != -1
DEFINE TIMER oTimer OF oWnd;
INTERVAL nPollTime;
ACTION ReadGPS(hPort, oTimer)
endif

ACTIVATE WINDOW oWnd

CloseHandle( hPort )

return nil

function ReadGPS( hPort, oTimer )

local nChr := 1
local cText := ""
local n := 1

oTimer:DeActivate() // stops timer - waits for data

do while nChr > 0 .and. n < 21
nChr := ReadByte( hPort )
cText := cText + Chr( nChr )
n++
end do

msginfo( cText )

oTimer:Activate() // restarts timer

return nil

function OnOff( hPort, oTimer, lOnOff )
if hPort != -1
if lOnOff
oTimer:DeActivate() // stops timer
else
oTimer:Activate() // starts timer
endif
endif
return !(lOnOff)

hth
regards

Posts: 48
Joined: Sun Oct 30, 2005 09:29 AM
How to stop en endless loop ?
Posted: Thu Jun 08, 2006 08:14 AM

Hi Jon,

Thank you for these info.

I will git it a try and will post teh results.

Best regards,
Raymond

Raymond Fischbach
www.mouches.org

Continue the discussion