From d66d0e31cd9f5174e1095e1cde1ce2ebf72e35c5 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 4 Aug 2009 10:42:40 +0000 Subject: [PATCH] 2009-08-04 12:41 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbtpathy/tpwin.c * contrib/hbtpathy/ChangeLog * contrib/hbtpathy/telepath.prg * Formatting. + Added some dummy functions to at least make the win version link properly. It didn't work for me though. * contrib/hbwin/win_tprt.prg * contrib/hbwin/win_prt.c * Formatting. * Added Hungarian notation to variables. ! Tweaked a few types. + Extended number of ports to 32 (from 16). F.e. on my system the Nokia phone gets installed on COM22. ; TODO: Rename functions/class to comply with rest of lib. --- harbour/ChangeLog | 17 + harbour/contrib/hbtpathy/ChangeLog | 4 - harbour/contrib/hbtpathy/telepath.prg | 779 ++++++++--------- harbour/contrib/hbtpathy/tpwin.c | 8 + harbour/contrib/hbwin/win_prt.c | 1156 +++++++++++++------------ harbour/contrib/hbwin/win_tprt.prg | 6 +- 6 files changed, 1002 insertions(+), 968 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index a42a0df31b..8391dfa6fc 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,23 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-08-04 12:41 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hbtpathy/tpwin.c + * contrib/hbtpathy/ChangeLog + * contrib/hbtpathy/telepath.prg + * Formatting. + + Added some dummy functions to at least make the win version link + properly. It didn't work for me though. + + * contrib/hbwin/win_tprt.prg + * contrib/hbwin/win_prt.c + * Formatting. + * Added Hungarian notation to variables. + ! Tweaked a few types. + + Extended number of ports to 32 (from 16). F.e. on my system + the Nokia phone gets installed on COM22. + ; TODO: Rename functions/class to comply with rest of lib. + 2009-08-04 03:44 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * source/vm/fm.c ! Fixed linux/sunpro warning. diff --git a/harbour/contrib/hbtpathy/ChangeLog b/harbour/contrib/hbtpathy/ChangeLog index 9def0c36f3..c42f1cd15c 100644 --- a/harbour/contrib/hbtpathy/ChangeLog +++ b/harbour/contrib/hbtpathy/ChangeLog @@ -109,7 +109,6 @@ * tp_/testtp.prg + Added CVS ID to every file - I sent the original version to the flagship website in may 2000. I just now (July 2001) made the first change to the code. @@ -120,6 +119,3 @@ assumed that if you were setting parity to N, the port was already at N and I didn't explicitly call stty -parenb and -parodd. I included telepathy.bak in case you care to look at the prior version. - - - diff --git a/harbour/contrib/hbtpathy/telepath.prg b/harbour/contrib/hbtpathy/telepath.prg index 6b9f6869e1..c93ffd485e 100644 --- a/harbour/contrib/hbtpathy/telepath.prg +++ b/harbour/contrib/hbtpathy/telepath.prg @@ -63,27 +63,24 @@ #include "telepath.ch" - THREAD STATIC t_aPorts // Array with port info THREAD STATIC t_nErrorCode := 0 // Error code from last operation, 0 if no error +FUNCTION tp_baud( nPort, nNewBaud ) + DEFAULT nNewBaud TO 0 -function tp_baud( nPort, nNewBaud ) + IF ! isport( nPort ) .OR. Empty( t_aPorts[ nPort, TPFP_NAME ] ) + RETURN TE_NOPORT + ENDIF - default nNewBaud to 0 + IF ! isopenport( nPort ) + RETURN 0 + ENDIF - if ! isport( nPort ) .OR. Empty( t_aPorts[ nPort, TPFP_NAME ] ) - return TE_NOPORT - endif - - if ! isopenport( nPort ) - return 0 - endif - - if nNewBaud > 0 - if p_InitPortSpeed( t_aPorts[ nPort, TPFP_HANDLE ] ,; + IF nNewBaud > 0 + IF p_InitPortSpeed( t_aPorts[ nPort, TPFP_HANDLE ] ,; nNewBaud,; t_aPorts[ nPort, TPFP_DBITS ] ,; t_aPorts[ nPort, TPFP_PARITY ] ,; @@ -92,65 +89,53 @@ function tp_baud( nPort, nNewBaud ) t_aPorts[ nPort, TPFP_BAUD ] := nNewBaud - else + ELSE // set error code - endif - endif + ENDIF + ENDIF -return t_aPorts[ nPort, TPFP_BAUD ] + RETURN t_aPorts[ nPort, TPFP_BAUD ] +FUNCTION tp_inkey( nSecs ) + RETURN inkey( nSecs ) -function tp_inkey( nSecs ) - if valtype( nSecs ) == "U" - return inkey() - endif -return inkey( nSecs ) +FUNCTION tp_idle( lNewval ) + IF lNewval == .T. + RETURN .T. + ENDIF + RETURN .F. +PROCEDURE tp_delay( nTime ) + DEFAULT nTime TO 0 -function tp_idle( lNewval ) - if lNewval == .t. - return .t. - endif -return .f. - - - -function tp_delay( nTime ) - - default nTime to 0 - - if nTime < 0 - return nil - - elseif nTime > 1800 + IF nTime < 0 + RETURN + ELSEIF nTime > 1800 nTime := 1800 - - endif + ENDIF hb_idleSleep( nTime ) -return nil + RETURN +FUNCTION tp_close( nPort, nTimeout ) - -function tp_close( nPort, nTimeout ) - - default nTimeout to 0 + DEFAULT nTimeout TO 0 /* Clipper returns 0 even if a port is not open */ - if ! isopenport( nPort ) - return 0 - endif + IF ! isopenport( nPort ) + RETURN 0 + ENDIF - if nTimeout > 0 + IF nTimeout > 0 tp_flush( nPort, nTimeout ) - endif + ENDIF - if t_aPorts[ nPort, TPFP_HANDLE ] >= 0 + IF t_aPorts[ nPort, TPFP_HANDLE ] >= 0 - fClose( t_aPorts[ nPort, TPFP_HANDLE ] ) + FClose( t_aPorts[ nPort, TPFP_HANDLE ] ) /* Port parameters should stay the same for the case the port gets reopened @@ -158,21 +143,20 @@ function tp_close( nPort, nTimeout ) t_aPorts[ nPort, TPFP_OC ] := .F. t_aPorts[ nPort, TPFP_INBUF ] := "" t_aPorts[ nPort, TPFP_HANDLE ] := -1 - endif + ENDIF -return 0 + RETURN 0 - - -function tp_reopen( nPort, nInSize, nOutSize ) +FUNCTION tp_reopen( nPort, nInSize, nOutSize ) LOCAL nBaud, nData, cParity, nStop, cPortName - default nInSize to 1536, nOutSize to 1536 + DEFAULT nInSize TO 1536 + DEFAULT nOutSize TO 1536 - if ! isport( nPort ) .OR. Empty( t_aPorts[ nPort, TPFP_NAME ] ) - return TE_NOPORT - endif + IF ! isport( nPort ) .OR. Empty( t_aPorts[ nPort, TPFP_NAME ] ) + RETURN TE_NOPORT + ENDIF cPortname := t_aPorts[ nPort, TPFP_NAME ] nBaud := t_aPorts[ nPort, TPFP_BAUD ] @@ -180,26 +164,29 @@ function tp_reopen( nPort, nInSize, nOutSize ) cParity := t_aPorts[ nPort, TPFP_PARITY ] nStop := t_aPorts[ nPort, TPFP_SBITS ] -return tp_open( nPort, nInSize, nOutSize, nBaud, nData, cParity, nStop, cPortName ) + RETURN tp_open( nPort, nInSize, nOutSize, nBaud, nData, cParity, nStop, cPortName ) +FUNCTION tp_open( nPort, nInSize, nOutSize, nBaud, nData, cParity, nStop, cPortname ) - -function tp_open( nPort, nInSize, nOutSize, nBaud, nData, cParity, nStop, cPortname ) - - local nRes, lPortExist + LOCAL nRes, lPortExist #ifdef __PLATFORM__UNIX - local nFileCase, nDirCase + LOCAL nFileCase + LOCAL nDirCase #endif - default nInSize to 1536, nOutSize to 1536 - default nBaud to 1200, nData to 8, cParity to "N", nStop to 1 + DEFAULT nInSize TO 1536 + DEFAULT nOutSize TO 1536 + DEFAULT nBaud TO 1200 + DEFAULT nData TO 8 + DEFAULT cParity TO "N" + DEFAULT nStop TO 1 /* Serial ports name are made up of cPortName + nPort if nPort is not NIL */ #ifdef __PLATFORM__UNIX - default cPortName to "/dev/ttyS" + DEFAULT cPortName TO "/dev/ttyS" #else - default cPortName to "COM" // Ok for Windows and OS/2 + DEFAULT cPortName TO "COM" // Ok for Windows and OS/2 #endif /* This way compatibility is retained for ports 1-4 on Windows and Linux, but, @@ -207,258 +194,243 @@ function tp_open( nPort, nInSize, nOutSize, nBaud, nData, cParity, nStop, cPortn a full name on cPortName */ #ifdef __PLATFORM__UNIX - cPortname := AllTrim( cPortname ) + iif( ISNUMBER( nPort ), hb_NToS( nPort - 1 ), "" ) + cPortname := AllTrim( cPortname ) + iif( ISNUMBER( nPort ), hb_NToS( nPort - 1 ), "" ) #else - cPortname := AllTrim( cPortname ) + iif( ISNUMBER( nPort ), hb_NToS( nPort ), "" ) + cPortname := AllTrim( cPortname ) + iif( ISNUMBER( nPort ), hb_NToS( nPort ), "" ) #endif #ifdef __PLATFORM__UNIX - nFileCase := Set( _SET_FILECASE, 0 ) - nDirCase := Set( _SET_DIRCASE, 0 ) + nFileCase := Set( _SET_FILECASE, 0 ) + nDirCase := Set( _SET_DIRCASE, 0 ) #endif + lPortExist := File( cPortname ) + #ifdef __PLATFORM__UNIX - Set( _SET_FILECASE, nFileCase ) - Set( _SET_DIRCASE, nDirCase ) + Set( _SET_FILECASE, nFileCase ) + Set( _SET_DIRCASE, nDirCase ) #endif - if ! lPortExist - return TE_NOPORT - endif + IF ! lPortExist + RETURN TE_NOPORT + ENDIF - if ! isport( nPort ) - return TE_NOPORT - endif + IF ! isport( nPort ) + RETURN TE_NOPORT + ENDIF - t_aPorts[ nPort, TPFP_NAME ] := cPortname - t_aPorts[ nPort, TPFP_BAUD ] := nBaud - t_aPorts[ nPort, TPFP_DBITS ] := nData - t_aPorts[ nPort, TPFP_PARITY ] := cParity - t_aPorts[ nPort, TPFP_SBITS ] := nStop - t_aPorts[ nPort, TPFP_OC ] := .F. - t_aPorts[ nPort, TPFP_INBUF ] := "" + t_aPorts[ nPort, TPFP_NAME ] := cPortname + t_aPorts[ nPort, TPFP_BAUD ] := nBaud + t_aPorts[ nPort, TPFP_DBITS ] := nData + t_aPorts[ nPort, TPFP_PARITY ] := cParity + t_aPorts[ nPort, TPFP_SBITS ] := nStop + t_aPorts[ nPort, TPFP_OC ] := .F. + t_aPorts[ nPort, TPFP_INBUF ] := "" t_aPorts[ nPort, TPFP_INBUF_SIZE ] := nInSize #ifdef __PLATFORM__UNIX // Maybe we should have a p_Open() on every platform - t_aPorts[ nPort, TPFP_HANDLE ] := p_Open( cPortname ) + t_aPorts[ nPort, TPFP_HANDLE ] := p_Open( cPortname ) #else - t_aPorts[ nPort, TPFP_HANDLE ] := fOpen( cPortname, FO_READWRITE ) + t_aPorts[ nPort, TPFP_HANDLE ] := FOpen( cPortname, FO_READWRITE ) #endif - if t_aPorts[ nPort, TPFP_HANDLE ] >= 0 + IF t_aPorts[ nPort, TPFP_HANDLE ] >= 0 /* low level C functions are prefixed p_ (don't ask me why :)) */ - if ( nRes := p_InitPortSpeed( t_aPorts[ nPort, TPFP_HANDLE ] ,; + IF ( nRes := p_InitPortSpeed( t_aPorts[ nPort, TPFP_HANDLE ] ,; t_aPorts[ nPort, TPFP_BAUD ] ,; t_aPorts[ nPort, TPFP_DBITS ] ,; t_aPorts[ nPort, TPFP_PARITY ] ,; t_aPorts[ nPort, TPFP_SBITS ] ) ) == 0 t_aPorts[ nPort, TPFP_OC ] := .T. - return nRes - - else - + RETURN nRes + ELSE tp_Close( t_aPorts[ nPort, TPFP_HANDLE ] ) - return nRes - - endif - - endif + RETURN nRes + ENDIF + ENDIF // set error code to a static var to have tp_error() work as expected - //cnHandle := ferror() + //cnHandle := FError() - t_aPorts[ nPort, TPFP_NAME ] := "" - t_aPorts[ nPort, TPFP_HANDLE ] := -1 - t_aPorts[ nPort, TPFP_BAUD ] := 1200 - t_aPorts[ nPort, TPFP_DBITS ] := 8 - t_aPorts[ nPort, TPFP_PARITY ] := "N" - t_aPorts[ nPort, TPFP_SBITS ] := 1 - t_aPorts[ nPort, TPFP_OC ] := .F. - t_aPorts[ nPort, TPFP_INBUF ] := "" - t_aPorts[ nPort, TPFP_INBUF_SIZE ] := 0 + t_aPorts[ nPort, TPFP_NAME ] := "" + t_aPorts[ nPort, TPFP_HANDLE ] := -1 + t_aPorts[ nPort, TPFP_BAUD ] := 1200 + t_aPorts[ nPort, TPFP_DBITS ] := 8 + t_aPorts[ nPort, TPFP_PARITY ] := "N" + t_aPorts[ nPort, TPFP_SBITS ] := 1 + t_aPorts[ nPort, TPFP_OC ] := .F. + t_aPorts[ nPort, TPFP_INBUF ] := "" + t_aPorts[ nPort, TPFP_INBUF_SIZE ] := 0 -return TE_CONFL // maybe should return something different? + RETURN TE_CONFL // maybe should return something different? +FUNCTION tp_recv( nPort, nLength, nTimeout ) + LOCAL nDone + LOCAL cRet -function tp_recv( nPort, nLength, nTimeout ) - - local nDone - local cRet - - default nLength to t_aPorts[ nPort, TPFP_INBUF_SIZE ] - default nTimeout to 0 + DEFAULT nLength TO t_aPorts[ nPort, TPFP_INBUF_SIZE ] + DEFAULT nTimeout TO 0 FetchChars( nPort ) nDone := Seconds() + iif( nTimeout >= 0, nTimeout, 0 ) - while Len( t_aPorts[ nPort, TPFP_INBUF ] ) < nLength .AND.; - ( nTimeout < 0 .OR. Seconds() < nDone ) + DO WHILE Len( t_aPorts[ nPort, TPFP_INBUF ] ) < nLength .AND.; + ( nTimeout < 0 .OR. Seconds() < nDone ) - if ! tp_idle() + IF ! tp_idle() FetchChars( nPort ) - else - exit - endif + ELSE + EXIT + ENDIF + ENDDO - enddo - - if nLength > Len( t_aPorts[ nPort, TPFP_INBUF ] ) + IF nLength > Len( t_aPorts[ nPort, TPFP_INBUF ] ) cRet := t_aPorts[ nPort, TPFP_INBUF ] t_aPorts[ nPort, TPFP_INBUF ] := "" - else + ELSE cRet := SubStr( t_aPorts[ nPort, TPFP_INBUF ], 1, nLength ) t_aPorts[ nPort, TPFP_INBUF ] := SubStr( t_aPorts[ nPort, TPFP_INBUF ], nLength + 1 ) - endif + ENDIF -return cRet + RETURN cRet +FUNCTION tp_send( nPort, cString, nTimeout ) + LOCAL nWritten, nTotWritten, nDone -function tp_send( nPort, cString, nTimeout ) + DEFAULT cString TO "" + DEFAULT nTimeout TO 0 - local nWritten, nTotWritten, nDone + IF ! isopenport( nPort ) + RETURN 0 + ENDIF - default cString to "", nTimeout to 0 - - if ! isopenport( nPort ) - return 0 - endif - - if Len( cString ) == 0 - return 0 - endif + IF Len( cString ) == 0 + RETURN 0 + ENDIF nDone := Seconds() + iif( nTimeout >= 0, nTimeout, 0) nTotWritten := 0 - while nTotWritten < Len( cString ) .AND. ; + DO WHILE nTotWritten < Len( cString ) .AND. ; ( nTimeout < 0 .OR. Seconds() <= nDone ) nWritten := p_WritePort( t_aPorts[ nPort, TPFP_HANDLE ], SubStr( cString, nTotWritten + 1 ) ) - if nWritten >= 0 + IF nWritten >= 0 nTotWritten += nWritten - if nTotWritten < Len( cString ) + IF nTotWritten < Len( cString ) - if ! tp_idle() + IF ! tp_idle() hb_idleSleep( 1 ) - else - exit - endif + ELSE + EXIT + ENDIF + ENDIF + ELSE // nWritten < 0, error occurred + EXIT + ENDIF + ENDDO - endif - - else // nWritten < 0, error occurred - exit - - endif - - enddo - -return nTotWritten + RETURN nTotWritten +FUNCTION tp_sendsub( nPort, cString, nStart, nLength, nTimeout ) -function tp_sendsub( nPort, cString, nStart, nLength, nTimeout ) + DEFAULT nStart TO 1 + DEFAULT nLength TO Len( cString ) - default nStart to 1, nLength to Len( cString ) - -return tp_send( nPort, SubStr( cString, nStart, nLength ), nTimeout ) + RETURN tp_send( nPort, SubStr( cString, nStart, nLength ), nTimeout ) +FUNCTION tp_recvto( nPort, cDelim, nMaxlen, nTimeout ) -function tp_recvto( nPort, cDelim, nMaxlen, nTimeout ) + LOCAL cChar + LOCAL nAt + LOCAL nStartPos := 1, nFirst := 0 + LOCAL nDone, cRet := "" - local cChar - local nAt - local nStartPos := 1, nFirst := 0 - local nDone, cRet := "" + IF ! isopenport( nPort ) + RETURN "" + ENDIF + IF ! ISCHARACTER( cDelim ) .OR. Len( cDelim ) == 0 + RETURN "" + ENDIF - if ! isopenport( nPort ) - return "" - endif - - if ! ISCHARACTER( cDelim ) .OR. Len( cDelim ) == 0 - return "" - endif - - default nMaxlen to 64999 /* dos telepathy def. on xharbour could be higher */ - default nTimeout to 0 - + DEFAULT nMaxlen TO 64999 /* dos telepathy def. on xharbour could be higher */ + DEFAULT nTimeout TO 0 FetchChars( nPort ) /* Telepathy ng: [...] If nTimeout is omitted or zero, reads until finding the delimiter or the input buffer is empty. */ - if nTimeout == 0 .AND. Len( t_aPorts[ nPort, TPFP_INBUF ] ) == 0 - return "" - endif + IF nTimeout == 0 .AND. Len( t_aPorts[ nPort, TPFP_INBUF ] ) == 0 + RETURN "" + ENDIF nDone := Seconds() + iif( nTimeout >= 0, nTimeout, 0 ) - while ( nTimeout < 0 .OR. Seconds() < nDone ) + DO WHILE ( nTimeout < 0 .OR. Seconds() < nDone ) - if Len( cDelim ) == 1 + IF Len( cDelim ) == 1 nAt := hb_At( cDelim, t_aPorts[ nPort, TPFP_INBUF ], nStartPos ) - if nAt > 0 .AND. iif( nFirst > 0, nAt < nFirst, .T. ) + IF nAt > 0 .AND. iif( nFirst > 0, nAt < nFirst, .T. ) nFirst := nAt - endif + ENDIF - else + ELSE FOR EACH cChar IN cDelim nAt := hb_At( cChar, t_aPorts[ nPort, TPFP_INBUF ], nStartPos ) - if nAt > 0 .AND. iif( nFirst > 0, nAt < nFirst, .T. ) + IF nAt > 0 .AND. iif( nFirst > 0, nAt < nFirst, .T. ) nFirst := nAt - endif + ENDIF NEXT - endif + ENDIF // I've found it - if nFirst > 0 - exit + IF nFirst > 0 + EXIT - else + ELSE // Next loop I don't need to search that part of the input buffer that // I've already just searched for nStartPos := Max( Len( t_aPorts[ nPort, TPFP_INBUF ] ), 1 ) // I've read more characters than I'm allowed to, so I exit - if nStartPos >= nMaxLen - exit - endif + IF nStartPos >= nMaxLen + EXIT + ENDIF - if ! tp_idle() + IF ! tp_idle() FetchChars( nPort ) - else - exit - endif - endif + ELSE + EXIT + ENDIF + ENDIF - enddo + ENDDO - if nFirst > 0 + IF nFirst > 0 cRet := Left( t_aPorts[ nPort, TPFP_INBUF ], nFirst ) t_aPorts[ nPort, TPFP_INBUF ] := SubStr( t_aPorts[ nPort, TPFP_INBUF ], nFirst + 1 ) - endif - -return cRet - + ENDIF + RETURN cRet /* here's an improvement over original TP... you can "lookfor" a string @@ -466,162 +438,146 @@ return cRet of course, if you're using clipper/tp code and you search for a single char it will work the same. */ -function tp_lookfor( nPort, cLookfor ) +FUNCTION tp_lookfor( nPort, cLookfor ) - if ! isopenport( nPort ) - return 0 - endif + IF ! isopenport( nPort ) + RETURN 0 + ENDIF FetchChars( nPort ) -return At( cLookfor, t_aPorts[ nPort, TPFP_INBUF ] ) + RETURN At( cLookfor, t_aPorts[ nPort, TPFP_INBUF ] ) +FUNCTION tp_inchrs( nPort ) - -function tp_inchrs( nPort ) - - if ! isopenport( nPort ) - return 0 - endif + IF ! isopenport( nPort ) + RETURN 0 + ENDIF FetchChars( nPort ) -return Len( t_aPorts[ nPort, TPFP_INBUF ] ) + RETURN Len( t_aPorts[ nPort, TPFP_INBUF ] ) +FUNCTION tp_outfree( nPort ) + IF ! isopenport( nPort ) + RETURN 0 + ENDIF -function tp_outfree( nPort ) + RETURN p_OutFree( t_aPorts[ nPort, TPFP_HANDLE ] ) - if ! isopenport( nPort ) - return 0 - endif +PROCEDURE tp_clearin( nPort ) -return p_OutFree( t_aPorts[ nPort, TPFP_HANDLE ] ) - - - -function tp_clearin( nPort ) - - if isopenport( nPort ) + IF isopenport( nPort ) FetchChars( nPort ) t_aPorts[ nPort, TPFP_INBUF ] := "" - endif + ENDIF -return nil + RETURN +PROCEDURE tp_clrkbd() + CLEAR TYPEAHEAD -function tp_clrkbd() + RETURN - clear typeahead +FUNCTION tp_crc16( cString ) -return nil + RETURN p_CRC16( cString ) +FUNCTION tp_crc32( cString ) - -function tp_crc16( cString ) - -return p_CRC16( cString ) - - - -function tp_crc32( cString ) - -return p_CRC32( cString ) + RETURN p_CRC32( cString ) /* nPort, nTimeout, acList|cString..., lIgnorecase */ -function tp_waitfor( ... ) +FUNCTION tp_waitfor( ... ) - local aParam := hb_AParams() - local nPort//, nTimeout, lIgnorecase + LOCAL aParam := hb_AParams() + LOCAL nPort//, nTimeout, lIgnorecase nPort := aParam[ 1 ] - //nTimeout := aParam[ 2 ] - //lIgnorecase := aParam[ Len( aParam ) ] + // nTimeout := aParam[ 2 ] + // lIgnorecase := aParam[ Len( aParam ) ] - if ! isopenport( nPort ) - return 0 - endif + IF ! isopenport( nPort ) + RETURN 0 + ENDIF - //default nTimeout to -1 - //default lIgnorecase to .f. + // DEFAULT nTimeout TO -1 + // DEFAULT lIgnorecase TO .F. /* - if ntimeout < 0 + IF ntimeout < 0 nDone := _clock() + 999999 - elseif ntimeout == 0 + ELSEIF ntimeout == 0 nDone := 4 - else + ELSE nDone := _clock() + nTimeout - endif + ENDIF - while ( nDone > _clock() .or. nFirst == 100000 ) .and. ! tp_idle() + DO WHILE ( nDone > _clock() .OR. nFirst == 100000 ) .AND. ! tp_idle() - if nFirst == 100000 + IF nFirst == 100000 nFirst := 99999 - endif + ENDIF FetchChars( nPort ) - for x := 1 to len( acList ) - if lIgnorecase - nAt := at( upper( acList[ x ] ), upper( t_aPorts[ nPort, TPFP_INBUF ] )) - else - nAt := at( acList[ x ] , t_aPorts[ nPort, TPFP_INBUF ] ) - endif - if nAt > 0 .and. nAt < nFirst + FOR x := 1 TO Len( acList ) + IF lIgnorecase + nAt := At( upper( acList[ x ] ), Upper( t_aPorts[ nPort, TPFP_INBUF ] )) + ELSE + nAt := At( acList[ x ] , t_aPorts[ nPort, TPFP_INBUF ] ) + ENDIF + IF nAt > 0 .AND. nAt < nFirst nFirst := nAt nRet := x - endif - next + ENDIF + NEXT - if nFirst < 64000 - exit - endif + IF nFirst < 64000 + EXIT + ENDIF #if 0 sched_yield() // C level function #endif - enddo + ENDDO - if nFirst < 64000 - tp_recv( nPort, nAt + len( acList[ nRet ] )) - return nRet - endif + IF nFirst < 64000 + tp_recv( nPort, nAt + Len( acList[ nRet ] )) + RETURN nRet + ENDIF */ -return 0 - - + RETURN 0 /* We cannot set, well, _I_ think we cannot, CTS without setting RTS flowcontrol, so this function and tp_ctrlrts() do the same thing, that is set/reset CRTSCTS flowcontol */ -function tp_ctrlcts( nPort, nNewCtrl ) +FUNCTION tp_ctrlcts( nPort, nNewCtrl ) - local nCurValue + LOCAL nCurValue - if ! isopenport( nPort ) - return 0 - endif + IF ! isopenport( nPort ) + RETURN 0 + ENDIF - if Valtype( nNewCtrl ) == "U" + IF Valtype( nNewCtrl ) == "U" nCurValue := p_ctrlcts( t_aPorts[ nPort, TPFP_HANDLE ] ) - - else + ELSE nCurValue := p_ctrlcts( t_aPorts[ nPort, TPFP_HANDLE ], nNewCtrl ) + ENDIF - endif - -return nCurValue + RETURN nCurValue // Simply calls tp_ctrlcts() -function tp_ctrlrts( nPort, nNewCtrl ) +FUNCTION tp_ctrlrts( nPort, nNewCtrl ) -return tp_ctrlcts( nPort, nNewCtrl ) + RETURN tp_ctrlcts( nPort, nNewCtrl ) @@ -631,225 +587,202 @@ return tp_ctrlcts( nPort, nNewCtrl ) // returns old dtr value 0,1,2 // sets to 0 = dtr off, 1 dtr on, 2 = dtr flow control autotoggle // I don't support 2. who uses dtr for flow control anyway... -function tp_ctrldtr( nPort, nParamNewval ) +FUNCTION tp_ctrldtr( nPort, nParamNewval ) LOCAL nph, nnewval, noldval - if ! isopenport( nPort ) - return -1 - endif + IF ! isopenport( nPort ) + RETURN -1 + ENDIF nph := t_aPorts[ nPort, TPFP_HANDLE ] - _P_CTRLDTR(nph, @nnewval, @noldval) + _P_CTRLDTR( nph, @nnewval, @noldval ) -return noldval + RETURN noldval */ +FUNCTION tp_isdcd( nPort ) + IF ! isopenport( nPort ) + RETURN .F. + ENDIF -function tp_isdcd( nPort ) + RETURN p_isdcd( t_aPorts[ nPort, TPFP_HANDLE ] ) - if ! isopenport( nPort ) - return .f. - endif +FUNCTION tp_isri( nPort ) -return p_isdcd( t_aPorts[ nPort, TPFP_HANDLE ] ) + IF ! isopenport( nPort ) + RETURN .F. + ENDIF + RETURN p_isri( t_aPorts[ nPort, TPFP_HANDLE ] ) +FUNCTION tp_isdsr( nPort ) -function tp_isri( nPort ) + IF ! isopenport( nPort ) + RETURN .F. + ENDIF - if ! isopenport( nPort ) - return .f. - endif + RETURN p_isdsr( t_aPorts[ nPort, TPFP_HANDLE ] ) -return p_isri( t_aPorts[ nPort, TPFP_HANDLE ] ) - - - -function tp_isdsr( nPort ) - - if ! isopenport( nPort ) - return .f. - endif - -return p_isdsr( t_aPorts[ nPort, TPFP_HANDLE ] ) - - - -function tp_iscts( nPort ) - - if ! isopenport( nPort ) - return .f. - endif - -return p_iscts( t_aPorts[ nPort, TPFP_HANDLE ] ) +FUNCTION tp_iscts( nPort ) + IF ! isopenport( nPort ) + RETURN .F. + ENDIF + RETURN p_iscts( t_aPorts[ nPort, TPFP_HANDLE ] ) #ifdef __PLATFORM__UNIX // NB: On linux i don't know how to make a drain with a timeout, so here // I'll wait as long as it takes to drain the port. -function tp_flush( nPort, nTimeout ) +FUNCTION tp_flush( nPort, nTimeout ) - //local nStart := Seconds() - local nRes + //LOCAL nStart := Seconds() + LOCAL nRes - default nTimeout to 0 + DEFAULT nTimeout TO 0 - if ! isopenport( nPort ) - return TE_CLOSED - endif + IF ! isopenport( nPort ) + RETURN TE_CLOSED + ENDIF nRes := p_Drain( t_aPorts[ nPort, TPFP_HANDLE ] ) // Sleep rest of timeout /* - if nTimeout > 0 .AND. Seconds() - nStart < nTimeout + IF nTimeout > 0 .AND. Seconds() - nStart < nTimeout hb_idleSleep( nTimeout - ( Seconds() - nStart ) ) - endif + ENDIF */ // NB: returns timeout on error trying to reach compatibility with other platforms // to be tested -return iif( nRes == 0, 0, TE_TMOUT ) + RETURN iif( nRes == 0, 0, TE_TMOUT ) #else -function tp_flush( nPort, nTimeout ) +FUNCTION tp_flush( nPort, nTimeout ) - local nDone + LOCAL nDone - default nTimeout to -1 + DEFAULT nTimeout TO -1 - if ! isopenport( nPort ) - return TE_CLOSED - endif + IF ! isopenport( nPort ) + RETURN TE_CLOSED + ENDIF - if nTimeout > 1800 + IF nTimeout > 1800 nTimeout := 1800 - endif + ENDIF nDone := Seconds() + iif( nTimeout >= 0, nTimeout, 0 ) - while tp_OutFree( nPort ) > 0 .AND. ; + DO WHILE tp_OutFree( nPort ) > 0 .AND. ; ( nTimeout < 0 .OR. Seconds() < nDone ) - hb_IdleState() - enddo + hb_IdleState() + ENDDO -return iif( tp_OutFree( nPort ) > 0, TE_TMOUT, 0 ) + RETURN iif( tp_OutFree( nPort ) > 0, TE_TMOUT, 0 ) #endif - - /* /// sorry, but ctrldsr and ctrlcts will act like isdsr and iscts... if you want /// flow control, talk to the system. -function tp_ctrldsr( nPort ) -return tp_isdsr( nPort ) +FUNCTION tp_ctrldsr( nPort ) + RETURN tp_isdsr( nPort ) /// you can't do these things. try rc.serial -function tp_shared -return 0 - -function tp_setport -return 0 - +FUNCTION tp_shared + RETURN 0 +FUNCTION tp_setport + RETURN 0 */ // internal (static) functions --------------------------------------------------- -static function isopenport( nPort ) +STATIC FUNCTION isopenport( nPort ) - if ! isport( nPort ) - return .f. - endif + IF ! isport( nPort ) + RETURN .F. + ENDIF -return t_aPorts[ nPort, TPFP_OC ] + RETURN t_aPorts[ nPort, TPFP_OC ] +STATIC FUNCTION isport( nPort ) + IF ! ISNUMBER( nPort ) .OR. nPort < 1 .OR. nPort > TP_MAXPORTS + RETURN .F. + ENDIF -static function isport( nPort ) + RETURN .T. - if ! ISNUMBER( nPort ) .OR. nPort < 1 .OR. nPort > TP_MAXPORTS - return .f. - endif +STATIC FUNCTION FetchChars( nPort ) -return .t. + LOCAL cStr - - -static function FetchChars( nPort ) - - local cStr - - if ! isopenport( nPort ) - return 0 - endif + IF ! isopenport( nPort ) + RETURN 0 + ENDIF cStr := p_ReadPort( t_aPorts[ nPort, TPFP_HANDLE ] ) - if Len( cStr ) > 0 + IF Len( cStr ) > 0 t_aPorts[ nPort, TPFP_INBUF ] += cStr - endif - -return Len( cStr ) - + ENDIF + RETURN Len( cStr ) INIT PROCEDURE _tpinit() - local x + LOCAL x - if t_aPorts == nil - t_aPorts := array( TP_MAXPORTS ) - for x := 1 to len( t_aPorts ) + IF t_aPorts == NIL + t_aPorts := Array( TP_MAXPORTS ) + FOR x := 1 TO Len( t_aPorts ) /// port name, file handle, baud, data bits, parity, stop bits, Open?, input buffer, input buff.size t_aPorts[ x ] := { "", -1, 1200, 8, "N", 1, .F., "", 0 } - next - endif - -return - - + NEXT + ENDIF + RETURN /* /// you can uncomment the following section for compatability with TP code... I figured /// you'd probably want them commented so it won't compile so that you would see where /// you have potential incomplete port problems -///function tp_mstat -///return "" +///FUNCTION tp_mstat +/// RETURN "" /// -///function tp_szmodem -///return 0 +///FUNCTION tp_szmodem +/// RETURN 0 /// -///function tp_noteoff -///return 0 +///FUNCTION tp_noteoff +/// RETURN 0 /// -///function tp_ontime -///return 0 +///FUNCTION tp_ontime +/// RETURN 0 /// -///function tp_rzmodem -///return 0 +///FUNCTION tp_rzmodem +/// RETURN 0 /// -///function tp_error -///return 0 +///FUNCTION tp_error +/// RETURN 0 /// -///function tp_errmsg -///return "" +///FUNCTION tp_errmsg +/// RETURN "" /// -///function tp_fifo -///return 0 +///FUNCTION tp_fifo +/// RETURN 0 /// /// -///function tp_outchrs -///return 0 +///FUNCTION tp_outchrs +/// RETURN 0 /// -///function tp_keybd -///return 0 +///FUNCTION tp_keybd +/// RETURN 0 /// /// tp_debug is not a real TP function. I included it so you can define your own debug @@ -859,11 +792,11 @@ return /// the global debug level I print the message. Since I don't have your system globals, /// I will ignore the first parameter and always print it. /// I recommend you modify this function to suit your own debugging needs -function tp_debug( nDebugLevel, cString ) +FUNCTION tp_debug( nDebugLevel, cString ) ? cString -return nil + RETURN NIL */ -procedure tp_uninstall() +PROCEDURE tp_uninstall() /* NOTE: dummy function, solely for compatibility. */ - return + RETURN diff --git a/harbour/contrib/hbtpathy/tpwin.c b/harbour/contrib/hbtpathy/tpwin.c index b3c408bb5b..890e1d4659 100644 --- a/harbour/contrib/hbtpathy/tpwin.c +++ b/harbour/contrib/hbtpathy/tpwin.c @@ -120,4 +120,12 @@ HB_FUNC( P_WRITEPORT ) hb_retnl( bRet ? ( long ) nWritten : -1 ); /* Put GetLastError() on error, or better a second byref param? */ } +/* TODO: Implement these dummy functions. */ +HB_FUNC( P_OUTFREE ) {} +HB_FUNC( P_CTRLCTS ) {} +HB_FUNC( P_ISDCD ) {} +HB_FUNC( P_ISRI ) {} +HB_FUNC( P_ISDSR ) {} +HB_FUNC( P_ISCTS ) {} + #endif /* HB_OS_WIN */ diff --git a/harbour/contrib/hbwin/win_prt.c b/harbour/contrib/hbwin/win_prt.c index 03ed641f12..55baec62e8 100644 --- a/harbour/contrib/hbwin/win_prt.c +++ b/harbour/contrib/hbwin/win_prt.c @@ -53,9 +53,10 @@ #define HB_OS_WIN_USED #include "hbapi.h" +#include "hbapierr.h" #include "hbwin.h" -#include +//#include /* Waste some space ! */ static struct @@ -79,743 +80,822 @@ static struct { INVALID_HANDLE_VALUE, TEXT( "\\\\.\\COM13" ) }, { INVALID_HANDLE_VALUE, TEXT( "\\\\.\\COM14" ) }, { INVALID_HANDLE_VALUE, TEXT( "\\\\.\\COM15" ) }, - { INVALID_HANDLE_VALUE, TEXT( "\\\\.\\COM16" ) } + { INVALID_HANDLE_VALUE, TEXT( "\\\\.\\COM16" ) }, + { INVALID_HANDLE_VALUE, TEXT( "\\\\.\\COM17" ) }, + { INVALID_HANDLE_VALUE, TEXT( "\\\\.\\COM18" ) }, + { INVALID_HANDLE_VALUE, TEXT( "\\\\.\\COM19" ) }, + { INVALID_HANDLE_VALUE, TEXT( "\\\\.\\COM20" ) }, + { INVALID_HANDLE_VALUE, TEXT( "\\\\.\\COM21" ) }, + { INVALID_HANDLE_VALUE, TEXT( "\\\\.\\COM22" ) }, + { INVALID_HANDLE_VALUE, TEXT( "\\\\.\\COM23" ) }, + { INVALID_HANDLE_VALUE, TEXT( "\\\\.\\COM24" ) }, + { INVALID_HANDLE_VALUE, TEXT( "\\\\.\\COM25" ) }, + { INVALID_HANDLE_VALUE, TEXT( "\\\\.\\COM26" ) }, + { INVALID_HANDLE_VALUE, TEXT( "\\\\.\\COM27" ) }, + { INVALID_HANDLE_VALUE, TEXT( "\\\\.\\COM28" ) }, + { INVALID_HANDLE_VALUE, TEXT( "\\\\.\\COM29" ) }, + { INVALID_HANDLE_VALUE, TEXT( "\\\\.\\COM30" ) }, + { INVALID_HANDLE_VALUE, TEXT( "\\\\.\\COM31" ) }, + { INVALID_HANDLE_VALUE, TEXT( "\\\\.\\COM32" ) } }; static struct { DCB OldDCB; COMMTIMEOUTS OldTimeouts; -} s_PortData2[ 16 ]; +} s_PortData2[ 32 ]; -static int s_WinFcn = 0; -static DWORD s_WinError = 0; +static int s_iWinFcn = 0; +static DWORD s_dwWinError = 0; -static int s_ReadIntervalTimeout = -1; /* -1 says use default calculation */ -static int s_ReadTotalTimeoutMultiplier = -1; -static int s_ReadTotalTimeoutConstant = -1; -static int s_WriteTotalTimeoutMultiplier = -1; -static int s_WriteTotalTimeoutConstant = -1; +static int s_iReadIntervalTimeout = -1; /* -1 says use default calculation */ +static int s_iReadTotalTimeoutMultiplier = -1; +static int s_iReadTotalTimeoutConstant = -1; +static int s_iWriteTotalTimeoutMultiplier = -1; +static int s_iWriteTotalTimeoutConstant = -1; -static int s_InQueue = -1; -static int s_OutQueue = -1; +static int s_iInQueue = -1; +static int s_iOutQueue = -1; HB_FUNC( WINPORTOPEN ) { int Port = hb_parni( 1 ); - LONG BaudRate = hb_parnl( 2 ); - int Parity = hb_parni( 3 ); - int ByteSize = hb_parni( 4 ); - int StopBits = hb_parni( 5 ); - /*LONG s_InQueue = hb_parnl( 6 ); */ - /*LONG s_OutQueue = hb_parnl( 7 ); */ + int iPort = hb_parni( 1 ); - HANDLE hCommPort; - COMMTIMEOUTS NewTimeouts; - DCB NewDCB; - - s_WinFcn = FCNCREATEFILE; - s_WinError = 0; - if( ( hCommPort = CreateFile( s_PortData[ Port ].Name, - GENERIC_READ | GENERIC_WRITE, - 0, - 0, - OPEN_EXISTING, - FILE_FLAG_NO_BUFFERING, 0 ) ) == INVALID_HANDLE_VALUE ) + if( iPort >= 0 && iPort < ( int ) HB_SIZEOFARRAY( s_PortData ) ) { - s_WinError = GetLastError(); - hb_retnl( -1 ); - return; - } + DWORD dwBaudRate = ( DWORD ) hb_parnl( 2 ); + int iParity = hb_parni( 3 ); + int iByteSize = hb_parni( 4 ); + int iStopBits = hb_parni( 5 ); + /*LONG s_iInQueue = hb_parnl( 6 ); */ + /*LONG s_iOutQueue = hb_parnl( 7 ); */ - s_WinFcn = FCNGETCOMMSTATE; - s_WinError = 0; + HANDLE hCommPort; + COMMTIMEOUTS NewTimeouts; + DCB NewDCB; - /* We'll put everything back */ - s_PortData2[ Port ].OldDCB.DCBlength = sizeof( DCB ); - if( ! GetCommState( hCommPort, &( s_PortData2[ Port ].OldDCB ) ) ) - { - s_WinError = GetLastError(); - CloseHandle( hCommPort ); - hb_retnl( -1 ); - return; - } - - NewDCB.DCBlength = sizeof( DCB ); - if( ! GetCommState( hCommPort, &NewDCB ) ) - { - s_WinError = GetLastError(); - CloseHandle( hCommPort ); - hb_retnl( -1 ); - return; - } - - /* Initialised with NO flow control or control signals! */ - NewDCB.BaudRate = ( DWORD ) BaudRate; - NewDCB.fBinary = 1; - NewDCB.fParity = 0; - NewDCB.fOutxCtsFlow = 0; - NewDCB.fOutxDsrFlow = 0; - NewDCB.fDtrControl = DTR_CONTROL_DISABLE; - NewDCB.fDsrSensitivity = 0; - NewDCB.fTXContinueOnXoff = 1; - NewDCB.fOutX = 0; - NewDCB.fInX = 0; - NewDCB.fErrorChar = 1; - NewDCB.fNull = 0; - NewDCB.fRtsControl = RTS_CONTROL_DISABLE; - NewDCB.fAbortOnError = 0; - /*NewDCB.XonLim*/ - /*NewDCB.XoffLim*/ - NewDCB.ByteSize = ( BYTE ) ByteSize; - NewDCB.Parity = ( BYTE ) Parity; - NewDCB.StopBits = ( BYTE ) StopBits; - /*NewDCB.XonChar*/ - /*NewDCB.XoffChar*/ - NewDCB.ErrorChar = '?'; - /*NewDCB.EofChar*/ - /*NewDCB.EvtChar*/ - - /* function reinitializes all hardware and control settings, but it does not empty output or input queues */ - s_WinFcn = FCNSETCOMMSTATE; - s_WinError = 0; - if( ! SetCommState( hCommPort, &NewDCB ) ) - { - s_WinError = GetLastError(); - CloseHandle( hCommPort ); - hb_retnl( -1 ); - return; - } - - /* We'll leave this to Windows, unless you really want it changed! */ - if( s_InQueue != -1 ) - { - s_WinFcn = FCNSETUPCOMM; - s_WinError = 0; - if( ! SetupComm( hCommPort, s_InQueue, s_OutQueue ) ) + s_iWinFcn = FCNCREATEFILE; + s_dwWinError = 0; + if( ( hCommPort = CreateFile( s_PortData[ iPort ].Name, + GENERIC_READ | GENERIC_WRITE, + 0, + 0, + OPEN_EXISTING, + FILE_FLAG_NO_BUFFERING, 0 ) ) == INVALID_HANDLE_VALUE ) { - s_WinError = GetLastError(); + s_dwWinError = GetLastError(); + hb_retnl( -1 ); + return; + } + + s_iWinFcn = FCNGETCOMMSTATE; + s_dwWinError = 0; + + /* We'll put everything back */ + s_PortData2[ Port ].OldDCB.DCBlength = sizeof( DCB ); + if( ! GetCommState( hCommPort, &( s_PortData2[ Port ].OldDCB ) ) ) + { + s_dwWinError = GetLastError(); CloseHandle( hCommPort ); hb_retnl( -1 ); return; } - } - /* We'll put everything back */ - s_WinFcn = FCNGETCOMMTIMEOUTS; - s_WinError = 0; - if( ! GetCommTimeouts( hCommPort, &( s_PortData2[ Port ].OldTimeouts ) ) ) - { - s_WinError = GetLastError(); - CloseHandle( hCommPort ); - hb_retnl( -1 ); - return; - } + NewDCB.DCBlength = sizeof( DCB ); + if( ! GetCommState( hCommPort, &NewDCB ) ) + { + s_dwWinError = GetLastError(); + CloseHandle( hCommPort ); + hb_retnl( -1 ); + return; + } - /* Maximum time, in milliseconds, allowed to elapse between the arrival of two characters on - the communications line. During a ReadFile operation, the time period begins when the first - character is received. If the interval between the arrival of any two characters exceeds this - amount, the ReadFile operation is completed and any buffered data is returned. A value of zero - indicates that interval time-outs are not used. */ + /* Initialised with NO flow control or control signals! */ + NewDCB.BaudRate = dwBaudRate; + NewDCB.fBinary = 1; + NewDCB.fParity = 0; + NewDCB.fOutxCtsFlow = 0; + NewDCB.fOutxDsrFlow = 0; + NewDCB.fDtrControl = DTR_CONTROL_DISABLE; + NewDCB.fDsrSensitivity = 0; + NewDCB.fTXContinueOnXoff = 1; + NewDCB.fOutX = 0; + NewDCB.fInX = 0; + NewDCB.fErrorChar = 1; + NewDCB.fNull = 0; + NewDCB.fRtsControl = RTS_CONTROL_DISABLE; + NewDCB.fAbortOnError = 0; + /*NewDCB.XonLim*/ + /*NewDCB.XoffLim*/ + NewDCB.ByteSize = ( BYTE ) iByteSize; + NewDCB.Parity = ( BYTE ) iParity; + NewDCB.StopBits = ( BYTE ) iStopBits; + /*NewDCB.XonChar*/ + /*NewDCB.XoffChar*/ + NewDCB.ErrorChar = '?'; + /*NewDCB.EofChar*/ + /*NewDCB.EvtChar*/ - /* A value of MAXDWORD, combined with zero values for both the s_ReadTotalTimeoutConstant and - s_ReadTotalTimeoutMultiplier members, specifies that the read operation is to return - immediately with the characters that have already been received, even if no characters - have been received. */ - NewTimeouts.ReadIntervalTimeout = ( s_ReadIntervalTimeout == -1 ? MAXDWORD : ( DWORD ) s_ReadIntervalTimeout ); + /* function reinitializes all hardware and control settings, but it does not empty output or input queues */ + s_iWinFcn = FCNSETCOMMSTATE; + s_dwWinError = 0; + if( ! SetCommState( hCommPort, &NewDCB ) ) + { + s_dwWinError = GetLastError(); + CloseHandle( hCommPort ); + hb_retnl( -1 ); + return; + } - /* Multiplier, in milliseconds, used to calculate the total time-out period for read operations. - For each read operation, this value is multiplied by the requested number of bytes to be read. */ - NewTimeouts.ReadTotalTimeoutMultiplier = ( s_ReadTotalTimeoutMultiplier == -1 ? 0 : s_ReadTotalTimeoutMultiplier ); + /* We'll leave this to Windows, unless you really want it changed! */ + if( s_iInQueue != -1 ) + { + s_iWinFcn = FCNSETUPCOMM; + s_dwWinError = 0; + if( ! SetupComm( hCommPort, s_iInQueue, s_iOutQueue ) ) + { + s_dwWinError = GetLastError(); + CloseHandle( hCommPort ); + hb_retnl( -1 ); + return; + } + } - /* Constant, in milliseconds, used to calculate the total time-out period for read operations. - For each read operation, this value is added to the product of the s_ReadTotalTimeoutMultiplier - member and the requested number of bytes. */ - NewTimeouts.ReadTotalTimeoutConstant = ( s_ReadTotalTimeoutConstant == -1 ? 0 : s_ReadTotalTimeoutConstant ); + /* We'll put everything back */ + s_iWinFcn = FCNGETCOMMTIMEOUTS; + s_dwWinError = 0; + if( ! GetCommTimeouts( hCommPort, &( s_PortData2[ Port ].OldTimeouts ) ) ) + { + s_dwWinError = GetLastError(); + CloseHandle( hCommPort ); + hb_retnl( -1 ); + return; + } - /* A value of zero for both the s_ReadTotalTimeoutMultiplier and s_ReadTotalTimeoutConstant members - indicates that total time-outs are not used for read operations ... - and MAXDWORD, 0 and 0 are what we use by default */ + /* Maximum time, in milliseconds, allowed to elapse between the arrival of two characters on + the communications line. During a ReadFile operation, the time period begins when the first + character is received. If the interval between the arrival of any two characters exceeds this + amount, the ReadFile operation is completed and any buffered data is returned. A value of zero + indicates that interval time-outs are not used. */ - /* Multiplier, in milliseconds, used to calculate the total time-out period for write operations. - For each write operation, this value is multiplied by the number of bytes to be written. */ - if( s_WriteTotalTimeoutMultiplier == -1 ) - { - /* float of 1.0 makes whole expression float */ - NewTimeouts.WriteTotalTimeoutMultiplier = HB_MIN( 1, ( DWORD ) ( ( 1.0 / BaudRate ) * - ( ByteSize + 1 + ( Parity == NOPARITY ? 0 : 1 ) + ( StopBits == ONESTOPBIT ? 1 : StopBits == ONE5STOPBITS ? 1.5 : 2 ) ) * 1000 ) ); - } - /* Constant, in milliseconds, used to calculate the total time-out period for write operations. - For each write operation, this value is added to the product of the s_WriteTotalTimeoutMultiplier member and the number of bytes to be written. */ - else - NewTimeouts.WriteTotalTimeoutMultiplier = s_WriteTotalTimeoutMultiplier; + /* A value of MAXDWORD, combined with zero values for both the s_iReadTotalTimeoutConstant and + s_iReadTotalTimeoutMultiplier members, specifies that the read operation is to return + immediately with the characters that have already been received, even if no characters + have been received. */ + NewTimeouts.ReadIntervalTimeout = ( s_iReadIntervalTimeout == -1 ? MAXDWORD : ( DWORD ) s_iReadIntervalTimeout ); - /* 50 ms is a thumbsuck - seems long enough and not too long! */ - NewTimeouts.WriteTotalTimeoutConstant = s_WriteTotalTimeoutConstant == -1 ? 50 : s_WriteTotalTimeoutConstant; + /* Multiplier, in milliseconds, used to calculate the total time-out period for read operations. + For each read operation, this value is multiplied by the requested number of bytes to be read. */ + NewTimeouts.ReadTotalTimeoutMultiplier = ( s_iReadTotalTimeoutMultiplier == -1 ? 0 : s_iReadTotalTimeoutMultiplier ); - /* A value of zero for both the s_WriteTotalTimeoutMultiplier and s_WriteTotalTimeoutConstant members - indicates that total time-outs are not used for write operations ... - and if flow control is enabled the program will "hang" or if it is not enabled the data will - be lost (potentially), so we set a minimum of 1ms (baud rates higher than 4800) */ + /* Constant, in milliseconds, used to calculate the total time-out period for read operations. + For each read operation, this value is added to the product of the s_iReadTotalTimeoutMultiplier + member and the requested number of bytes. */ + NewTimeouts.ReadTotalTimeoutConstant = ( s_iReadTotalTimeoutConstant == -1 ? 0 : s_iReadTotalTimeoutConstant ); - s_WinFcn = FCNSETCOMMTIMEOUTS; - s_WinError = 0; - if( ! SetCommTimeouts( hCommPort, &NewTimeouts ) ) - { - s_WinError = GetLastError(); - CloseHandle( hCommPort ); - hb_retnl( -1 ); + /* A value of zero for both the s_iReadTotalTimeoutMultiplier and s_iReadTotalTimeoutConstant members + indicates that total time-outs are not used for read operations ... + and MAXDWORD, 0 and 0 are what we use by default */ + + /* Multiplier, in milliseconds, used to calculate the total time-out period for write operations. + For each write operation, this value is multiplied by the number of bytes to be written. */ + if( s_iWriteTotalTimeoutMultiplier == -1 ) + { + /* float of 1.0 makes whole expression float */ + NewTimeouts.WriteTotalTimeoutMultiplier = HB_MIN( 1, ( DWORD ) ( ( 1.0 / dwBaudRate ) * + ( iByteSize + 1 + ( iParity == NOPARITY ? 0 : 1 ) + ( iStopBits == ONESTOPBIT ? 1 : iStopBits == ONE5STOPBITS ? 1.5 : 2 ) ) * 1000 ) ); + } + /* Constant, in milliseconds, used to calculate the total time-out period for write operations. + For each write operation, this value is added to the product of the s_iWriteTotalTimeoutMultiplier member and the number of bytes to be written. */ + else + NewTimeouts.WriteTotalTimeoutMultiplier = s_iWriteTotalTimeoutMultiplier; + + /* 50 ms is a thumbsuck - seems long enough and not too long! */ + NewTimeouts.WriteTotalTimeoutConstant = s_iWriteTotalTimeoutConstant == -1 ? 50 : s_iWriteTotalTimeoutConstant; + + /* A value of zero for both the s_iWriteTotalTimeoutMultiplier and s_iWriteTotalTimeoutConstant members + indicates that total time-outs are not used for write operations ... + and if flow control is enabled the program will "hang" or if it is not enabled the data will + be lost (potentially), so we set a minimum of 1ms (baud rates higher than 4800) */ + + s_iWinFcn = FCNSETCOMMTIMEOUTS; + s_dwWinError = 0; + if( ! SetCommTimeouts( hCommPort, &NewTimeouts ) ) + { + s_dwWinError = GetLastError(); + CloseHandle( hCommPort ); + hb_retnl( -1 ); + } + else + { + s_PortData[ Port ].Port = hCommPort; + hb_retnl( hCommPort == INVALID_HANDLE_VALUE ? -1 : 0 ); + } } else - { - s_PortData[ Port ].Port = hCommPort; - hb_retnl( hCommPort == INVALID_HANDLE_VALUE ? -1 : 0 ); - } + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } - HB_FUNC( WINPORTCLOSE ) { - int Port = hb_parni( 1 ); - long Drain = hb_parni( 2 ); - HANDLE hCommPort = s_PortData[ Port ].Port; + int iPort = hb_parni( 1 ); - s_WinFcn = FCNSETCOMMSTATE; - s_WinError = 0; - if( ! SetCommState( hCommPort, &( s_PortData2[ Port ].OldDCB ) ) ) + if( iPort >= 0 && iPort < ( int ) HB_SIZEOFARRAY( s_PortData ) ) { - s_WinError = GetLastError(); - CloseHandle( hCommPort ); - hb_retl( FALSE ); - return; + HANDLE hCommPort = s_PortData[ iPort ].Port; + long lDrain = hb_parnl( 2 ); + + s_iWinFcn = FCNSETCOMMSTATE; + s_dwWinError = 0; + if( ! SetCommState( hCommPort, &( s_PortData2[ iPort ].OldDCB ) ) ) + { + s_dwWinError = GetLastError(); + CloseHandle( hCommPort ); + hb_retl( FALSE ); + return; + } + + s_iWinFcn = FCNSETCOMMTIMEOUTS; + s_dwWinError = 0; + if( ! SetCommTimeouts( hCommPort, &( s_PortData2[ iPort ].OldTimeouts ) ) ) + { + s_dwWinError = GetLastError(); + CloseHandle( hCommPort ); + hb_retl( FALSE ); + return; + } + + s_PortData[ iPort ].Port = INVALID_HANDLE_VALUE; + + s_iWinFcn = FCNCLOSEHANDLE; + s_dwWinError = 0; + + /* I honestly don't know if this helps */ + if( lDrain > 0 ) + Sleep( lDrain * 1000 ); + + hb_retl( CloseHandle( hCommPort ) != 0 ); + s_dwWinError = GetLastError(); } - - s_WinFcn = FCNSETCOMMTIMEOUTS; - s_WinError = 0; - if( ! SetCommTimeouts( hCommPort, &( s_PortData2[ Port ].OldTimeouts ) ) ) - { - s_WinError = GetLastError(); - CloseHandle( hCommPort ); - hb_retl( FALSE ); - return; - } - - s_PortData[ Port ].Port = INVALID_HANDLE_VALUE; - - s_WinFcn = FCNCLOSEHANDLE; - s_WinError = 0; - - /* I honestly don't know if this helps */ - if( Drain > 0 ) - Sleep( Drain * 1000 ); - - hb_retl( CloseHandle( hCommPort ) != 0 ); - s_WinError = GetLastError(); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } - HB_FUNC( WINPORTWRITE ) { - int Port = hb_parni( 1 ); - const char * lpBuffer = hb_parcx( 2 ); - LONG NumberofBytesToWrite = hb_parclen( 2 ); - HANDLE hCommPort = s_PortData[ Port ].Port; - DWORD NumberofBytesWritten; + int iPort = hb_parni( 1 ); - s_WinFcn = FCNWRITEFILE; - s_WinError = 0; - if( ! WriteFile( hCommPort, lpBuffer, NumberofBytesToWrite, &NumberofBytesWritten, NULL ) ) + if( iPort >= 0 && iPort < ( int ) HB_SIZEOFARRAY( s_PortData ) ) { - s_WinError = GetLastError(); - hb_retnl( -1 ); + HANDLE hCommPort = s_PortData[ iPort ].Port; + const char * lpBuffer = hb_parcx( 2 ); + DWORD dwNumberofBytesToWrite = ( DWORD ) hb_parclen( 2 ); + DWORD dwNumberofBytesWritten; + + s_iWinFcn = FCNWRITEFILE; + s_dwWinError = 0; + if( ! WriteFile( hCommPort, lpBuffer, dwNumberofBytesToWrite, &dwNumberofBytesWritten, NULL ) ) + { + s_dwWinError = GetLastError(); + hb_retnl( -1 ); + } + else + hb_retnl( dwNumberofBytesWritten ); } else - hb_retnl( NumberofBytesWritten ); + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } - HB_FUNC( WINPORTREAD ) { - int Port = hb_parni( 1 ); - char * lpBuffer; - LONG NumberOfBytesToRead = hb_parclen( 2 ); - HANDLE hCommPort = s_PortData[ Port ].Port; - DWORD NumberOfBytesRead; + int iPort = hb_parni( 1 ); - lpBuffer = ( char * ) hb_xgrab( NumberOfBytesToRead + 1 ); - s_WinFcn = FCNREADFILE; - s_WinError = 0; - if( ! ReadFile( hCommPort, lpBuffer, NumberOfBytesToRead, &NumberOfBytesRead, NULL ) ) + if( iPort >= 0 && iPort < ( int ) HB_SIZEOFARRAY( s_PortData ) ) { - s_WinError = GetLastError(); - hb_retnl( -1 ); + HANDLE hCommPort = s_PortData[ iPort ].Port; + char * lpBuffer; + DWORD dwNumberOfBytesToRead = ( DWORD ) hb_parclen( 2 ); + DWORD dwNumberOfBytesRead; + + lpBuffer = ( char * ) hb_xgrab( dwNumberOfBytesToRead + 1 ); + s_iWinFcn = FCNREADFILE; + s_dwWinError = 0; + if( ! ReadFile( hCommPort, lpBuffer, dwNumberOfBytesToRead, &dwNumberOfBytesRead, NULL ) ) + { + s_dwWinError = GetLastError(); + hb_retnl( -1 ); + } + else + { + if( ! hb_storclen_buffer( lpBuffer, dwNumberOfBytesRead, 2 ) ) + hb_xfree( lpBuffer ); + hb_retnl( dwNumberOfBytesRead ); + } } else - { - if( ! hb_storclen_buffer( lpBuffer, NumberOfBytesRead, 2 ) ) - hb_xfree( lpBuffer ); - hb_retnl( NumberOfBytesRead ); - } + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } - HB_FUNC( WINPORTSTATUS ) { - int Port = hb_parni( 1 ); - HANDLE hCommPort = s_PortData[ Port ].Port; - DWORD ModemStat; + int iPort = hb_parni( 1 ); - s_WinFcn = FCNGETCOMMMODEMSTATUS; - s_WinError = 0; - if( ! GetCommModemStatus( hCommPort, &ModemStat ) ) + if( iPort >= 0 && iPort < ( int ) HB_SIZEOFARRAY( s_PortData ) ) { - s_WinError = GetLastError(); - hb_retl( FALSE ); + HANDLE hCommPort = s_PortData[ iPort ].Port; + DWORD dwModemStat; + + s_iWinFcn = FCNGETCOMMMODEMSTATUS; + s_dwWinError = 0; + if( ! GetCommModemStatus( hCommPort, &dwModemStat ) ) + { + s_dwWinError = GetLastError(); + hb_retl( FALSE ); + } + else + { + hb_storl( ( dwModemStat & MS_CTS_ON ) != 0, 2 ); /* The CTS (clear-to-send) signal is on. */ + hb_storl( ( dwModemStat & MS_DSR_ON ) != 0, 3 ); /* The DSR (data-set-ready) signal is on. */ + hb_storl( ( dwModemStat & MS_RING_ON ) != 0, 4 ); /* The ring indicator signal is on. */ + hb_storl( ( dwModemStat & MS_RLSD_ON ) != 0, 5 ); /* The RLSD (receive-line-signal-detect) signal is on. Also is DCD. */ + + hb_retl( TRUE ); + } } else - { - hb_storl( ( ModemStat & MS_CTS_ON ) != 0, 2 ); /* The CTS (clear-to-send) signal is on. */ - hb_storl( ( ModemStat & MS_DSR_ON ) != 0, 3 ); /* The DSR (data-set-ready) signal is on. */ - hb_storl( ( ModemStat & MS_RING_ON ) != 0, 4 ); /* The ring indicator signal is on. */ - hb_storl( ( ModemStat & MS_RLSD_ON ) != 0, 5 ); /* The RLSD (receive-line-signal-detect) signal is on. Also is DCD. */ - - hb_retl( TRUE ); - } + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } - HB_FUNC( WINPORTPURGE ) { - int Port = hb_parni( 1 ); - HANDLE hCommPort = s_PortData[ Port ].Port; - DWORD Flags; + int iPort = hb_parni( 1 ); - Flags = ( hb_parl( 2 ) ? PURGE_RXCLEAR : 0 ) | ( hb_parl( 3 ) ? PURGE_TXCLEAR : 0 ); - s_WinFcn = FCNPURGECOMM; - s_WinError = 0; - if( ! PurgeComm( hCommPort, Flags ) ) + if( iPort >= 0 && iPort < ( int ) HB_SIZEOFARRAY( s_PortData ) ) { - s_WinError = GetLastError(); - hb_retl( FALSE ); + HANDLE hCommPort = s_PortData[ iPort ].Port; + DWORD dwFlags; + + dwFlags = ( hb_parl( 2 ) ? PURGE_RXCLEAR : 0 ) | ( hb_parl( 3 ) ? PURGE_TXCLEAR : 0 ); + s_iWinFcn = FCNPURGECOMM; + s_dwWinError = 0; + if( ! PurgeComm( hCommPort, dwFlags ) ) + { + s_dwWinError = GetLastError(); + hb_retl( FALSE ); + } + else + hb_retl( TRUE ); } else - hb_retl( TRUE ); + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } - HB_FUNC( WINPORTQUEUESTATUS ) { - int Port = hb_parni( 1 ); - HANDLE hCommPort = s_PortData[ Port ].Port; - DWORD Errors; - COMSTAT ComStat; + int iPort = hb_parni( 1 ); - s_WinFcn = FCNCLEARCOMMERROR; - s_WinError = 0; - if( ! ClearCommError( hCommPort, &Errors, &ComStat ) ) + if( iPort >= 0 && iPort < ( int ) HB_SIZEOFARRAY( s_PortData ) ) { - s_WinError = GetLastError(); - hb_retl( FALSE ); + HANDLE hCommPort = s_PortData[ iPort ].Port; + DWORD dwErrors; + COMSTAT ComStat; + + s_iWinFcn = FCNCLEARCOMMERROR; + s_dwWinError = 0; + if( ! ClearCommError( hCommPort, &dwErrors, &ComStat ) ) + { + s_dwWinError = GetLastError(); + hb_retl( FALSE ); + } + else + { + hb_storl( ComStat.fCtsHold, 2 ); + hb_storl( ComStat.fDsrHold, 3 ); + hb_storl( ComStat.fRlsdHold, 4 ); + hb_storl( ComStat.fXoffHold, 5 ); + hb_storl( ComStat.fXoffSent, 6 ); + hb_stornl( ComStat.cbInQue, 7 ); + hb_stornl( ComStat.cbOutQue, 8 ); /* This value will be zero for a nonoverlapped write */ + + hb_retl( TRUE ); + } } else - { - hb_storl( ComStat.fCtsHold, 2 ); - hb_storl( ComStat.fDsrHold, 3 ); - hb_storl( ComStat.fRlsdHold, 4 ); - hb_storl( ComStat.fXoffHold, 5 ); - hb_storl( ComStat.fXoffSent, 6 ); - hb_stornl( ComStat.cbInQue, 7 ); - hb_stornl( ComStat.cbOutQue, 8 ); /* This value will be zero for a nonoverlapped write */ - - hb_retl( TRUE ); - } + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } - /* If handshaking is enabled, it is an error for the application to adjust the line by using the EscapeCommFunction function */ HB_FUNC( WINPORTSETRTS ) { - int Port = hb_parni( 1 ); - HANDLE hCommPort = s_PortData[ Port ].Port; - DWORD Func = hb_parl( 2 ) ? SETRTS : CLRRTS; + int iPort = hb_parni( 1 ); - s_WinFcn = ESCAPECOMMFUNCTION; - s_WinError = 0; - if( ! EscapeCommFunction( hCommPort, Func ) ) + if( iPort >= 0 && iPort < ( int ) HB_SIZEOFARRAY( s_PortData ) ) { - s_WinError = GetLastError(); - hb_retl( FALSE ); + HANDLE hCommPort = s_PortData[ iPort ].Port; + DWORD dwFunc = hb_parl( 2 ) ? SETRTS : CLRRTS; + + s_iWinFcn = ESCAPECOMMFUNCTION; + s_dwWinError = 0; + if( ! EscapeCommFunction( hCommPort, dwFunc ) ) + { + s_dwWinError = GetLastError(); + hb_retl( FALSE ); + } + else + hb_retl( TRUE ); } else - hb_retl( TRUE ); + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } - /* If handshaking is enabled, it is an error for the application to adjust the line by using the EscapeCommFunction function */ HB_FUNC( WINPORTSETDTR ) { - int Port = hb_parni( 1 ); - HANDLE hCommPort = s_PortData[ Port ].Port; - DWORD Func = hb_parl( 2 ) ? SETDTR : CLRDTR; + int iPort = hb_parni( 1 ); - s_WinFcn = ESCAPECOMMFUNCTION; - s_WinError = 0; - if( ! EscapeCommFunction( hCommPort, Func ) ) + if( iPort >= 0 && iPort < ( int ) HB_SIZEOFARRAY( s_PortData ) ) { - s_WinError = GetLastError(); - hb_retl( FALSE ); + HANDLE hCommPort = s_PortData[ iPort ].Port; + DWORD dwFunc = hb_parl( 2 ) ? SETDTR : CLRDTR; + + s_iWinFcn = ESCAPECOMMFUNCTION; + s_dwWinError = 0; + if( ! EscapeCommFunction( hCommPort, dwFunc ) ) + { + s_dwWinError = GetLastError(); + hb_retl( FALSE ); + } + else + hb_retl( TRUE ); } else - hb_retl( TRUE ); + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } - HB_FUNC( WINPORTRTSFLOW ) { - int Port = hb_parni( 1 ); - HANDLE hCommPort = s_PortData[ Port ].Port; - DCB CurDCB; - int RtsControl = hb_parni( 2 ); + int iPort = hb_parni( 1 ); - s_WinFcn = FCNGETCOMMSTATE; - s_WinError = 0; - CurDCB.DCBlength = sizeof( DCB ); - if( ! GetCommState( hCommPort, &CurDCB ) ) + if( iPort >= 0 && iPort < ( int ) HB_SIZEOFARRAY( s_PortData ) ) { - s_WinError = GetLastError(); - hb_retl( FALSE ); - return; - } + HANDLE hCommPort = s_PortData[ iPort ].Port; + DCB CurDCB; + int iRtsControl = hb_parni( 2 ); - if( RtsControl == RTS_CONTROL_DISABLE ) - { - CurDCB.fOutxCtsFlow = 0; - CurDCB.fRtsControl = RTS_CONTROL_DISABLE; - } - else if( RtsControl == RTS_CONTROL_ENABLE ) - { - CurDCB.fOutxCtsFlow = 1; - CurDCB.fRtsControl = RTS_CONTROL_ENABLE; - } - else if( RtsControl == RTS_CONTROL_HANDSHAKE ) - { - CurDCB.fOutxCtsFlow = 1; - CurDCB.fRtsControl = RTS_CONTROL_HANDSHAKE; - } - else /* RTS_CONTROL_TOGGLE - RS485? */ - { - hb_retl( FALSE ); - return; - } + s_iWinFcn = FCNGETCOMMSTATE; + s_dwWinError = 0; + CurDCB.DCBlength = sizeof( DCB ); + if( ! GetCommState( hCommPort, &CurDCB ) ) + { + s_dwWinError = GetLastError(); + hb_retl( FALSE ); + return; + } - s_WinFcn = FCNSETCOMMSTATE; - s_WinError = 0; - if( ! SetCommState( hCommPort, &CurDCB ) ) - { - s_WinError = GetLastError(); - hb_retl( FALSE ); + if( iRtsControl == RTS_CONTROL_DISABLE ) + { + CurDCB.fOutxCtsFlow = 0; + CurDCB.fRtsControl = RTS_CONTROL_DISABLE; + } + else if( iRtsControl == RTS_CONTROL_ENABLE ) + { + CurDCB.fOutxCtsFlow = 1; + CurDCB.fRtsControl = RTS_CONTROL_ENABLE; + } + else if( iRtsControl == RTS_CONTROL_HANDSHAKE ) + { + CurDCB.fOutxCtsFlow = 1; + CurDCB.fRtsControl = RTS_CONTROL_HANDSHAKE; + } + else /* RTS_CONTROL_TOGGLE - RS485? */ + { + hb_retl( FALSE ); + return; + } + + s_iWinFcn = FCNSETCOMMSTATE; + s_dwWinError = 0; + if( ! SetCommState( hCommPort, &CurDCB ) ) + { + s_dwWinError = GetLastError(); + hb_retl( FALSE ); + } + else + hb_retl( TRUE ); } else - hb_retl( TRUE ); + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } - HB_FUNC( WINPORTDTRFLOW ) { - int Port = hb_parni( 1 ); - HANDLE hCommPort = s_PortData[ Port ].Port; - DCB CurDCB; - int DtrControl = hb_parni( 2 ); + int iPort = hb_parni( 1 ); - s_WinFcn = FCNGETCOMMSTATE; - s_WinError = 0; - CurDCB.DCBlength = sizeof( DCB ); - if( ! GetCommState( hCommPort, &CurDCB ) ) + if( iPort >= 0 && iPort < ( int ) HB_SIZEOFARRAY( s_PortData ) ) { - s_WinError = GetLastError(); - hb_retl( FALSE ); - return; - } + HANDLE hCommPort = s_PortData[ iPort ].Port; + DCB CurDCB; + int DtrControl = hb_parni( 2 ); - if( DtrControl == DTR_CONTROL_DISABLE ) - { - CurDCB.fOutxDsrFlow = 0; - CurDCB.fDtrControl = DTR_CONTROL_DISABLE; - } - else if( DtrControl == DTR_CONTROL_ENABLE ) - { - CurDCB.fOutxDsrFlow = 1; - CurDCB.fDtrControl = DTR_CONTROL_ENABLE; - } - else if( DtrControl == DTR_CONTROL_HANDSHAKE ) - { - CurDCB.fOutxDsrFlow = 1; - CurDCB.fDtrControl = DTR_CONTROL_HANDSHAKE; + s_iWinFcn = FCNGETCOMMSTATE; + s_dwWinError = 0; + CurDCB.DCBlength = sizeof( DCB ); + if( ! GetCommState( hCommPort, &CurDCB ) ) + { + s_dwWinError = GetLastError(); + hb_retl( FALSE ); + return; + } + + if( DtrControl == DTR_CONTROL_DISABLE ) + { + CurDCB.fOutxDsrFlow = 0; + CurDCB.fDtrControl = DTR_CONTROL_DISABLE; + } + else if( DtrControl == DTR_CONTROL_ENABLE ) + { + CurDCB.fOutxDsrFlow = 1; + CurDCB.fDtrControl = DTR_CONTROL_ENABLE; + } + else if( DtrControl == DTR_CONTROL_HANDSHAKE ) + { + CurDCB.fOutxDsrFlow = 1; + CurDCB.fDtrControl = DTR_CONTROL_HANDSHAKE; + } + else + { + hb_retl( FALSE ); + return; + } + + s_iWinFcn = FCNSETCOMMSTATE; + s_dwWinError = 0; + if( ! SetCommState( hCommPort, &CurDCB ) ) + { + s_dwWinError = GetLastError(); + hb_retl( FALSE ); + } + else + hb_retl( TRUE ); } else - { - hb_retl( FALSE ); - return; - } - - s_WinFcn = FCNSETCOMMSTATE; - s_WinError = 0; - if( ! SetCommState( hCommPort, &CurDCB ) ) - { - s_WinError = GetLastError(); - hb_retl( FALSE ); - } - else - hb_retl( TRUE ); + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } - HB_FUNC( WINPORTXONXOFFFLOW ) { - int Port = hb_parni( 1 ); - HANDLE hCommPort = s_PortData[ Port ].Port; - DCB CurDCB; + int iPort = hb_parni( 1 ); - s_WinFcn = FCNGETCOMMSTATE; - s_WinError = 0; - CurDCB.DCBlength = sizeof( DCB ); - if( ! GetCommState( hCommPort, &CurDCB ) ) + if( iPort >= 0 && iPort < ( int ) HB_SIZEOFARRAY( s_PortData ) ) { - s_WinError = GetLastError(); - hb_retl( FALSE ); - return; - } + HANDLE hCommPort = s_PortData[ iPort ].Port; + DCB CurDCB; - if( hb_parl( 2 ) ) - { - CurDCB.fInX = 1; - CurDCB.fOutX = 1; + s_iWinFcn = FCNGETCOMMSTATE; + s_dwWinError = 0; + CurDCB.DCBlength = sizeof( DCB ); + if( ! GetCommState( hCommPort, &CurDCB ) ) + { + s_dwWinError = GetLastError(); + hb_retl( FALSE ); + return; + } + + if( hb_parl( 2 ) ) + { + CurDCB.fInX = 1; + CurDCB.fOutX = 1; + } + else + { + CurDCB.fInX = 0; + CurDCB.fOutX = 0; + } + + s_iWinFcn = FCNSETCOMMSTATE; + s_dwWinError = 0; + if( ! SetCommState( hCommPort, &CurDCB ) ) + { + s_dwWinError = GetLastError(); + hb_retl( FALSE ); + } + else + hb_retl( TRUE ); } else - { - CurDCB.fInX = 0; - CurDCB.fOutX = 0; - } - - s_WinFcn = FCNSETCOMMSTATE; - s_WinError = 0; - if( ! SetCommState( hCommPort, &CurDCB ) ) - { - s_WinError = GetLastError(); - hb_retl( FALSE ); - } - else - hb_retl( TRUE ); + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } - /* You can leave some out. If you pass them by reference you can save the current setting. */ HB_FUNC( WINPORTTIMEOUTS ) { - long Tmp; + int iTmp; if( HB_ISNUM( 1 ) ) { - Tmp = s_ReadIntervalTimeout; - s_ReadIntervalTimeout = hb_parni( 1 ); - hb_stornl( Tmp, 1 ); + iTmp = s_iReadIntervalTimeout; + s_iReadIntervalTimeout = hb_parni( 1 ); + hb_storni( iTmp, 1 ); } else - s_ReadIntervalTimeout = -1; + s_iReadIntervalTimeout = -1; if( HB_ISNUM( 2 ) ) { - Tmp = s_ReadTotalTimeoutMultiplier; - s_ReadTotalTimeoutMultiplier = hb_parni( 2 ); - hb_stornl( Tmp, 2 ); + iTmp = s_iReadTotalTimeoutMultiplier; + s_iReadTotalTimeoutMultiplier = hb_parni( 2 ); + hb_storni( iTmp, 2 ); } else - s_ReadTotalTimeoutMultiplier = -1; + s_iReadTotalTimeoutMultiplier = -1; if( HB_ISNUM( 3 ) ) { - Tmp = s_ReadTotalTimeoutConstant; - s_ReadTotalTimeoutConstant = hb_parni( 3 ); - hb_stornl( Tmp, 3 ); + iTmp = s_iReadTotalTimeoutConstant; + s_iReadTotalTimeoutConstant = hb_parni( 3 ); + hb_storni( iTmp, 3 ); } else - s_ReadTotalTimeoutConstant = -1; + s_iReadTotalTimeoutConstant = -1; if( HB_ISNUM( 4 ) ) { - Tmp = s_WriteTotalTimeoutMultiplier; - s_WriteTotalTimeoutMultiplier = hb_parni( 4 ); - hb_stornl( Tmp, 4 ); + iTmp = s_iWriteTotalTimeoutMultiplier; + s_iWriteTotalTimeoutMultiplier = hb_parni( 4 ); + hb_storni( iTmp, 4 ); } else - s_WriteTotalTimeoutMultiplier = -1; + s_iWriteTotalTimeoutMultiplier = -1; if( HB_ISNUM( 5 ) ) { - Tmp = s_WriteTotalTimeoutConstant; - s_WriteTotalTimeoutConstant = hb_parni( 5 ); - hb_stornl( Tmp, 5 ); + iTmp = s_iWriteTotalTimeoutConstant; + s_iWriteTotalTimeoutConstant = hb_parni( 5 ); + hb_storni( iTmp, 5 ); } else - s_WriteTotalTimeoutConstant = -1; + s_iWriteTotalTimeoutConstant = -1; } - /* You must set both! */ HB_FUNC( WINPORTBUFFERS ) { - s_InQueue = hb_parni( 1 ); - s_OutQueue = hb_parni( 2 ); + s_iInQueue = hb_parni( 1 ); + s_iOutQueue = hb_parni( 2 ); } - HB_FUNC( WINPORTERROR ) { - hb_retnl( s_WinError ); - s_WinError = 0; /* Note - reset */ + hb_retnl( s_dwWinError ); + s_dwWinError = 0; /* Note - reset */ } - HB_FUNC( WINPORTFCN ) { - hb_retni( s_WinFcn ); + hb_retni( s_iWinFcn ); } HB_FUNC( FORMATMESSAGE ) { - char Buffer[ 256 ] = ""; - DWORD Messageid = HB_ISNUM( 1 ) ? ( DWORD ) hb_parnl( 1 ) : GetLastError(); + char buffer[ 256 ] = ""; + DWORD dwMessageid = HB_ISNUM( 1 ) ? ( DWORD ) hb_parnl( 1 ) : GetLastError(); - if( FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, Messageid, MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), /* Default language */ - ( LPTSTR ) Buffer, sizeof( Buffer ), NULL) == 0 ) + if( FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwMessageid, MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), /* Default language */ + ( LPTSTR ) buffer, sizeof( buffer ), NULL) == 0 ) { - hb_snprintf( Buffer, sizeof( Buffer ), "FormatMessage() failed for message %ld.", Messageid ); + hb_snprintf( buffer, sizeof( buffer ), "FormatMessage() failed for message %ld.", dwMessageid ); } - hb_retc( Buffer ); + hb_retc( buffer ); } - HB_FUNC( WINPORTDEBUGDCB ) { - int Port = hb_parni( 1 ); - int DebugLevel = HB_ISNUM(2) ? hb_parni( 2 ) : WPDBGBASIC; - HANDLE hCommPort = s_PortData[ Port ].Port; - DCB CurDCB; - COMMTIMEOUTS CurCOMMTIMEOUTS; - COMMPROP CurCOMMPROP; - char DebugString[ 1024 ] = ""; - char Buffer[ 80 ]; + int iPort = hb_parni( 1 ); - s_WinFcn = FCNGETCOMMSTATE; - s_WinError = 0; - CurDCB.DCBlength = sizeof( DCB ); - if( GetCommState( hCommPort, &CurDCB ) ) + if( iPort >= 0 && iPort < ( int ) HB_SIZEOFARRAY( s_PortData ) ) { - if( DebugLevel & WPDBGBASIC ) + int iDebugLevel = HB_ISNUM( 2 ) ? hb_parni( 2 ) : WPDBGBASIC; + HANDLE hCommPort = s_PortData[ iPort ].Port; + DCB CurDCB; + COMMTIMEOUTS CurCOMMTIMEOUTS; + COMMPROP CurCOMMPROP; + char szDebugString[ 1024 ] = ""; + char buffer[ 80 ]; + + s_iWinFcn = FCNGETCOMMSTATE; + s_dwWinError = 0; + CurDCB.DCBlength = sizeof( DCB ); + if( GetCommState( hCommPort, &CurDCB ) ) { - hb_snprintf( Buffer, sizeof( Buffer ), "Baud : %lu\n", CurDCB.BaudRate ) ; hb_strncat( DebugString, Buffer, sizeof( DebugString ) - 1 ); - hb_snprintf( Buffer, sizeof( Buffer ), "ByteSize : %i\n" , CurDCB.ByteSize ) ; hb_strncat( DebugString, Buffer, sizeof( DebugString ) - 1 ); - hb_snprintf( Buffer, sizeof( Buffer ), "Parity : %i\n" , CurDCB.Parity ) ; hb_strncat( DebugString, Buffer, sizeof( DebugString ) - 1 ); - hb_snprintf( Buffer, sizeof( Buffer ), "StopBits : %i\n" , CurDCB.StopBits ) ; hb_strncat( DebugString, Buffer, sizeof( DebugString ) - 1 ); + if( iDebugLevel & WPDBGBASIC ) + { + hb_snprintf( buffer, sizeof( buffer ), "Baud : %lu\n", CurDCB.BaudRate ) ; hb_strncat( szDebugString, buffer, sizeof( szDebugString ) - 1 ); + hb_snprintf( buffer, sizeof( buffer ), "ByteSize : %i\n" , CurDCB.ByteSize ) ; hb_strncat( szDebugString, buffer, sizeof( szDebugString ) - 1 ); + hb_snprintf( buffer, sizeof( buffer ), "Parity : %i\n" , CurDCB.Parity ) ; hb_strncat( szDebugString, buffer, sizeof( szDebugString ) - 1 ); + hb_snprintf( buffer, sizeof( buffer ), "StopBits : %i\n" , CurDCB.StopBits ) ; hb_strncat( szDebugString, buffer, sizeof( szDebugString ) - 1 ); + } + if( iDebugLevel & WPDBGFLOW ) + { + hb_strncat( szDebugString, "fRtsControl : ", sizeof( szDebugString ) - 1 ); + hb_strncat( szDebugString, CurDCB.fRtsControl == RTS_CONTROL_DISABLE ? "RTS_CONTROL_DISABLE\n" : + CurDCB.fRtsControl == RTS_CONTROL_ENABLE ? "RTS_CONTROL_ENABLE\n" : + CurDCB.fRtsControl == RTS_CONTROL_HANDSHAKE ? "RTS_CONTROL_HANDSHAKE\n" : "RTS_CONTROL_TOGGLE\n", sizeof( szDebugString ) - 1 ); + hb_strncat( szDebugString, "fOutxCtsFlow : ", sizeof( szDebugString ) - 1 ); + hb_strncat( szDebugString, CurDCB.fOutxCtsFlow ? "true\n" : "false\n", sizeof( szDebugString ) - 1 ); + hb_strncat( szDebugString, "fOutX : ", sizeof( szDebugString ) - 1 ); + hb_strncat( szDebugString, CurDCB.fOutX ? "true\n" : "false\n", sizeof( szDebugString ) - 1 ); + hb_strncat( szDebugString, "fInX : ", sizeof( szDebugString ) - 1 ); + hb_strncat( szDebugString, CurDCB.fInX ? "true\n" : "false\n", sizeof( szDebugString ) - 1 ); + hb_strncat( szDebugString, "fDtrControl : ", sizeof( szDebugString ) - 1 ); + hb_strncat( szDebugString, CurDCB.fDtrControl == DTR_CONTROL_DISABLE ? "DTR_CONTROL_DISABLE\n" : + CurDCB.fDtrControl == DTR_CONTROL_ENABLE ? "DTR_CONTROL_ENABLE\n" : "DTR_CONTROL_HANDSHAKE\n", sizeof( szDebugString ) - 1 ); + hb_strncat( szDebugString, "fOutxDsrFlow : ", sizeof( szDebugString ) - 1 ); + hb_strncat( szDebugString, CurDCB.fOutxDsrFlow ? "true\n" : "false\n", sizeof( szDebugString ) - 1 ); + } + if( iDebugLevel & WPDBGXTRAFLOW ) + { + hb_strncat( szDebugString, "fDsrSensitivity : ", sizeof( szDebugString ) - 1 ); + hb_strncat( szDebugString, CurDCB.fDsrSensitivity ? "true\n" : "false\n", sizeof( szDebugString ) - 1 ); + hb_strncat( szDebugString, "fTXContinueOnXoff : ", sizeof( szDebugString ) - 1 ); + hb_strncat( szDebugString, CurDCB.fTXContinueOnXoff ? "true\n" : "false\n", sizeof( szDebugString ) - 1 ); + hb_snprintf( buffer, sizeof( buffer ), "XonLim : %i\n" , CurDCB.XonLim ) ; hb_strncat( szDebugString, buffer, sizeof( szDebugString ) - 1 ); + hb_snprintf( buffer, sizeof( buffer ), "XoffLim : %i\n" , CurDCB.XoffLim ) ; hb_strncat( szDebugString, buffer, sizeof( szDebugString ) - 1 ); + hb_snprintf( buffer, sizeof( buffer ), "XonChar : 0x%i\n" , CurDCB.XonChar ) ; hb_strncat( szDebugString, buffer, sizeof( szDebugString ) - 1 ); + hb_snprintf( buffer, sizeof( buffer ), "XoffChar : 0x%i\n", CurDCB.XoffChar ) ; hb_strncat( szDebugString, buffer, sizeof( szDebugString ) - 1 ); + } + if( iDebugLevel & WPDBGOTHER ) + { + hb_strncat(szDebugString, "fBinary : ", sizeof( szDebugString ) - 1 ); + hb_strncat(szDebugString, CurDCB.fBinary ? "true\n" : "false\n", sizeof( szDebugString ) - 1 ); + hb_strncat(szDebugString, "fParity : ", sizeof( szDebugString ) - 1 ); + hb_strncat(szDebugString, CurDCB.fParity ? "true\n" : "false\n", sizeof( szDebugString ) - 1 ); + hb_strncat(szDebugString, "fErrorChar : ", sizeof( szDebugString ) - 1 ); + hb_strncat(szDebugString, CurDCB.fErrorChar ? "true\n" : "false\n", sizeof( szDebugString ) - 1 ); + hb_strncat(szDebugString, "fNull : ", sizeof( szDebugString ) - 1 ); + hb_strncat(szDebugString, CurDCB.fNull ? "true\n" : "false\n", sizeof( szDebugString ) - 1 ); + hb_strncat(szDebugString, "fAbortOnError : ", sizeof( szDebugString ) - 1 ); + hb_strncat(szDebugString, CurDCB.fAbortOnError ? "true\n" : "false\n", sizeof( szDebugString ) - 1 ); + hb_snprintf( buffer, sizeof( buffer ), "ErrorChar : 0x%i\n", CurDCB.ErrorChar ) ; hb_strncat( szDebugString, buffer, sizeof( szDebugString ) - 1 ); + hb_snprintf( buffer, sizeof( buffer ), "EofChar : 0x%i\n" , CurDCB.EofChar ) ; hb_strncat( szDebugString, buffer, sizeof( szDebugString ) - 1 ); + hb_snprintf( buffer, sizeof( buffer ), "EvtChar : 0x%i\n" , CurDCB.EvtChar ) ; hb_strncat( szDebugString, buffer, sizeof( szDebugString ) - 1 ); + } } - if( DebugLevel & WPDBGFLOW ) + else { - hb_strncat( DebugString, "fRtsControl : ", sizeof( DebugString ) - 1 ); - hb_strncat( DebugString, CurDCB.fRtsControl == RTS_CONTROL_DISABLE ? "RTS_CONTROL_DISABLE\n" : - CurDCB.fRtsControl == RTS_CONTROL_ENABLE ? "RTS_CONTROL_ENABLE\n" : - CurDCB.fRtsControl == RTS_CONTROL_HANDSHAKE ? "RTS_CONTROL_HANDSHAKE\n" : "RTS_CONTROL_TOGGLE\n", sizeof( DebugString ) - 1 ); - hb_strncat( DebugString, "fOutxCtsFlow : ", sizeof( DebugString ) - 1 ); - hb_strncat( DebugString, CurDCB.fOutxCtsFlow ? "true\n" : "false\n", sizeof( DebugString ) - 1 ); - hb_strncat( DebugString, "fOutX : ", sizeof( DebugString ) - 1 ); - hb_strncat( DebugString, CurDCB.fOutX ? "true\n" : "false\n", sizeof( DebugString ) - 1 ); - hb_strncat( DebugString, "fInX : ", sizeof( DebugString ) - 1 ); - hb_strncat( DebugString, CurDCB.fInX ? "true\n" : "false\n", sizeof( DebugString ) - 1 ); - hb_strncat( DebugString, "fDtrControl : ", sizeof( DebugString ) - 1 ); - hb_strncat( DebugString, CurDCB.fDtrControl == DTR_CONTROL_DISABLE ? "DTR_CONTROL_DISABLE\n" : - CurDCB.fDtrControl == DTR_CONTROL_ENABLE ? "DTR_CONTROL_ENABLE\n" : "DTR_CONTROL_HANDSHAKE\n", sizeof( DebugString ) - 1 ); - hb_strncat( DebugString, "fOutxDsrFlow : ", sizeof( DebugString ) - 1 ); - hb_strncat( DebugString, CurDCB.fOutxDsrFlow ? "true\n" : "false\n", sizeof( DebugString ) - 1 ); + s_dwWinError = GetLastError(); + hb_retc_null(); + return; } - if( DebugLevel & WPDBGXTRAFLOW ) + + if( iDebugLevel & WPDBGTIMEOUTS ) { - hb_strncat( DebugString, "fDsrSensitivity : ", sizeof( DebugString ) - 1 ); - hb_strncat( DebugString, CurDCB.fDsrSensitivity ? "true\n" : "false\n", sizeof( DebugString ) - 1 ); - hb_strncat( DebugString, "fTXContinueOnXoff : ", sizeof( DebugString ) - 1 ); - hb_strncat( DebugString, CurDCB.fTXContinueOnXoff ? "true\n" : "false\n", sizeof( DebugString ) - 1 ); - hb_snprintf( Buffer, sizeof( Buffer ), "XonLim : %i\n" , CurDCB.XonLim ) ; hb_strncat( DebugString, Buffer, sizeof( DebugString ) - 1 ); - hb_snprintf( Buffer, sizeof( Buffer ), "XoffLim : %i\n" , CurDCB.XoffLim ) ; hb_strncat( DebugString, Buffer, sizeof( DebugString ) - 1 ); - hb_snprintf( Buffer, sizeof( Buffer ), "XonChar : 0x%i\n" , CurDCB.XonChar ) ; hb_strncat( DebugString, Buffer, sizeof( DebugString ) - 1 ); - hb_snprintf( Buffer, sizeof( Buffer ), "XoffChar : 0x%i\n", CurDCB.XoffChar ) ; hb_strncat( DebugString, Buffer, sizeof( DebugString ) - 1 ); + s_iWinFcn = FCNGETCOMMTIMEOUTS; + s_dwWinError = 0; + if( GetCommTimeouts( hCommPort, &CurCOMMTIMEOUTS ) ) + { + hb_snprintf( buffer, sizeof( buffer ), "ReadIntervalTimeout : %lu\n" , CurCOMMTIMEOUTS.ReadIntervalTimeout ) ; hb_strncat( szDebugString, buffer, sizeof( szDebugString ) - 1 ); + hb_snprintf( buffer, sizeof( buffer ), "ReadTotalTimeoutMultiplier : %ld\n" , CurCOMMTIMEOUTS.ReadTotalTimeoutMultiplier ) ; hb_strncat( szDebugString, buffer, sizeof( szDebugString ) - 1 ); + hb_snprintf( buffer, sizeof( buffer ), "ReadTotalTimeoutConstant : %ld\n" , CurCOMMTIMEOUTS.ReadTotalTimeoutConstant ) ; hb_strncat( szDebugString, buffer, sizeof( szDebugString ) - 1 ); + hb_snprintf( buffer, sizeof( buffer ), "WriteTotalTimeoutMultiplier : %ld\n", CurCOMMTIMEOUTS.WriteTotalTimeoutMultiplier ) ; hb_strncat( szDebugString, buffer, sizeof( szDebugString ) - 1 ); + hb_snprintf( buffer, sizeof( buffer ), "WriteTotalTimeoutConstant : %ld\n" , CurCOMMTIMEOUTS.WriteTotalTimeoutConstant ) ; hb_strncat( szDebugString, buffer, sizeof( szDebugString ) - 1 ); + } + else + { + s_dwWinError = GetLastError(); + hb_retc_null(); + return; + } } - if( DebugLevel & WPDBGOTHER ) + + if( iDebugLevel & WPDBGQUEUE ) { - hb_strncat(DebugString, "fBinary : ", sizeof( DebugString ) - 1 ); - hb_strncat(DebugString, CurDCB.fBinary ? "true\n" : "false\n", sizeof( DebugString ) - 1 ); - hb_strncat(DebugString, "fParity : ", sizeof( DebugString ) - 1 ); - hb_strncat(DebugString, CurDCB.fParity ? "true\n" : "false\n", sizeof( DebugString ) - 1 ); - hb_strncat(DebugString, "fErrorChar : ", sizeof( DebugString ) - 1 ); - hb_strncat(DebugString, CurDCB.fErrorChar ? "true\n" : "false\n", sizeof( DebugString ) - 1 ); - hb_strncat(DebugString, "fNull : ", sizeof( DebugString ) - 1 ); - hb_strncat(DebugString, CurDCB.fNull ? "true\n" : "false\n", sizeof( DebugString ) - 1 ); - hb_strncat(DebugString, "fAbortOnError : ", sizeof( DebugString ) - 1 ); - hb_strncat(DebugString, CurDCB.fAbortOnError ? "true\n" : "false\n", sizeof( DebugString ) - 1 ); - hb_snprintf( Buffer, sizeof( Buffer ), "ErrorChar : 0x%i\n", CurDCB.ErrorChar ) ; hb_strncat( DebugString, Buffer, sizeof( DebugString ) - 1 ); - hb_snprintf( Buffer, sizeof( Buffer ), "EofChar : 0x%i\n" , CurDCB.EofChar ) ; hb_strncat( DebugString, Buffer, sizeof( DebugString ) - 1 ); - hb_snprintf( Buffer, sizeof( Buffer ), "EvtChar : 0x%i\n" , CurDCB.EvtChar ) ; hb_strncat( DebugString, Buffer, sizeof( DebugString ) - 1 ); + s_iWinFcn = FCNGETCOMMPROPERTIES; + s_dwWinError = 0; + if( GetCommProperties( hCommPort, &CurCOMMPROP ) ) + { + hb_snprintf( buffer, sizeof( buffer ), "dwCurrentTxQueue : %lu\n", CurCOMMPROP.dwCurrentTxQueue ) ; hb_strncat( szDebugString, buffer, sizeof( szDebugString ) - 1 ); + hb_snprintf( buffer, sizeof( buffer ), "dwCurrentRxQueue : %lu\n", CurCOMMPROP.dwCurrentRxQueue ) ; hb_strncat( szDebugString, buffer, sizeof( szDebugString ) - 1 ); + } + else + { + s_dwWinError = GetLastError(); + hb_retc_null(); + return; + } } + + hb_retc( szDebugString ); } else - { - s_WinError = GetLastError(); - hb_retc_null(); - return; - } - - if( DebugLevel & WPDBGTIMEOUTS ) - { - s_WinFcn = FCNGETCOMMTIMEOUTS; - s_WinError = 0; - if( GetCommTimeouts( hCommPort, &CurCOMMTIMEOUTS ) ) - { - hb_snprintf( Buffer, sizeof( Buffer ), "ReadIntervalTimeout : %lu\n" , CurCOMMTIMEOUTS.ReadIntervalTimeout ) ; hb_strncat( DebugString, Buffer, sizeof( DebugString ) - 1 ); - hb_snprintf( Buffer, sizeof( Buffer ), "ReadTotalTimeoutMultiplier : %ld\n" , CurCOMMTIMEOUTS.ReadTotalTimeoutMultiplier ) ; hb_strncat( DebugString, Buffer, sizeof( DebugString ) - 1 ); - hb_snprintf( Buffer, sizeof( Buffer ), "ReadTotalTimeoutConstant : %ld\n" , CurCOMMTIMEOUTS.ReadTotalTimeoutConstant ) ; hb_strncat( DebugString, Buffer, sizeof( DebugString ) - 1 ); - hb_snprintf( Buffer, sizeof( Buffer ), "WriteTotalTimeoutMultiplier : %ld\n", CurCOMMTIMEOUTS.WriteTotalTimeoutMultiplier ) ; hb_strncat( DebugString, Buffer, sizeof( DebugString ) - 1 ); - hb_snprintf( Buffer, sizeof( Buffer ), "WriteTotalTimeoutConstant : %ld\n" , CurCOMMTIMEOUTS.WriteTotalTimeoutConstant ) ; hb_strncat( DebugString, Buffer, sizeof( DebugString ) - 1 ); - } - else - { - s_WinError = GetLastError(); - hb_retc_null(); - return; - } - } - - if( DebugLevel & WPDBGQUEUE ) - { - s_WinFcn = FCNGETCOMMPROPERTIES; - s_WinError = 0; - if( GetCommProperties( hCommPort, &CurCOMMPROP ) ) - { - hb_snprintf( Buffer, sizeof( Buffer ), "dwCurrentTxQueue : %lu\n", CurCOMMPROP.dwCurrentTxQueue ) ; hb_strncat( DebugString, Buffer, sizeof( DebugString ) - 1 ); - hb_snprintf( Buffer, sizeof( Buffer ), "dwCurrentRxQueue : %lu\n", CurCOMMPROP.dwCurrentRxQueue ) ; hb_strncat( DebugString, Buffer, sizeof( DebugString ) - 1 ); - } - else - { - s_WinError = GetLastError(); - hb_retc_null(); - return; - } - } - - hb_retc( DebugString ); + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } diff --git a/harbour/contrib/hbwin/win_tprt.prg b/harbour/contrib/hbwin/win_tprt.prg index a8c206374c..abb9169cb1 100644 --- a/harbour/contrib/hbwin/win_tprt.prg +++ b/harbour/contrib/hbwin/win_tprt.prg @@ -55,7 +55,7 @@ #include "hbwin.ch" -#define MAXSERIAL 16 +#define MAXSERIAL 32 // // The class is a VERY thin layer over the xHarbour functions and the xHarbour functions @@ -121,7 +121,7 @@ METHOD Init( cPortName, nBaudRate, nParity, nByteSize, nStopBits ) CLASS WinPort RETURN self -METHOD Read( /*@*/cString, nLength ) CLASS WinPort +METHOD Read( /* @ */ cString, nLength ) CLASS WinPort LOCAL nResult cString := Space( nlength ) @@ -204,6 +204,6 @@ METHOD Error() CLASS WinPort ENDIF // WinPortError clears the error - don't call it twice - cString += "error (" + LTrim( Str( nError := WinPortError() ) ) + ") : " + FormatMessage( nError ) + cString += "error (" + hb_ntos( nError := WinPortError() ) + ") : " + FormatMessage( nError ) RETURN cString