home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 16 / CD_ASCQ_16_0994.iso / news / 4611 / fw16d.ins / SOURCE / CLASSES / TCOMM.PRG < prev    next >
Text File  |  1994-05-28  |  3KB  |  79 lines

  1. // Developed by a FiveWin user
  2.  
  3. #include "FiveWin.ch"
  4.  
  5. //----------------------------------------------------------------------------//
  6.  
  7. CLASS TComm
  8.  
  9.     DATA nDevice, nInQueue, nOutQueue, nId, nStop, nBaud, nData, nErr
  10.     DATA cParity, cStyle, cChar
  11.     DATA aStatus
  12.  
  13.     METHOD Break() BLOCK { |Self| IIF( SetCommBreak( ::nId ) < 0, ;
  14.                     MsgInfo( "Error al bloquear el puerto de comunicaciones" ), ) }
  15.  
  16.   METHOD Close() BLOCK { |Self| IIF( CloseComm( ::nId ) < 0, ;
  17.                     MsgInfo( "Error intentando cerrar el puerto de comunicaciones" ), ) }
  18.  
  19.   METHOD Error()
  20.  
  21.   METHOD Escape( nCode ) BLOCK { |Self,nCode| IIF( EscapeCommFunction( ::nId, nCode ) < 0, ;
  22.                     MsgInfo( OemToAnsi( "Error enviando código de escape" ) ), ) }
  23.  
  24.   METHOD Flush( nQueue ) BLOCK { |Self,nQueue| IIF( FlushComm( ::nId, nQueue ) != 0, ;
  25.                     MsgInfo( "Error al vaciar el buffer de las comunicaciones" ), ) }
  26.  
  27.   METHOD New( nDevice, nInQueue, nOutQueue, cStyle ) CONSTRUCTOR
  28.  
  29.   METHOD SetUp()
  30.  
  31.   METHOD UnBreak() BLOCK { |Self| IIF( ClearCommBreak( ::nId ) < 0, ;
  32.                     MsgInfo( "Error desbloqueando el puerto de comunicaciones" ), ) }
  33.  
  34.   METHOD Write( cString )
  35.  
  36. ENDCLASS
  37.  
  38. //----------------------------------------------------------------------------//
  39.  
  40. METHOD New( nDevice, nInQueue, nOutQueue, cStyle, nBaud, cParity, nStop, nData ) CLASS TComm
  41.     DEFAULT cStyle := "COM", nInQueue := 1024, nOutQueue := 128, nDevice := 1, ;
  42.             nBaud := 9600, cParity := "n", nStop := 1, nData := 8
  43.  
  44.     ::nDevice   := nDevice
  45.     ::nInQueue  := nInQueue
  46.     ::nOutQueue := nOutQueue
  47.     ::cStyle    := cStyle
  48.     ::nBaud     := nBaud
  49.     ::cParity   := cParity
  50.     ::nStop     := nStop
  51.     ::nData        := nData
  52.  
  53.     ::nId := OpenComm( cStyle + ALLTRIM( STR( nDevice ) ), nInQueue, nOutQueue )
  54.  
  55.     IIF( ::nId < 0, MsgInfo( "Error al inizializar las comunicaciones" + CHR(13) + ;
  56.                             OemToAnsi( "Número del error --> " ) + ALLTRIM( STR( ::nId ) ) ), )
  57. RETURN 
  58.  
  59. METHOD Error() CLASS TComm
  60.     ::aStatus := GetError( ::aStatus )
  61. RETURN
  62.  
  63. METHOD SetUp() CLASS TComm
  64.     LOCAL cString
  65.     cString := ::cStyle + ALLTRIM( STR( ::nDevice ) ) + ":" +  ALLTRIM( STR( ::nBaud ) ) + "," + ;
  66.             ::cParity + "," + ALLTRIM( STR( ::nData ) ) + "," + ALLTRIM( STR( ::nStop ) )
  67.     IF !ConfComm( cString )
  68.         MsgInfo( "Error al configurar el puerto de comunicaciones" )
  69.     ENDIF
  70. RETURN
  71.  
  72. METHOD Write( cString ) CLASS TComm
  73.     ::nErr := WriteComm( ::nId, cString )
  74.     IF ::nErr < 0
  75.         MsgInfo( "Error al escribir datos" + CHR(13) +;
  76.                 "Datos escritos --> " + ALLTRIM( STR( ABS( ::nErr ) ) ) )
  77.     ENDIF
  78. RETURN
  79.