Code: Select all
/*
Function to test for Serial ports and their acceptable speeds. May run
differently under different versions of Windows.
Ned Robertson -- 5/30/2001
*/
#include 'Fivewin.ch'
#include 'fileio.ch'
STATIC nComm
//----------------------------------------------------------------//
Function CommTest ()
LOCAL cF := 'commTest.log', cP, cR, j, i
LOCAL aSpd := { '9600', ; // Ol' Faithful
'14400', ; // Common modem speed
'19200', ; // Double Ol' Faithful - popular in telephony
'28800', ; // Common modem speed
'33600', ; // semi-common modem speed
'38400', ; // Quadruple Ol' Faithful - popular in telephony
'57600', ; // Common modem speed
'115200' } // Upper limit of serial port
FErase( cF )
FOR i = 1 TO 4
cP := LTrim( Str( i ) )
IF Empty( CommOpen( cP, aSpd[ 1 ] ) )
CloseComm( nComm )
FOR j = 1 TO Len( aSpd )
cR := CommOpen( cP, aSpd[ j ] )
IF Empty( cR )
LogFile( cF, { 'Successful Open of COM' + cP + ' at ' + aSpd[ j ] } )
ELSE
LogFile( cF, { cR } )
ENDIF
CloseComm( nComm )
NEXT
ELSE
LogFile( cF, { 'No port found at COM' + cP } )
ENDIF
NEXT
? "Mira: " + cF
Return NIl
//----------------------------------------------------------------//
Function CommOpen ( cPort, cSpeed )
LOCAL cDcb, cRv := '', cS := 'COM' + cPort + ':' + cSpeed + ',n,8,1'
nComm := OpenComm( 'COM' + cPort, 1024 , 128 )
IF nComm >= 0 // We have a valid port...
IF BuildCommDcb( cS, @cDcb ) // Set Speed, etc
#ifdef __CLIPPER__
IF SetCommState( cDcb )
#else
IF SetCommState( nComm, cDcb )
#endif
cRv := ''
ELSE
cRv := 'Failed to SetCommState on COM' + cPort + ' at ' + cSpeed
ENDIF
ELSE
cRv := 'Failed to BuildCommDCB on COM' + cPort + ' at ' + cSpeed
ENDIF
ELSE
cRv := 'Failed to find COM' + cPort
ENDIF
Return cRv
//----------------------------------------------------------------//