by Jon Munro » Thu Jun 08, 2006 4: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