Page 1 of 1

LECTURA EM PUERTO SERIAL EN FIVE 2.7 FOR XHARBOUR

PostPosted: Thu Dec 29, 2005 2:27 pm
by karinha
AMIGOS, COMO HACER PARA LECTURAS EN PUERTO SERIAL?

COM1, COM2, ETC.

EJEMPLO: TESTEI PHONE.PRG, PERO NO FUNCIONA.

ERRO: CANNOT CREATE DIALOG BOX Y EN 16 BITS MI FUNCIONA PERFECTO.

PostPosted: Thu Dec 29, 2005 3:01 pm
by karinha
TESTCOM3.PRG, TAMBIÉN, NO MI RETORNA NADA.

PostPosted: Thu Dec 29, 2005 5:12 pm
by karinha
Antonio, Podrias ayudarme con el uso de HBCOMM.LIB, no compreendi nada.

Ke devo hacer para compilar e llamar el puerto u sus datos?

Tienes ejemplo funcionando, o donde encuentro?

PostPosted: Thu Dec 29, 2005 6:01 pm
by AngelSalom
Ahi va una lista de las funciones (no es de mi cosecha) pero a mi me funciona perfectamente :

/*

The Harbour interface routines for the HBCOMM library. It is not clear who
produced the harbour routines to interface with Harold Howe's TCommPort
encapsulation. Regardless, the Harbour interface has been modified to
allow for more than one port to be open (MAXOPENPORTS) compiled at 20 and
to allow for the sending and receiving of data containing NULL characters
(Chr(0)).

As a C/C++ coder, I make a fair plumber. Anyone who wishes to clean-up my
code is welcome to do so.

Ned Robertson
XpertCTI, LLC
Richmond, VA USA
July, 2003

*/

#include "hbapi.h"
#include "hbcomm.h"

static int aHandles[ MAXOPENPORTS ] ; // assumes initialized to zeros
static int nHBase = 256 ;

// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ //

HB_FUNC(INIT_PORT) /* Nx_port(string),Nbaud(numerico),Ndata(numerico),Nparity(numerico),Nstop(numerico),nBufferSize(numerico)
retorna .t. se abriu a porta */

/* cPort, nBaudrate, nDatabits, nParity, nStopbits, nBuffersize

Main initiator/port opener.

cPort may take either the form 'COMn' or the more general '\\.\COMn'
The more general form is required for port numbers > 9.

nParity codes: 0,1,2,3 -> none, odd, mark, even

nStopBits codes: 0,1,2 -> 1, 1.5, 2

Returns a "handle" >= 256. A return of -1 means open failed.

The handle must be used on all references to the port and is equivalent to
nComm used in 16 bit Clipper/Fivewin routines. All routines take the
handle reference as their first argument.

*/

{

int i = 0, n = -1, nHandle ;

while ( n < 0 && i < MAXOPENPORTS ) {

if ( aHandles[ i++ ] == 0 )

n = i - 1 ;

}

if ( n != -1 ) {

nHandle = nHBase++ ;

aHandles[ n ] = nHandle ;

if ( hb_init_port( n, hb_parc( 1 ) , hb_parnl( 2 ) ,
hb_parnl( 3 ) , hb_parnl( 4 ) , hb_parnl( 5 ) ,
hb_parnl( 6 ) ) )

hb_retnl( nHandle ) ;

else

hb_retnl( 0 ) ;

}

}

// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ //

HB_FUNC( OUTBUFCLR ) // purge output buffer
{
int nIdx ;

nIdx = FindIndex( hb_parnl( 1 ) ) ;

if ( nIdx != -1 ) {

hb_outbufclr( nIdx ) ;

hb_retl( TRUE ) ;

}

else

hb_retl( FALSE ) ;


}

// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ //

HB_FUNC( ISWORKING ) // See if port is opened correctly
{
int nIdx ;

nIdx = FindIndex( hb_parnl( 1 ) ) ;

if ( nIdx != -1 )

hb_retl( hb_isworking( nIdx ) );

else

hb_retl( FALSE ) ;

}

// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ //

HB_FUNC( INCHR ) // fetch hb_parnl( 2 ) chars into hb_parc( 3 )
{

int nIdx ;

nIdx = FindIndex( hb_parnl( 1 ) ) ;

if ( nIdx != -1 )

// hb_retc( hb_inchr( nIdx, hb_parnl( 1 ) ) );
hb_retnl( hb_inchr( nIdx, hb_parnl( 2 ), hb_parc( 3 ) ) ); // EDR*7/03

else

hb_retnl( 0 ) ;

}

// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ //

HB_FUNC( OUTCHR ) // Send out characters. Returns .t. if successful.
{

int nIdx ;

nIdx = FindIndex( hb_parnl( 1 ) ) ;

if ( nIdx != -1 )

// hb_retl( hb_outchr( hb_parc( 1 ) ) );
hb_retl( hb_outchr( nIdx, hb_parc( 2 ), hb_parclen( 2 ) ) ); // EDR*7/03

else

hb_retl( FALSE ) ;

}

// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ //

HB_FUNC( INBUFSIZE ) // Find out how many chars are in input buffer
{

int nIdx ;

nIdx = FindIndex( hb_parnl( 1 ) ) ;

if ( nIdx != -1 )

hb_retnl( hb_inbufsize( nIdx ) );

else

hb_retnl( 0 ) ;

}

// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ //

HB_FUNC( OUTBUFSIZE ) // Find out how many characters are in out buf ?
{

int nIdx ;

nIdx = FindIndex( hb_parnl( 1 ) ) ;

if ( nIdx != -1 )

hb_retnl( hb_outbufsize( nIdx ) );

else

hb_retnl( 0 ) ;

}

// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ //

HB_FUNC( UNINT_PORT ) // Close port and clear handle
{
int nIdx ;

nIdx = FindIndex( hb_parnl( 1 ) ) ;

if ( nIdx != -1 ) {

hb_unint_port( nIdx );

aHandles[ nIdx ] = 0 ;

hb_retl( TRUE ) ;

}

else

hb_retl( FALSE ) ;
}

// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ //

int FindIndex ( int nH ) // Convert "handle" to tcomm array index
{
int i = 0, n = -1 ;

while ( n < 0 && i < MAXOPENPORTS ) {

if ( aHandles[ i++ ] == nH )

n = i - 1 ;

}

// printf( "index= %8d\n", n );

return n ;
}

// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ //

HB_FUNC( CHKIDX ) // For debugging - not normally used

{
int nIdx ;

nIdx = FindIndex( hb_parnl( 1 ) ) ;

hb_retnl( nIdx );

}

#pragma ENDDUMP

PostPosted: Thu Dec 29, 2005 6:04 pm
by AngelSalom
Aqui va un ejemplo :

nIdCom:=IniciarComm ("COM1",9600,"n",8,1,1024)
// Esto escribe en el puerto (por ejemplo en un visor)
nBytes:=OutChr(nIdCom,"Hola mariola!")
TerminarComm (nIdCom)


Function IniciarComm(cPuerto,nVelocidad,cParidad,nDatos,nParada,nBuffer)
Local nComm

IF ( nComm := Init_Port( cPuerto, nVelocidad, nDatos, cParidad ,nParada, nBuffer) ) == -1
Msginfo ("Error al abrir el puerto")
Else
OutBufClr(nComm)
ENDIF

RETURN nComm

FUNCTION TerminarComm(nComm)
RETURN UNINT_PORT(nComm)

PostPosted: Thu Dec 29, 2005 6:39 pm
by karinha
AngelSalom wrote:Aqui va un ejemplo :

nIdCom:=IniciarComm ("COM1",9600,"n",8,1,1024)
// Esto escribe en el puerto (por ejemplo en un visor)
nBytes:=OutChr(nIdCom,"Hola mariola!")
TerminarComm (nIdCom)


Function IniciarComm(cPuerto,nVelocidad,cParidad,nDatos,nParada,nBuffer)
Local nComm

IF ( nComm := Init_Port( cPuerto, nVelocidad, nDatos, cParidad ,nParada, nBuffer) ) == -1
Msginfo ("Error al abrir el puerto")
Else
OutBufClr(nComm)
ENDIF

RETURN nComm

FUNCTION TerminarComm(nComm)
RETURN UNINT_PORT(nComm)


Buenas Angel... Gracias.

Dudas:

Mi basta incorporar la HBCOMM.LIB, y hacer estas llamadas, ke mi funcionara perfecto??

Si tienes algo ke puedas enviarme, por favor mi correo és este:

kmt_karinha@pop.com.br

desde ya muchas gracias, y disculpe el incomodo, és ke estoy iniciando.

Disculpe mi portunhol.

PostPosted: Fri Dec 30, 2005 2:22 pm
by karinha
//-> Amigos FiveWinners, Necesito Ayuda/Help:

#Include "Fivewin.ch"

STATIC NIDCOM, NBYTES, NBUFFER

Function Main()

Local oDlg
Local oGet
Local cCodigo

nIdCom:=IniciarComm ("COM1",9600,"n",8,1,1024)

// nBytes:=OutChr(nIdCom,"Hola mariola!")

DEFINE DIALOG oDlg TITLE "Usando a Porta Serial no xHarbour"

@ 2, 6 GET oGet VAR cCodigo OF oDlg ;
SIZE 40, 12 ;
VALID !Empty( cCodigo )

@ 3, 7 BUTTON "&Buscar" OF oDlg ;
SIZE 30, 12 ;
ACTION( Pega_Codigo( cCodigo ) )

@ 3, 16 BUTTON "&Saida" OF oDlg ;
SIZE 30, 12 ;
ACTION oDlg:End() CANCEL

ACTIVATE DIALOG oDlg CENTERED

TerminarComm (nIdCom)

Return Nil

//-> Pegar el Codigo del Producto Para Grabar en el Banco de las Ventas
Function Pega_Codigo( cCodigo )

USE ESTOQUE INDEX ESTOQUE ALIAS ESTOQUE

SEEK( AllTrim( nBuffer ) ) //-> Kero Pegar o contenido del Buffer.

? cCodigo
? nBuffer

//-> Grabar el Resultado.

Return Nil

Function IniciarComm(cPuerto,nVelocidad,cParidad,nDatos,nParada,nBuffer)

Local nComm

IF ( nComm := Init_Port( cPuerto, nVelocidad, nDatos, cParidad ,nParada, nBuffer) ) == -1
Msginfo ("Erro ao abrir a porta serial")
Else
OutBufClr(nComm)
ENDIF

RETURN nComm

FUNCTION TerminarComm(nComm)
RETURN UNINT_PORT(nComm)

/*
Mi configuracion:

FIVEWIN 2.7 November 2005
XHABROUR 0.99.50
BORLAND BCC++ 5.5.1
*/

//-> Al Compilar, mi retorna:

//-> UNRESOLVED EXTERNAL '_HB_STACK_' REFERENCED FROM C:\XHARBOUR\LIB\HBCOMM.LIB

KE HACER??

PostPosted: Fri Dec 30, 2005 2:37 pm
by AngelSalom
Bufff. No se si habrá alguna diferencia con xharbour.
Yo uso harbour y la libreria me va perfecta.
Intenta conseguir el hbcomm adecuado.

PostPosted: Fri Dec 30, 2005 3:01 pm
by karinha
AngelSalom wrote:Bufff. No se si habrá alguna diferencia con xharbour.
Yo uso harbour y la libreria me va perfecta.
Intenta conseguir el hbcomm adecuado.



DONDE ANGEL?

Mi version és de: 27/05/2002

El código está correcto Angel?

Usted podrias enviarme a HBCOMM.LIB mas actual??

Como dar lectura na porta? pegar los datos? o contenido en el Buffer.

PostPosted: Wed Jan 04, 2006 4:49 pm
by AngelSalom
Te lo envio al correo privado.

PostPosted: Wed Jan 04, 2006 6:13 pm
by karinha
Muchas Gracias Angel.

Angel, Ayuda-me. Como usted captura el Contenido del Buffer?

És con este Comando: INBUFSIZE ??

PostPosted: Wed Jan 04, 2006 6:29 pm
by AngelSalom
Ahi va :

FUNCTION Lectura()
LOCAL nBytes := 200
LOCAL cLeido := SPACE(200)

nBytes := InbufSize(nComm)
nRecibido += nBytes

IF nBytes > 0
cLeido = SPACE(nBytes)
InChr( nComm, nBytes, @cLeido ) // --> Esto es lo que lee el puerto
ENDIF
RETURN nil

Un saludo.

PostPosted: Thu Jan 05, 2006 12:49 pm
by karinha
AngelSalom wrote:Ahi va :

FUNCTION Lectura()
LOCAL nBytes := 200
LOCAL cLeido := SPACE(200)

nBytes := InbufSize(nComm)
nRecibido += nBytes

IF nBytes > 0
cLeido = SPACE(nBytes)
InChr( nComm, nBytes, @cLeido ) // --> Esto es lo que lee el puerto
ENDIF
RETURN nil

Un saludo.


Gracias Angel. usted és increible. Saludos.