by tnhoe » Fri Apr 28, 2006 4:14 am
// modified fivewn sample to read continuos data from laser diameter reader, you can use a timer to call it .
function fReadPort
local cDcb, lError, nError
cErrCode := space( 16 )
if !( gnComm := OpenComm( 'COM1', 1024, 10 ) ) == 0
if !(BuildCommDcb( "COM1:2400,N,8,1", @cDcb ) .and. SetCommState( @cDcb ) )
nError := GetCommError( gnComm, @cErrCode )
MsgAlert( "Error "+ str( nError ) + CRLF + cErrCode)
RETURN( .f. )
endif
endif
cBlock=space(1024)
nTry=0
do while nTry<50 // can remove this nTry if not applicable
if ( nBytes := readComm( gnComm, @cBlock) ) > 0
msgwait('Got it ... '+str(nTry,5),'',1)
exit
else
nTry++
msgwait('Reading ... '+str(nTry,5),'',1)
endif
enddo
msginfo(cBlock) // can append data into dbf or text log (fwrite) here
if FlushComm( gnComm, 0 ) != 0
nError = GetCommError( gnComm )
Msgwait( 'FlushComm Error:' ,'',.01 )
endif
if ! CloseComm( gnComm )
nError = GetCommError( gnComm )
Msgwait( 'CloseComm Error: ' ,'',.01 )
endif
RETURN( .t. )