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
How to stop en endless loop ?
- Raymond Fischbach
- Posts: 48
- Joined: Sun Oct 30, 2005 9:29 am
- Location: Belgium
- Contact:
- Enrico Maria Giordano
- Posts: 8753
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Has thanked: 1 time
- Been thanked: 4 times
- Contact:
Re: How to stop en endless loop ?
Just put something like
IF lStop; EXIT; ENDIF
inside the loop and
ACTION lStop := .T.
in the stop button action.
EMG
IF lStop; EXIT; ENDIF
inside the loop and
ACTION lStop := .T.
in the stop button action.
EMG
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
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
Jon Munro
www.bscan456.com
www.bscan456.com
- Raymond Fischbach
- Posts: 48
- Joined: Sun Oct 30, 2005 9:29 am
- Location: Belgium
- Contact:
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
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
![Sad :(](./images/smilies/icon_sad.gif)
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
www.mouches.org
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
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
Jon Munro
www.bscan456.com
www.bscan456.com
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
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
Jon Munro
www.bscan456.com
www.bscan456.com
- Raymond Fischbach
- Posts: 48
- Joined: Sun Oct 30, 2005 9:29 am
- Location: Belgium
- Contact:
Hi Jon,
Thank you for these info.
I will git it a try and will post teh results.
Best regards,
Raymond
Thank you for these info.
I will git it a try and will post teh results.
Best regards,
Raymond
Raymond Fischbach
www.mouches.org
www.mouches.org