2010-11-10 22:47 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
* contrib/hbwin/tests/testcom1.prg
* contrib/hbwin/tests/testcom2.prg
* contrib/hbwin/win_tcom.prg
* contrib/hbwin/win_com.c
! Fixed samples to not query error value (since it RTEs if
the port is not open)
+ WIN_COMISVALID( <nPort> ) -> <l> added to check if port number is a valid one.
+ WIN_COMERRORCLEAR( <nPort> ) added to clear last error.
! WIN_COMERROR() changed to not clear the error on read.
+ WIN_COM():ERROR() method added to retrieve last error in numeric form.
* Samples changed to use :ERRORTEXT() to show errors.
; INCOMPATIBLE changes.
; DISCLAIMER: I'm not a user of this, so to raise your chances for
a fix, pls submit patches. I also couldn't spend huge
time to rethink the whole concept of these interfaces.
IOW: Contribute.
This commit is contained in:
@@ -16,6 +16,25 @@
|
||||
The license applies to all entries newer than 2009-04-28.
|
||||
*/
|
||||
|
||||
2010-11-10 22:47 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
|
||||
* contrib/hbwin/tests/testcom1.prg
|
||||
* contrib/hbwin/tests/testcom2.prg
|
||||
* contrib/hbwin/win_tcom.prg
|
||||
* contrib/hbwin/win_com.c
|
||||
! Fixed samples to not query error value (since it RTEs if
|
||||
the port is not open)
|
||||
+ WIN_COMISVALID( <nPort> ) -> <l> added to check if port number is a valid one.
|
||||
+ WIN_COMERRORCLEAR( <nPort> ) added to clear last error.
|
||||
! WIN_COMERROR() changed to not clear the error on read.
|
||||
+ WIN_COM():ERROR() method added to retrieve last error in numeric form.
|
||||
* Samples changed to use :ERRORTEXT() to show errors.
|
||||
; INCOMPATIBLE changes.
|
||||
|
||||
; DISCLAIMER: I'm not a user of this, so to raise your chances for
|
||||
a fix, pls submit patches. I also couldn't spend huge
|
||||
time to rethink the whole concept of these interfaces.
|
||||
IOW: Contribute.
|
||||
|
||||
2010-11-10 21:44 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
|
||||
* package/harbour.spec
|
||||
* package/harbour-win.spec.in
|
||||
|
||||
@@ -59,14 +59,14 @@ PROCEDURE Main( cPortName )
|
||||
LOCAL nResult
|
||||
|
||||
IF ! oWinPort:Open()
|
||||
? "Open() failed :", oWinPort:Error()
|
||||
? "Open() failed"
|
||||
ELSE
|
||||
? "Open() succeeded"
|
||||
?
|
||||
IF oWinPort:SetDTR( .T. )
|
||||
? "SetDTR( .T. ) succeeded"
|
||||
ELSE
|
||||
? "SetDTR( .T. ) failed :", oWinPort:Error()
|
||||
? "SetDTR( .T. ) failed :", oWinPort:ErrorText()
|
||||
ENDIF
|
||||
IF ( nResult := oWinPort:Write( cString ) ) == Len( cString )
|
||||
? "Write() succeeded"
|
||||
@@ -76,7 +76,7 @@ PROCEDURE Main( cPortName )
|
||||
? "Scan something... we'll not read it but purge it, press enter"
|
||||
Inkey( 0 )
|
||||
? "Read() ", oWinPort:Read( @cString, 32 ), Len( cString ), cString
|
||||
? oWinPort:Error()
|
||||
? oWinPort:ErrorText()
|
||||
? "Close", oWinPort:Close()
|
||||
ENDIF
|
||||
|
||||
|
||||
@@ -71,14 +71,14 @@ PROCEDURE Main( cPortName )
|
||||
|
||||
oWinPort := win_Com():Init( cPortName, WIN_CBR_9600, WIN_ODDPARITY, 7, WIN_ONESTOPBIT )
|
||||
IF ! oWinPort:Open()
|
||||
? "Open() failed :", oWinPort:Error()
|
||||
? "Open() failed"
|
||||
ELSE
|
||||
? "Open() succeeded"
|
||||
?
|
||||
IF oWinPort:Status( @lCTS, @lDSR, @lRing, @lDCD )
|
||||
? "Status() succeeded : CTS ", lCTS, ", DSR ", lDSR, ", Ring ", lRing, ", DCD ", lDCD
|
||||
ELSE
|
||||
? "Status() failed :", oWinPort:Error()
|
||||
? "Status() failed :", oWinPort:ErrorText()
|
||||
ENDIF
|
||||
?
|
||||
? "Testing DTR, configure a scanner to require DTR"
|
||||
@@ -89,7 +89,7 @@ PROCEDURE Main( cPortName )
|
||||
IF oWinPort:SetDTR( .T. )
|
||||
? "SetDTR( .T. ) succeeded"
|
||||
ELSE
|
||||
? "SetDTR( .T. ) failed :", oWinPort:Error()
|
||||
? "SetDTR( .T. ) failed :", oWinPort:ErrorText()
|
||||
ENDIF
|
||||
? "Scan something... and press enter (read should work)"
|
||||
Inkey( 0 )
|
||||
@@ -98,7 +98,7 @@ PROCEDURE Main( cPortName )
|
||||
? "QueueStatus() : CTSHold", lCtsHold, ", DSRHold", lDsrHold, ", DCDHold", lDCDHold, ", XoffHold", lXoffHold, ;
|
||||
", Xoff Sent ", lXoffSent, ", InQueue ", nInQueue, ", nOutQueue ", nOutQueue
|
||||
ELSE
|
||||
? "QueueStatus() failed :", oWinPort:Error()
|
||||
? "QueueStatus() failed :", oWinPort:ErrorText()
|
||||
ENDIF
|
||||
?
|
||||
? "Read() ", oWinPort:Read( @cString, 32 ), Len( cString ), cString
|
||||
@@ -107,31 +107,31 @@ PROCEDURE Main( cPortName )
|
||||
? "QueueStatus() : CTSHold", lCtsHold, ", DSRHold", lDsrHold, ", DCDHold", lDCDHold, ", XoffHold", lXoffHold, ;
|
||||
", Xoff Sent ", lXoffSent, ", InQueue ", nInQueue, ", nOutQueue ", nOutQueue
|
||||
ELSE
|
||||
? "QueueStatus() failed :", oWinPort:Error()
|
||||
? "QueueStatus() failed :", oWinPort:ErrorText()
|
||||
ENDIF
|
||||
?
|
||||
IF oWinPort:RTSFlow( WIN_RTS_CONTROL_HANDSHAKE )
|
||||
? "RTSFlow( WIN_RTS_CONTROL_HANDSHAKE ) succeeded"
|
||||
ELSE
|
||||
? "RTSFlow( WIN_RTS_CONTROL_HANDSHAKE ) failed :", oWinPort:Error()
|
||||
? "RTSFlow( WIN_RTS_CONTROL_HANDSHAKE ) failed :", oWinPort:ErrorText()
|
||||
ENDIF
|
||||
? oWinPort:DebugDCB( HB_WIN_COM_DBGFLOW )
|
||||
IF oWinPort:SetRTS( .F. )
|
||||
? "SetRTS( .F. ) succeeded (it shouldn't according to docs!)"
|
||||
ELSE
|
||||
? "SetRTS( .F. ) failed (it should) :", oWinPort:Error()
|
||||
? "SetRTS( .F. ) failed (it should) :", oWinPort:ErrorText()
|
||||
ENDIF
|
||||
?
|
||||
IF oWinPort:RTSFlow( WIN_RTS_CONTROL_DISABLE )
|
||||
? "RTSFlow( WIN_RTS_CONTROL_DISABLE ) succeeded"
|
||||
ELSE
|
||||
? "RTSFlow( WIN_RTS_CONTROL_DISABLE ) failed :", oWinPort:Error()
|
||||
? "RTSFlow( WIN_RTS_CONTROL_DISABLE ) failed :", oWinPort:ErrorText()
|
||||
ENDIF
|
||||
? oWinPort:DebugDCB( HB_WIN_COM_DBGFLOW )
|
||||
IF oWinPort:SetRTS( .F. )
|
||||
? "SetRTS( .F. ) succeeded (it should)"
|
||||
ELSE
|
||||
? "SetRTS( .F. ) failed :", oWinPort:Error()
|
||||
? "SetRTS( .F. ) failed :", oWinPort:ErrorText()
|
||||
ENDIF
|
||||
?
|
||||
? "Scan something... we'll not read it but purge it, press enter"
|
||||
@@ -140,19 +140,19 @@ PROCEDURE Main( cPortName )
|
||||
? "QueueStatus() : CTSHold", lCtsHold, ", DSRHold", lDsrHold, ", DCDHold", lDCDHold, ", XoffHold", lXoffHold, ;
|
||||
", Xoff Sent ", lXoffSent, ", InQueue ", nInQueue, ", nOutQueue ", nOutQueue
|
||||
ELSE
|
||||
? "QueueStatus() failed :", oWinPort:Error()
|
||||
? "QueueStatus() failed :", oWinPort:ErrorText()
|
||||
ENDIF
|
||||
IF oWinPort:Purge( .T., .T. )
|
||||
? "Purge() succeeded"
|
||||
ELSE
|
||||
? "Purge() failed :", oWinPort:Error()
|
||||
? "Purge() failed :", oWinPort:ErrorText()
|
||||
ENDIF
|
||||
? "InQueue should be zero"
|
||||
IF oWinPort:QueueStatus( @lCTSHold, @lDSRHold, @lDCDHold, @lXoffHold, @lXoffSent, @nInQueue, @nOutQueue )
|
||||
? "QueueStatus() : CTSHold", lCtsHold, ", DSRHold", lDsrHold, ", DCDHold", lDCDHold, ", XoffHold", lXoffHold, ;
|
||||
", Xoff Sent ", lXoffSent, ", InQueue ", nInQueue, ", nOutQueue ", nOutQueue
|
||||
ELSE
|
||||
? "QueueStatus() failed :", oWinPort:Error()
|
||||
? "QueueStatus() failed :", oWinPort:ErrorText()
|
||||
ENDIF
|
||||
?
|
||||
? "Read ", oWinPort:Read( @cString, 32 ), Len( cString ), cString
|
||||
@@ -166,7 +166,7 @@ PROCEDURE Main( cPortName )
|
||||
|
||||
oWinPort := Win_Com():Init( cPortName, WIN_CBR_9600, WIN_NOPARITY, 99, WIN_ONESTOPBIT )
|
||||
IF !oWinPort:Open
|
||||
? "Open() failed :", oWinPort:Error()
|
||||
? "Open() failed :", oWinPort:ErrorText()
|
||||
ELSE
|
||||
? "Open succeeded"
|
||||
? "Close", oWinPort:Close()
|
||||
@@ -178,7 +178,7 @@ PROCEDURE Main( cPortName )
|
||||
|
||||
oWinPort := Win_Com():Init( cPortName, WIN_CBR_9600, WIN_NOPARITY, 8, WIN_ONESTOPBIT )
|
||||
IF ! oWinPort:Open
|
||||
? "Open() failed :", oWinPort:Error()
|
||||
? "Open() failed :", oWinPort:ErrorText()
|
||||
ELSE
|
||||
? "Open succeeded"
|
||||
?
|
||||
@@ -187,7 +187,7 @@ PROCEDURE Main( cPortName )
|
||||
IF oWinPort:Status( @lCTS, @lDSR, @lRing, @lDCD )
|
||||
? "Status() succeeded : CTS ", lCTS, ", DSR ", lDSR, ", Ring ", lRing, ", DCD ", lDCD
|
||||
ELSE
|
||||
? "Status() failed :", oWinPort:Error()
|
||||
? "Status() failed :", oWinPort:ErrorText()
|
||||
ENDIF
|
||||
?
|
||||
|
||||
@@ -202,7 +202,7 @@ PROCEDURE Main( cPortName )
|
||||
? "QueueStatus() : CTSHold", lCtsHold, ", DSRHold", lDsrHold, ", DCDHold", lDCDHold, ", XoffHold", lXoffHold, ;
|
||||
", Xoff Sent ", lXoffSent, ", InQueue ", nInQueue, ", nOutQueue ", nOutQueue
|
||||
ELSE
|
||||
? "QueueStatus() failed :", oWinPort:Error()
|
||||
? "QueueStatus() failed :", oWinPort:ErrorText()
|
||||
ENDIF
|
||||
|
||||
?
|
||||
@@ -210,17 +210,17 @@ PROCEDURE Main( cPortName )
|
||||
IF oWinPort:RTSFlow( WIN_DTR_CONTROL_HANDSHAKE )
|
||||
? "RTSFlow( WIN_RTS_CONTROL_HANDSHAKE ) succeeded"
|
||||
ELSE
|
||||
? "RTSFlow( WIN_RTS_CONTROL_HANDSHAKE ) failed :", oWinPort:Error()
|
||||
? "RTSFlow( WIN_RTS_CONTROL_HANDSHAKE ) failed :", oWinPort:ErrorText()
|
||||
ENDIF
|
||||
IF oWinPort:DTRFlow( WIN_DTR_CONTROL_HANDSHAKE )
|
||||
? "DTRFlow( WIN_DTR_CONTROL_HANDSHAKE ) succeeded"
|
||||
ELSE
|
||||
? "DTRFlow( WIN_DTR_CONTROL_HANDSHAKE ) failed :", oWinPort:Error()
|
||||
? "DTRFlow( WIN_DTR_CONTROL_HANDSHAKE ) failed :", oWinPort:ErrorText()
|
||||
ENDIF
|
||||
IF oWinPort:XonXoffFlow( .T. )
|
||||
? "XonXoffFlow( .T. ) ", oWinPort:XonXoffFlow( .T. )
|
||||
ELSE
|
||||
? "XonXoffFlow( .T. ) failed :", oWinPort:Error()
|
||||
? "XonXoffFlow( .T. ) failed :", oWinPort:ErrorText()
|
||||
ENDIF
|
||||
?
|
||||
? oWinPort:DebugDCB( HB_WIN_COM_DBGFLOW )
|
||||
@@ -230,7 +230,7 @@ PROCEDURE Main( cPortName )
|
||||
? "QueueStatus() : CTSHold", lCtsHold, ", DSRHold", lDsrHold, ", DCDHold", lDCDHold, ", XoffHold", lXoffHold, ;
|
||||
", Xoff Sent ", lXoffSent, ", InQueue ", nInQueue, ", nOutQueue ", nOutQueue
|
||||
ELSE
|
||||
? "QueueStatus() failed :", oWinPort:Error()
|
||||
? "QueueStatus() failed :", oWinPort:ErrorText()
|
||||
ENDIF
|
||||
?
|
||||
? Seconds()
|
||||
|
||||
@@ -714,19 +714,36 @@ HB_FUNC( WIN_COMSETQUEUESIZE )
|
||||
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
|
||||
}
|
||||
|
||||
HB_FUNC( WIN_COMERROR )
|
||||
HB_FUNC( WIN_COMISVALID )
|
||||
{
|
||||
int iPort = hb_parni( 1 );
|
||||
|
||||
hb_retl( iPort >= 0 && iPort < ( int ) HB_SIZEOFARRAY( s_PortData ) );
|
||||
}
|
||||
|
||||
HB_FUNC( WIN_COMERRORCLEAR )
|
||||
{
|
||||
int iPort = hb_parni( 1 );
|
||||
|
||||
if( iPort >= 0 && iPort < ( int ) HB_SIZEOFARRAY( s_PortData ) )
|
||||
{
|
||||
hb_retnl( s_PortData[ iPort ].dwError );
|
||||
s_PortData[ iPort ].dwError = 0; /* NOTE: reset */
|
||||
s_PortData[ iPort ].dwError = 0;
|
||||
s_PortData[ iPort ].iFunction = 0;
|
||||
}
|
||||
else
|
||||
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
|
||||
}
|
||||
|
||||
HB_FUNC( WIN_COMERROR )
|
||||
{
|
||||
int iPort = hb_parni( 1 );
|
||||
|
||||
if( iPort >= 0 && iPort < ( int ) HB_SIZEOFARRAY( s_PortData ) )
|
||||
hb_retnl( s_PortData[ iPort ].dwError );
|
||||
else
|
||||
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
|
||||
}
|
||||
|
||||
HB_FUNC( WIN_COMFUNCLAST )
|
||||
{
|
||||
int iPort = hb_parni( 1 );
|
||||
|
||||
@@ -99,6 +99,7 @@ CREATE CLASS win_Com
|
||||
METHOD Close( nDrain )
|
||||
METHOD DebugDCB( nDebug )
|
||||
METHOD ErrorText()
|
||||
METHOD Error()
|
||||
|
||||
ENDCLASS
|
||||
|
||||
@@ -231,3 +232,6 @@ METHOD ErrorText() CLASS win_Com
|
||||
wapi_FormatMessage( NIL, NIL, nError := win_ComError( ::nPort ), NIL, @cMsg )
|
||||
|
||||
RETURN cString + "error (" + hb_ntos( nError ) + ") : " + cMsg
|
||||
|
||||
METHOD Error() CLASS win_Com
|
||||
RETURN win_ComError( ::nPort )
|
||||
|
||||
Reference in New Issue
Block a user