Page 1 of 1

Sniffer (COM ports)

Posted: Thu Apr 27, 2006 10:12 pm
by Maurilio Viana
Is possible scan COM1 / COM2 ports with FW or xHarbour and create a log of scanned data thart these ports receive?

If isn´t possible, does anybody know any program that scan com ports and generate a log file?

Thanks a lot
Maurilio

Posted: Fri Apr 28, 2006 4:14 am
by tnhoe
// 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. )

Posted: Fri Apr 28, 2006 8:59 pm
by Maurilio Viana
I´ll try it!

Thanks a lot!!!

Regards
Maurilio