FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Leer puerto COMM
Posts: 132
Joined: Sun Oct 23, 2005 04:09 PM
Leer puerto COMM
Posted: Wed Apr 05, 2006 10:27 PM

Que tal a Todos:

En clipper tengo funcionando lo siguiente:

.....
DO WHILE .T.
nTrab := nChars := nInicio := 0
cStatus:=""
/ Limpiar el buffer para una nueva lectura/
COM_FLUSH(nPuerto)

            DO WHILE (nChars := COM_COUNT(nPuerto)) <= 6 // Asegura
               @ 18,17 SAY "Leyendo el peso..."          // al menos haya 7
                                                                      // car cteres en
               IF INKEY() = K_ESC                        // el Buffers.
                  RESTSCREEN (16,15,21,36,cVentana)
                  SETCOLOR(cColorAnt)
                  RETURN(-1)
               ENDIF
            ENDDO                
            @ 18,17 SAY SPACE(18)

            /* Toma la cadena de car cteres del buffer */
            cDato := COM_READ(nPuerto)

            nInicio := at(chr(2) , cDato)  // B£sca el carater STX (inicio)

            nTrab := val( substr ( cDato, nInicio+2, 7 ) )

            cStatus := substr( cDato, nInicio+11, 1 )

            @ 19,25 SAY  nTrab PICT "9999999"

            GrabaEntrada(nTrab)
            DO CASE

CASE cStatus == " "
EXIT / El TRAB es correcto /
ENDCASE

            EXIT

ENDDO

Y NECESITO PASARLO A FIVEWIN, PARA ESO PUSE LO SIGUIENTE:

function entrada()
local cDcb, nBytes,nError,cDataRead
local nComm := OpenComm( "COM2", 1024, 128 )

if ! BuildCommDcb( "COM2:9600,n,8,1", @cDcb )
nError = GetCommError( nComm )
MsgInfo( "BuildCommDcb Error: " + Str( nError ) )
endif

if ! SetCommState( cDcb )
nError = GetCommError( nComm )
MsgInfo( "SetCommState Error: " + Str( nError ) )
endif

***Read Comm Port here
DO WHILE .t.
nBytes := ReadComm( nComm , @cDataRead)
msginfo(nBytes) // <----- AQUI SOLO MUESTRA -1
if nBytes > 6
msginfo(cDataRead)
exit
endif
enddo
msginfo(cDataRead)

***Close Comm Port
if FlushComm( nComm, 0 ) != 0
nError = GetCommError( nComm )
MsgInfo( "FlushComm Error: " + Str( nError ) )
endif

if ! CloseComm( nComm )
nError = GetCommError( nComm )
MsgInfo( "CloseComm Error: " + Str( nError ) )
endif

Podrian ayudarme en lo que me falta, por favor, de antemano muchas gracias

Atte Miguel Salas

Continue the discussion