| tpcommon.c | |||
| Type | Function | Source | Line |
|---|---|---|---|
| HB_FUNC | P_CRC16(void)
HB_FUNC( P_CRC16 )
{
char *ptr = hb_parc( 1 );
int count = hb_parclen( 1 );
register unsigned short crc = 0;
while ( count-- > 0 )
crc = updcrc( *ptr++, crc );
/* swap Hi and Lo byte */
hb_retnl( ( crc >> 8 ) | ( ( crc << 8 ) & 0xFF00 ) );
}
/* Taken from: contrib/unicode/hbcrc32.c
* Harbour Unicode Support
*
* Source codes for functions:
* HB_CRC32()
* HB_NCRC32()
*
* Copyright 2004 Dmitry V. Korzhov | tpcommon.c | 100 |
| HB_FUNC | P_CRC32(void)
HB_FUNC( P_CRC32 )
{
char * ptr = hb_parc( 1 );
int count = hb_parclen( 1 );
register ULONG crc = CRC32INIT;
while( count-- > 0 )
crc = updcrc32( *ptr++, crc );
hb_retnl( crc ^ CRC32INIT );
}
| tpcommon.c | 165 |
| tplinux.c | |||
| Type | Function | Source | Line |
| HB_FUNC | P_OPEN(void)
HB_FUNC( P_OPEN )
{
int fd = open( hb_parcx( 1 ), O_RDWR | O_NOCTTY | O_NDELAY ); /* File descriptor for the port */
if( fd != -1 )
fcntl( fd, F_SETFL, 0 );
hb_retnl( fd );
}
| tplinux.c | 71 |
| HB_FUNC | P_INITPORTSPEED(void)
HB_FUNC( P_INITPORTSPEED )
{
struct termios options;
int port = hb_parnl( 1 );
int baud = B300;
char * ptr = hb_parcx( 4 );
int rc;
tcgetattr( port, &options );
/* let's set baud rate */
switch( hb_parnl( 2 ) )
{
case 0: baud = B0; break; /* Drop line */
case 50: baud = B50; break;
case 75: baud = B75; break;
case 110: baud = B110; break;
case 150: baud = B150; break;
case 200: baud = B200; break;
case 300: baud = B300; break;
case 600: baud = B600; break;
case 1200: baud = B1200; break;
case 1800: baud = B1800; break;
case 2400: baud = B2400; break;
case 4800: baud = B4800; break;
case 9600: baud = B9600; break;
case 19200: baud = B19200; break;
case 38400: baud = B38400; break;
case 57600: baud = B57600; break;
case 115200: baud = B115200; break;
case 230400: baud = B230400; break;
}
cfsetispeed( &options, baud );
cfsetospeed( &options, baud );
/* Enable the receiver and set local mode... */
options.c_cflag |= ( CLOCAL | CREAD );
/* Raw input from device */
cfmakeraw( &options );
/* Reset data bits ( cfmakeraw() puts it to CS8 ) */
options.c_cflag &= ~CSIZE;
/* Data bits */
if( hb_parni( 3 ) == 8 )
options.c_cflag |= CS8;
else
options.c_cflag |= CS7;
/* Stop bits */
if( hb_parni( 5 ) == 1 )
options.c_cflag &= ~CSTOPB;
/* Parity, only No, Even, Odd supported */
switch ( *ptr )
{
case 'N':
case 'n':
options.c_cflag &= ~PARENB;
options.c_iflag &= ~(INPCK); /* disable input parity checking */
break;
case 'O':
case 'o':
options.c_cflag |= PARENB;
options.c_cflag |= PARODD;
options.c_iflag |= INPCK;
break;
case 'E':
case 'e':
options.c_cflag |= PARENB;
options.c_cflag &= ~PARODD;
options.c_iflag |= INPCK;
break;
}
/* Every read() call returns as soon as a char is available OR after 3 tenths of a second */
options.c_cc[ VMIN ] = 0;
options.c_cc[ VTIME ] = 3;
/* Set the new options for the port... */
rc = tcsetattr( port, TCSAFLUSH, &options );
hb_retnl( rc );
}
| tplinux.c | 81 |
| HB_FUNC | P_READPORT(void)
HB_FUNC( P_READPORT )
{
char Buffer[ 512 ];
int nRead = read( hb_parnl( 1 ), Buffer, sizeof( Buffer ) );
hb_retclen( nRead > 0 ? Buffer : NULL, nRead );
}
| tplinux.c | 180 |
| HB_FUNC | P_WRITEPORT(void)
HB_FUNC( P_WRITEPORT )
{
long n = write( hb_parnl( 1 ), hb_parcx( 2 ), hb_parclen( 2 ) );
hb_retnl( n < 0 ? -1 : n );
}
| tplinux.c | 188 |
| HB_FUNC | P_DRAIN(void)
HB_FUNC( P_DRAIN )
{
hb_retnl( tcdrain( hb_parnl( 1 ) ) );
}
| tplinux.c | 195 |
| HB_FUNC | P_OUTFREE(void)
HB_FUNC( P_OUTFREE )
{
#if 0
APIRET rc;
RXQUEUE rxqueue = { 0 };
if ( ( rc = DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETOUTQUECOUNT,
NULL, 0L, NULL, &rxqueue, sizeof( RXQUEUE ), NULL ) ) == NO_ERROR )
hb_retnl( rxqueue.cb - rxqueue.cch );
else
hb_retnl( -1 ); /* Put GetLastError() here, or better a second byref param? */
#endif
}
| tplinux.c | 200 |
| HB_FUNC | P_ISDCD(void)
HB_FUNC( P_ISDCD )
{
int status;
if ( ioctl( hb_parnl( 1 ), TIOCMGET, &status ) == 0 )
hb_retl( ( status & TIOCM_CD ) == TIOCM_CD );
else
hb_retl( FALSE );
}
| tplinux.c | 214 |
| HB_FUNC | P_ISRI(void)
HB_FUNC( P_ISRI )
{
int status;
if ( ioctl( hb_parnl( 1 ), TIOCMGET, &status ) == 0 )
hb_retl( ( status & TIOCM_RI ) == TIOCM_RI );
else
hb_retl( FALSE );
}
| tplinux.c | 224 |
| HB_FUNC | P_ISDSR(void)
HB_FUNC( P_ISDSR )
{
int status;
if ( ioctl( hb_parnl( 1 ), TIOCMGET, &status ) == 0 )
hb_retl( ( status & TIOCM_DSR ) == TIOCM_DSR );
else
hb_retl( FALSE );
}
| tplinux.c | 234 |
| HB_FUNC | P_ISCTS(void)
HB_FUNC( P_ISCTS )
{
int status;
if ( ioctl( hb_parnl( 1 ), TIOCMGET, &status ) == 0 )
hb_retl( ( status & TIOCM_CTS ) == TIOCM_CTS );
else
hb_retl( FALSE );
}
| tplinux.c | 244 |
| HB_FUNC | P_CTRLCTS(void)
HB_FUNC( P_CTRLCTS )
{
#if !defined( CRTSCTS ) && defined( __WATCOMC__ )
# define CRTSCTS 020000000000
#endif
struct termios options;
int port = hb_parnl( 1 );
int newvalue = hb_pcount() == 2 ? hb_parnl( 2 ) : -1;
int curvalue;
int rc;
tcgetattr( port, &options );
curvalue = ( options.c_cflag & CRTSCTS ) == CRTSCTS;
if( newvalue == 0 )
options.c_cflag &= ~CRTSCTS;
else if( newvalue == 1 )
options.c_cflag |= CRTSCTS;
if( newvalue >= 0 )
rc = tcsetattr( port, TCSAFLUSH, &options );
hb_retni( curvalue ? 1 : 0 );
}
| tplinux.c | 254 |
| HB_FUNC | P_CTRLDTR(void)
HB_FUNC( P_CTRLDTR )
{
double nph = hb_parnd( 1 );
double nnewval, noldval;
unsigned int result = 0;
ioctl( nph, TIOCMGET, &result );
if( result & TIOCM_DTR )
noldval = 1;
else
noldval = 0;
if( noldval != nnewval )
{
if( nnewval == 0 )
result &= ~TIOCM_DTR;
else
result |= TIOCM_DTR;
ioctl( nph, TIOCMSET, &result );
}
hb_stornd( nnewval, 2 );
hb_stornd( noldval, 3 );
}
| tplinux.c | 281 |
| tpos2.c | |||
| Type | Function | Source | Line |
| HB_FUNC | P_INITPORTSPEED(void)
HB_FUNC( P_INITPORTSPEED )
{
LINECONTROL lctl;
DCBINFO dcb;
USHORT Baud = ( USHORT ) hb_parnl( 2 );
char * ptr = hb_parcx( 4 );
memset( &dcb, 0, sizeof( dcb ) );
memset( &lctl, 0, sizeof( lctl ) );
/* OS/2 has Mark and Space parity options */
switch( *ptr )
{
case 'N':
case 'n':
lctl.bParity = 0;
break;
case 'O':
case 'o':
lctl.bParity = 1;
break;
case 'E':
case 'e':
lctl.bParity = 2;
break;
case 'M':
case 'm':
lctl.bParity = 3;
break;
case 'S':
case 's':
lctl.bParity = 4;
}
lctl.bDataBits = hb_parnl( 3 );
lctl.bStopBits = hb_parnl( 5 ) == 1 ? 0 : hb_parnl( 5 ); /* 1 == 1.5 stop bits only valid with 5 data bits */
lctl.fTransBreak = 0;
if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_SETBAUDRATE, &Baud,
sizeof( USHORT ), NULL, NULL, 0L, NULL ) == NO_ERROR )
{
if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_SETLINECTRL,
&lctl, sizeof( LINECONTROL ), NULL, NULL, 0L, NULL ) == NO_ERROR )
{
/* tp_ help says: on port open
DTR ON (value 1)
CTS OFF
DCD IGNORE
DSR OFF
RTS ON (value 1)
XON/XOFF OFF
*/
dcb.fbCtlHndShake = MODE_DTR_HANDSHAKE | MODE_RTS_HANDSHAKE;
/* 0x20 == full duplex */
dcb.fbFlowReplace = MODE_RTS_HANDSHAKE | 0x20;
dcb.fbTimeout = MODE_NO_WRITE_TIMEOUT | MODE_NOWAIT_READ_TIMEOUT;
if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_SETDCBINFO, &dcb,
sizeof(DCBINFO), 0L, NULL, 0L, NULL ) == NO_ERROR )
hb_retnl( 0 );
else
hb_retnl( -3 );
}
else
hb_retnl( -2 );
}
else
hb_retnl( -1 );
}
| tpos2.c | 70 |
| HB_FUNC | P_READPORT(void)
HB_FUNC( P_READPORT )
{
char Buffer[ 512 ];
ULONG nRead = 0;
APIRET rc = DosRead( ( HFILE ) hb_parnl( 1 ), Buffer, sizeof( Buffer ), &nRead );
hb_retclen( rc == NO_ERROR ? Buffer : NULL, nRead );
}
| tpos2.c | 142 |
| HB_FUNC | P_WRITEPORT(void)
HB_FUNC( P_WRITEPORT )
{
ULONG nWritten = 0;
APIRET rc = DosWrite( ( HFILE ) hb_parnl( 1 ), hb_parcx( 2 ), hb_parclen( 2 ), &nWritten );
hb_retnl( rc == NO_ERROR ? ( long ) nWritten : -1 ); /* Put GetLastError() on error, or better a second byref param? */
}
| tpos2.c | 151 |
| HB_FUNC | P_OUTFREE(void)
HB_FUNC( P_OUTFREE )
{
APIRET rc;
RXQUEUE rxqueue;
memset( &rxqueue, 0, sizeof( rxqueue ) );
if( ( rc = DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETOUTQUECOUNT,
NULL, 0L, NULL, &rxqueue, sizeof(RXQUEUE), NULL ) ) == NO_ERROR )
hb_retnl( rxqueue.cb - rxqueue.cch );
else
hb_retnl( -1 ); /* Put GetLastError() here, or better a second byref param? */
}
| tpos2.c | 159 |
| HB_FUNC | P_ISDCD(void)
HB_FUNC( P_ISDCD )
{
BYTE instat;
/* if DosDevIOCtl() returns an error, return no DCD */
if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETMODEMINPUT,
NULL, 0, NULL, &instat, sizeof( instat ), NULL ) == NO_ERROR )
hb_retl( ( instat & DCD_ON ) == DCD_ON );
else
hb_retl( FALSE );
}
| tpos2.c | 173 |
| HB_FUNC | P_ISRI(void)
HB_FUNC( P_ISRI )
{
BYTE instat;
if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETMODEMINPUT,
NULL, 0, NULL, &instat, sizeof( instat ), NULL ) == NO_ERROR )
hb_retl( ( instat & RI_ON ) == RI_ON );
else
hb_retl( FALSE );
}
| tpos2.c | 185 |
| HB_FUNC | P_ISDSR(void)
HB_FUNC( P_ISDSR )
{
BYTE instat;
if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETMODEMINPUT,
NULL, 0, NULL, &instat, sizeof( instat ), NULL ) == NO_ERROR )
hb_retl( ( instat & DSR_ON ) == DSR_ON );
else
hb_retl( FALSE );
}
| tpos2.c | 196 |
| HB_FUNC | P_ISCTS(void)
HB_FUNC( P_ISCTS )
{
BYTE instat;
if( DosDevIOCtl( ( HFILE ) hb_parnl( 1 ), IOCTL_ASYNC, ASYNC_GETMODEMINPUT,
NULL, 0, NULL, &instat, sizeof( instat ), NULL ) == NO_ERROR )
hb_retl( ( instat & CTS_ON ) == CTS_ON );
else
hb_retl( FALSE );
}
| tpos2.c | 207 |
| HB_FUNC | P_CTRLCTS(void)
HB_FUNC( P_CTRLCTS )
{
hb_retni( 0 );
}
| tpos2.c | 218 |
| tpwin32.c | |||
| Type | Function | Source | Line |
| HB_FUNC | P_INITPORTSPEED(void)
HB_FUNC( P_INITPORTSPEED )
{
DCB dcb;
char values[ 20 ];
LPTSTR lpValues;
FillMemory( &dcb, sizeof( dcb ), 0 );
dcb.DCBlength = sizeof( dcb );
snprintf( values, sizeof( values ), "%lu,%1s,%1lu,%1lu", hb_parnl( 2 ), hb_parcx( 4 ), hb_parnl( 3 ), hb_parnl( 5 ) );
lpValues = HB_TCHAR_CONVTO( values );
if( BuildCommDCB( lpValues, &dcb ) )
{
if( SetCommState( ( HANDLE ) hb_parnl( 1 ), &dcb ) )
{
COMMTIMEOUTS timeouts;
/* read/write operations return immediatly */
timeouts.ReadIntervalTimeout = MAXDWORD;
timeouts.ReadTotalTimeoutMultiplier = 0;
timeouts.ReadTotalTimeoutConstant = 0;
timeouts.WriteTotalTimeoutMultiplier = 0;
timeouts.WriteTotalTimeoutConstant = 0;
hb_retnl( SetCommTimeouts( ( HANDLE ) hb_parnl( 1 ), &timeouts ) ? 0 : -1 );
}
else
hb_retnl( -1 );
}
else
hb_retnl( -1 );
HB_TCHAR_FREE( lpValues );
}
| tpwin32.c | 64 |
| HB_FUNC | P_READPORT(void)
HB_FUNC( P_READPORT )
{
char Buffer[ 512 ];
DWORD nRead = 0;
OVERLAPPED Overlapped;
BOOL bRet;
memset( &Overlapped, 0, sizeof( OVERLAPPED ) );
bRet = ReadFile( ( HANDLE ) hb_parnl( 1 ), Buffer, sizeof( Buffer ), &nRead, &Overlapped );
hb_retclen( bRet ? Buffer : NULL, nRead );
}
| tpwin32.c | 100 |
| HB_FUNC | P_WRITEPORT(void)
HB_FUNC( P_WRITEPORT )
{
DWORD nWritten = 0;
OVERLAPPED Overlapped;
BOOL bRet;
memset( &Overlapped, 0, sizeof( OVERLAPPED ) );
bRet = WriteFile( ( HANDLE ) hb_parnl( 1 ), hb_parcx( 2 ), hb_parclen( 2 ), &nWritten, &Overlapped );
hb_retnl( bRet ? ( long ) nWritten : -1 ); /* Put GetLastError() on error, or better a second byref param? */
}
| tpwin32.c | 112 |
| telepath.prg | |||
| Type | Function | Source | Line |
| FUNCTION | tp_baud( nPort, nNewBaud )
function tp_baud( nPort, nNewBaud )
local nRes
default nNewBaud to 0
if ! isport( nPort ) .OR. Empty( s_aPorts[ nPort, TPFP_NAME ] )
return TE_NOPORT
endif
if ! isopenport( nPort )
return 0
endif
if nNewBaud > 0
if ( nRes := p_InitPortSpeed( s_aPorts[ nPort, TPFP_HANDLE ] ,;
nNewBaud,;
s_aPorts[ nPort, TPFP_DBITS ] ,;
s_aPorts[ nPort, TPFP_PARITY ] ,;
s_aPorts[ nPort, TPFP_SBITS ] ) ) == 0
s_aPorts[ nPort, TPFP_BAUD ] := nNewBaud
else
// set error code
endif
endif
return s_aPorts[ nPort, TPFP_BAUD ]
| telepath.prg | 73 |
| FUNCTION | tp_inkey( nSecs )
function tp_inkey( nSecs )
if valtype( nSecs ) == "U"
return inkey()
endif
return inkey( nSecs )
| telepath.prg | 106 |
| FUNCTION | tp_idle( lNewval )
function tp_idle( lNewval )
if lNewval == .t.
return .t.
endif
return .f.
| telepath.prg | 114 |
| FUNCTION | tp_delay( nTime )
function tp_delay( nTime )
default nTime to 0
if nTime < 0
return nil
elseif nTime > 1800
nTime := 1800
endif
ThreadSleep( nTime * 1000 )
return nil
| telepath.prg | 122 |
| FUNCTION | tp_close( nPort, nTimeout )
function tp_close( nPort, nTimeout )
default nTimeout to 0
/* Clipper returns 0 even if a port is not open */
if ! isopenport( nPort )
return 0
endif
if nTimeout > 0
tp_flush( nPort, nTimeout )
endif
if s_aPorts[ nPort, TPFP_HANDLE ] >= 0
fClose( s_aPorts[ nPort, TPFP_HANDLE ] )
/* Port parameters should stay the same for the case the port
gets reopened
*/
s_aPorts[ nPort, TPFP_OC ] := .F.
s_aPorts[ nPort, TPFP_INBUF ] := ""
s_aPorts[ nPort, TPFP_HANDLE ] := -1
endif
return 0
| telepath.prg | 140 |
| FUNCTION | tp_reopen( nPort, nInSize, nOutSize )
function tp_reopen( nPort, nInSize, nOutSize )
LOCAL nBaud, nData, cParity, nStop, cPortName
default nInSize to 1536, nOutSize to 1536
if ! isport( nPort ) .OR. Empty( s_aPorts[ nPort, TPFP_NAME ] )
return TE_NOPORT
endif
cPortname := s_aPorts[ nPort, TPFP_NAME ]
nBaud := s_aPorts[ nPort, TPFP_BAUD ]
nData := s_aPorts[ nPort, TPFP_DBITS ]
cParity := s_aPorts[ nPort, TPFP_PARITY ]
nStop := s_aPorts[ nPort, TPFP_SBITS ]
return tp_open( nPort, nInSize, nOutSize, nBaud, nData, cParity, nStop, cPortName )
| telepath.prg | 169 |
| FUNCTION | tp_open( nPort, nInSize, nOutSize, nBaud, nData, cParity, nStop, cPortname )
function tp_open( nPort, nInSize, nOutSize, nBaud, nData, cParity, nStop, cPortname )
local nRes, lPortExist
#ifdef __PLATFORM__LINUX
local nFileCase, nDirCase
#endif
default nInSize to 1536, nOutSize to 1536
default nBaud to 1200, nData to 8, cParity to "N", nStop to 1
/* Serial ports name are made up of cPortName + nPort if nPort is not NIL */
#ifdef __PLATFORM__LINUX
default cPortName to "/dev/ttyS"
#else
default cPortName to "COM" // Ok for Win32 and OS/2
#endif
/* This way compatibility is retained for ports 1-4 on Win32 and Linux, but,
should necessity arise, it is possible to simply pass a NIL on nPort and
a full name on cPortName
*/
#ifdef __PLATFORM__LINUX
cPortname := AllTrim( cPortname ) + iif( ValType( nPort ) == "N", AllTrim( Str( nPort - 1 ) ), "" )
#else
cPortname := AllTrim( cPortname ) + iif( ValType( nPort ) == "N", AllTrim( Str( nPort ) ), "" )
#endif
#ifdef __PLATFORM__LINUX
nFileCase := Set( _SET_FILECASE, 0 )
nDirCase := Set( _SET_DIRCASE, 0 )
#endif
lPortExist := File( cPortname )
#ifdef __PLATFORM__LINUX
Set( _SET_FILECASE, nFileCase )
Set( _SET_DIRCASE, nDirCase )
#endif
if ! lPortExist
return TE_NOPORT
endif
if ! isport( nPort )
return TE_NOPORT
endif
s_aPorts[ nPort, TPFP_NAME ] := cPortname
s_aPorts[ nPort, TPFP_BAUD ] := nBaud
s_aPorts[ nPort, TPFP_DBITS ] := nData
s_aPorts[ nPort, TPFP_PARITY ] := cParity
s_aPorts[ nPort, TPFP_SBITS ] := nStop
s_aPorts[ nPort, TPFP_OC ] := .F.
s_aPorts[ nPort, TPFP_INBUF ] := ""
s_aPorts[ nPort, TPFP_INBUF_SIZE ] := nInSize
#ifdef __PLATFORM__LINUX
// Maybe we should have a p_Open() on every platform
s_aPorts[ nPort, TPFP_HANDLE ] := p_Open( cPortname )
#else
s_aPorts[ nPort, TPFP_HANDLE ] := fOpen( cPortname, FO_READWRITE )
#endif
if s_aPorts[ nPort, TPFP_HANDLE ] >= 0
/* low level C functions are prefixed p_ (don't ask me why :)) */
if ( nRes := p_InitPortSpeed( s_aPorts[ nPort, TPFP_HANDLE ] ,;
s_aPorts[ nPort, TPFP_BAUD ] ,;
s_aPorts[ nPort, TPFP_DBITS ] ,;
s_aPorts[ nPort, TPFP_PARITY ] ,;
s_aPorts[ nPort, TPFP_SBITS ] ) ) == 0
s_aPorts[ nPort, TPFP_OC ] := .T.
return nRes
else
tp_Close( s_aPorts[ nPort, TPFP_HANDLE ] )
return nRes
endif
endif
// set error code to a static var to have tp_error() work as expected
//cnHandle := ferror()
s_aPorts[ nPort, TPFP_NAME ] := ""
s_aPorts[ nPort, TPFP_HANDLE ] := -1
s_aPorts[ nPort, TPFP_BAUD ] := 1200
s_aPorts[ nPort, TPFP_DBITS ] := 8
s_aPorts[ nPort, TPFP_PARITY ] := "N"
s_aPorts[ nPort, TPFP_SBITS ] := 1
s_aPorts[ nPort, TPFP_OC ] := .F.
s_aPorts[ nPort, TPFP_INBUF ] := ""
s_aPorts[ nPort, TPFP_INBUF_SIZE ] := 0
return TE_CONFL // maybe should return something different?
| telepath.prg | 189 |
| FUNCTION | tp_recv( nPort, nLength, nTimeout )
function tp_recv( nPort, nLength, nTimeout )
local nDone
local cRet := ""
default nLength to s_aPorts[ nPort, TPFP_INBUF_SIZE ]
default nTimeout to 0
FetchChars( nPort )
nDone := Seconds() + iif( nTimeout >= 0, nTimeout, 0 )
while Len( s_aPorts[ nPort, TPFP_INBUF ] ) < nLength .AND.;
( nTimeout < 0 .OR. Seconds() < nDone )
if ! tp_idle()
FetchChars( nPort )
else
exit
endif
enddo
if nLength > Len( s_aPorts[ nPort, TPFP_INBUF ] )
cRet := s_aPorts[ nPort, TPFP_INBUF ]
s_aPorts[ nPort, TPFP_INBUF ] := ""
else
cRet := SubStr( s_aPorts[ nPort, TPFP_INBUF ], 1, nLength )
s_aPorts[ nPort, TPFP_INBUF ] := SubStr( s_aPorts[ nPort, TPFP_INBUF ], nLength + 1 )
endif
return cRet
| telepath.prg | 289 |
| FUNCTION | tp_send( nPort, cString, nTimeout )
function tp_send( nPort, cString, nTimeout )
local nWritten, nTotWritten, nDone
default cString to "", nTimeout to 0
if ! isopenport( nPort )
return 0
endif
if Empty( cString )
return 0
endif
nDone := Seconds() + iif( nTimeout >= 0, nTimeout, 0)
nWritten := nTotWritten := 0
while nTotWritten < Len( cString ) .AND. ;
( nTimeout < 0 .OR. Seconds() <= nDone )
nWritten := p_WritePort( s_aPorts[ nPort, TPFP_HANDLE ], SubStr( cString, nTotWritten + 1 ) )
if nWritten >= 0
nTotWritten += nWritten
if nTotWritten < Len( cString )
if ! tp_idle()
ThreadSleep( 1000 )
else
exit
endif
endif
else // nWritten < 0, error occurred
exit
endif
enddo
return nTotWritten
| telepath.prg | 324 |
| FUNCTION | tp_sendsub( nPort, cString, nStart, nLength, nTimeout )
function tp_sendsub( nPort, cString, nStart, nLength, nTimeout ) default nStart to 1, nLength to Len( cString ) return tp_send( nPort, SubStr( cString, nStart, nLength ), nTimeout ) | telepath.prg | 371 |
| FUNCTION | tp_recvto( nPort, cDelim, nMaxlen, nTimeout )
function tp_recvto( nPort, cDelim, nMaxlen, nTimeout )
local cChar
local nAt
local nStartPos := 1, nFirst := 0
local nDone, cRet := ""
if ! isopenport( nPort )
return ""
endif
if !( ValType( cDelim ) == "C" ) .OR. Empty( cDelim )
return ""
endif
default nMaxlen to 64999 /* dos telepathy def. on xharbour could be higher */
default nTimeout to 0
FetchChars( nPort )
/* Telepathy ng: [...] If nTimeout is omitted or zero, reads until finding the
delimiter or the input buffer is empty. */
if nTimeout == 0 .AND. Empty( s_aPorts[ nPort, TPFP_INBUF ] )
return ""
endif
nDone := Seconds() + iif( nTimeout >= 0, nTimeout, 0 )
while ( nTimeout < 0 .OR. Seconds() < nDone )
if Len( cDelim ) == 1
nAt := hb_At( cDelim, s_aPorts[ nPort, TPFP_INBUF ], nStartPos )
if nAt > 0 .AND. iif( nFirst > 0, nAt < nFirst, .T. )
nFirst := nAt
endif
else
FOR EACH cChar IN cDelim
nAt := hb_At( cChar, s_aPorts[ nPort, TPFP_INBUF ], nStartPos )
if nAt > 0 .AND. iif( nFirst > 0, nAt < nFirst, .T. )
nFirst := nAt
endif
NEXT
endif
// I've found it
if nFirst > 0
exit
else
// Next loop I don't need to search that part of the input buffer that
// I've already just searched for
nStartPos := Max( Len( s_aPorts[ nPort, TPFP_INBUF ] ), 1 )
// I've read more characters than I'm allowed to, so I exit
if nStartPos >= nMaxLen
exit
endif
if ! tp_idle()
FetchChars( nPort )
else
exit
endif
endif
enddo
if nFirst > 0
cRet := Left( s_aPorts[ nPort, TPFP_INBUF ], nFirst )
s_aPorts[ nPort, TPFP_INBUF ] := SubStr( s_aPorts[ nPort, TPFP_INBUF ], nFirst + 1 )
endif
return cRet
| telepath.prg | 379 |
| FUNCTION | tp_lookfor( nPort, cLookfor )
function tp_lookfor( nPort, cLookfor )
if ! isopenport( nPort )
return 0
endif
FetchChars( nPort )
return At( cLookfor, s_aPorts[ nPort, TPFP_INBUF ] )
| telepath.prg | 471 |
| FUNCTION | tp_inchrs( nPort )
function tp_inchrs( nPort )
if ! isopenport( nPort )
return 0
endif
FetchChars( nPort )
return Len( s_aPorts[ nPort, TPFP_INBUF ] )
| telepath.prg | 483 |
| FUNCTION | tp_outfree( nPort )
function tp_outfree( nPort )
if ! isopenport( nPort )
return 0
endif
return p_OutFree( s_aPorts[ nPort, TPFP_HANDLE ] )
| telepath.prg | 495 |
| FUNCTION | tp_clearin( nPort )
function tp_clearin( nPort )
if isopenport( nPort )
FetchChars( nPort )
s_aPorts[ nPort, TPFP_INBUF ] := ""
endif
return nil
| telepath.prg | 505 |
| FUNCTION | tp_clrkbd()
function tp_clrkbd() clear typeahead return nil | telepath.prg | 516 |
| FUNCTION | tp_crc16( cString )
function tp_crc16( cString ) return p_CRC16( cString ) | telepath.prg | 524 |
| FUNCTION | tp_crc32( cString )
function tp_crc32( cString ) return p_CRC32( cString ) | telepath.prg | 530 |
| FUNCTION | tp_waitfor( ... )
function tp_waitfor( ... )
local aParam := hb_AParams()
local nPort, nTimeout, lIgnorecase
nPort := aParam[ 1 ]
nTimeout := aParam[ 2 ]
lIgnorecase := aParam[ Len( aParam ) ]
if ! isopenport( nPort )
return 0
endif
default nTimeout to -1
default lIgnorecase to .f.
/*
if ntimeout < 0
nDone := _clock() + 999999
elseif ntimeout == 0
nDone := 4
else
nDone := _clock() + nTimeout
endif
while ( nDone > _clock() .or. nFirst == 100000 ) .and. ! tp_idle()
if nFirst == 100000
nFirst := 99999
endif
FetchChars( nPort )
for x := 1 to len( acList )
if lIgnorecase
nAt := at( upper( acList[ x ] ), upper( s_aPorts[ nPort, TPFP_INBUF ] ))
else
nAt := at( acList[ x ] , s_aPorts[ nPort, TPFP_INBUF ] )
endif
if nAt > 0 .and. nAt < nFirst
nFirst := nAt
nRet := x
endif
next
if nFirst < 64000
exit
endif
#if 0
sched_yield() // C level function
#endif
enddo
if nFirst < 64000
tp_recv( nPort, nAt + len( acList[ nRet ] ))
return nRet
endif
*/
return 0
/* We cannot set, well, _I_ think we cannot, CTS without setting RTS flowcontrol, so this
| telepath.prg | 536 |
| FUNCTION AND | tp_ctrlrts() do the same thing, that is set/reset CRTSCTS flowcontol
function and tp_ctrlrts() do the same thing, that is set/reset CRTSCTS flowcontol */ | telepath.prg | 603 |
| FUNCTION | tp_ctrlcts( nPort, nNewCtrl )
function tp_ctrlcts( nPort, nNewCtrl )
local nCurValue
if ! isopenport( nPort )
return 0
endif
if Valtype( nNewCtrl ) == "U"
nCurValue := p_ctrlcts( s_aPorts[ nPort, TPFP_HANDLE ] )
else
nCurValue := p_ctrlcts( s_aPorts[ nPort, TPFP_HANDLE ], nNewCtrl )
endif
return nCurValue
| telepath.prg | 604 |
| FUNCTION | tp_ctrlrts( nPort, nNewCtrl )
function tp_ctrlrts( nPort, nNewCtrl ) return tp_ctrlcts( nPort, nNewCtrl ) | telepath.prg | 624 |
| FUNCTION | tp_isdcd( nPort )
function tp_isdcd( nPort )
if ! isopenport( nPort )
return .f.
endif
return p_isdcd( s_aPorts[ nPort, TPFP_HANDLE ] )
| telepath.prg | 651 |
| FUNCTION | tp_isri( nPort )
function tp_isri( nPort )
if ! isopenport( nPort )
return .f.
endif
return p_isri( s_aPorts[ nPort, TPFP_HANDLE ] )
| telepath.prg | 661 |
| FUNCTION | tp_isdsr( nPort )
function tp_isdsr( nPort )
if ! isopenport( nPort )
return .f.
endif
return p_isdsr( s_aPorts[ nPort, TPFP_HANDLE ] )
| telepath.prg | 671 |
| FUNCTION | tp_iscts( nPort )
function tp_iscts( nPort )
if ! isopenport( nPort )
return .f.
endif
return p_iscts( s_aPorts[ nPort, TPFP_HANDLE ] )
| telepath.prg | 681 |
| FUNCTION | tp_flush( nPort, nTimeout )
function tp_flush( nPort, nTimeout )
local nStart := Seconds()
local nRes
default nTimeout to 0
if ! isopenport( nPort )
return TE_CLOSED
endif
nRes := p_Drain( s_aPorts[ nPort, TPFP_HANDLE ] )
// Sleep rest of timeout
/*
if nTimeout > 0 .AND. Seconds() - nStart < nTimeout
ThreadSleep( ( nTimeout - ( Seconds() - nStart ) ) * 1000 )
endif
*/
// NB: returns timeout on error trying to reach compatibility with other platforms
// to be tested
return iif( nRes == 0, 0, TE_TMOUT )
| telepath.prg | 694 |
| FUNCTION | tp_flush( nPort, nTimeout )
function tp_flush( nPort, nTimeout )
local nDone
default nTimeout to -1
if ! isopenport( nPort )
return TE_CLOSED
endif
if nTimeout > 1800
nTimeout := 1800
endif
nDone := Seconds() + iif( nTimeout >= 0, nTimeout, 0 )
while tp_OutFree( nPort ) > 0 .AND. ;
( nTimeout < 0 .OR. Seconds() < nDone )
hb_IdleState()
enddo
return iif( tp_OutFree( nPort ) > 0, TE_TMOUT, 0 )
| telepath.prg | 720 |
| STATIC FUNCTION | isopenport( nPort )
static function isopenport( nPort )
if ! isport( nPort )
return .f.
endif
return s_aPorts[ nPort, TPFP_OC ]
| telepath.prg | 766 |
| STATIC FUNCTION | isport( nPort )
static function isport( nPort )
if valtype( nPort ) != "N" .or. nPort < 1 .or. nPort > TP_MAXPORTS
return .f.
endif
return .t.
| telepath.prg | 776 |
| STATIC FUNCTION | FetchChars( nPort )
static function FetchChars( nPort )
local cStr := ""
if ! isopenport( nPort )
return 0
endif
cStr := p_ReadPort( s_aPorts[ nPort, TPFP_HANDLE ] )
if ! Empty( cStr )
s_aPorts[ nPort, TPFP_INBUF ] += cStr
endif
return Len( cStr )
| telepath.prg | 786 |
| INIT PROCEDURE | _tpinit()
INIT PROCEDURE _tpinit()
local x
if s_aPorts == nil
s_aPorts := array( TP_MAXPORTS )
for x := 1 to len( s_aPorts )
/// port name, file handle, baud, data bits, parity, stop bits, Open?, input buffer, input buff.size
s_aPorts[ x ] := { "", -1, 1200, 8, "N", 1, .F., "", 0 }
next
endif
return
| telepath.prg | 804 |
| PROCEDURE | tp_uninstall()
procedure tp_uninstall() /* NOTE: dummy function, solely for compatibility. */ return | telepath.prg | 869 |
Page url: http://www.yourdomain.com/help/index.html?hbtpathy.htm