control serial port (ex: nt250.lib norton)

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
perenne
Posts: 3
Joined: Fri Aug 01, 2008 12:02 pm
Location: Brasil

control serial port (ex: nt250.lib norton)

Post by perenne »

Want to put this in libhbcomm.a in HMG ?
Where to find libhbcomm.a for download ?
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: control serial port (ex: nt250.lib norton)

Post by Roberto Lopez »

perenne wrote:Want to put this in libhbcomm.a in HMG ?
Where to find libhbcomm.a for download ?
I've googled that and I've found this:

http://www.fivewin.com.br/forum/post.as ... %E9+%3F&M=

You can include the code (from BEGINDUMP to ENDDUMP) in any .prg file and compile as usual .

I've not tested.

Regards,

Roberto.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: control serial port (ex: nt250.lib norton)

Post by Roberto Lopez »

Roberto Lopez wrote:
perenne wrote:Want to put this in libhbcomm.a in HMG ?
Where to find libhbcomm.a for download ?
I've googled that and I've found this:

http://www.fivewin.com.br/forum/post.as ... %E9+%3F&M=

You can include the code (from BEGINDUMP to ENDDUMP) in any .prg file and compile as usual .

I've not tested.

Regards,

Roberto.
This is the code:

Code: Select all


#pragma BEGINDUMP

/*

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 -> Limpeza da Saida do 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

Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
perenne
Posts: 3
Joined: Fri Aug 01, 2008 12:02 pm
Location: Brasil

Re: control serial port (ex: nt250.lib norton)

Post by perenne »

Thank you for responding,

I put the code from BEGINDUMP to ENDDUMP and gave the following error:

C:\visual\HBCOMM\Demo\MAIN.o:MAIN.c:(.text+0x1e9): undefined reference to `hb_init_port'
C:\visual\HBCOMM\Demo\MAIN.o:MAIN.c:(.text+0x23c): undefined reference to `hb_outbufclr'
C:\visual\HBCOMM\Demo\MAIN.o:MAIN.c:(.text+0x286): undefined reference to `hb_isworking'
C:\visual\HBCOMM\Demo\MAIN.o:MAIN.c:(.text+0x2ef): undefined reference to `hb_inchr'
C:\visual\HBCOMM\Demo\MAIN.o:MAIN.c:(.text+0x35c): undefined reference to `hb_outchr'
C:\visual\HBCOMM\Demo\MAIN.o:MAIN.c:(.text+0x3a6): undefined reference to `hb_inbufsize'
C:\visual\HBCOMM\Demo\MAIN.o:MAIN.c:(.text+0x3ec): undefined reference to `hb_outbufsize'
C:\visual\HBCOMM\Demo\MAIN.o:MAIN.c:(.text+0x432): undefined reference to `hb_unint_port'
ng C source output to 'C:\visual\HBCOMM\Demo\MAIN.c'... Done.
mingw32-make.exe: *** [C:\visual\HBCOMM\Demo\MAIN.exe] Error 1
Finished With Errors.

hbcomm.h downloaded from "www.carozodequilmes.com.ar/Projects/QAC/"

thanks!
Post Reply