Is it possible to use the serial ports in linux from xHarbour or xHarbour+FWL?
I'm thinking to port my software to this OS and I'd like to know this.
Thanks.
Is it possible to use the serial ports in linux from xHarbour or xHarbour+FWL?
I'm thinking to port my software to this OS and I'd like to know this.
Thanks.
NO LO ABRE ANTONIO. DICE QUE NO TIENE FORMATO PDF.
Please use Internet Explorer to open it ![]()
serial_test.prg
//-----------------------------------------------------------------
serial_fd := SERIAL_OPEN("/dev/ttyUSB0")
//"/dev/ttyUSB0" ->USB Serial
///dev/ttyS0 == com1 0x3f8
///dev/ttyS1 == com2
///dev/ttyS2 == com3
///dev/ttyS3 == com4
? SERIAL_WRITE(serial_fd, "Test Serial Port ...", 20)
vcv := 0
do while vcv == 0
serial_buf := spac(512)
se := SERIAL_READ(serial_fd, @serial_buff)
if se > 1
? serial_buf
endi
vcv := inkey()
endd
SERIAL_CLOSE(serial_fd)
//-------------------------------------------------------------------
//Serial port Init...
//-------------------------------------------------------------------
#pragma BEGINDUMP
#include "hbapi.h"
#include "hbfast.h"
#include "hbapifs.h"
#include "hbapierr.h"
#include "hbapiitm.h"
#include "hbvm.h"
#include "sys/ioctl.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "sys/socket.h"
#include "unistd.h"
#include "netinet/in.h"
#include "arpa/inet.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "net/if.h"
#include "arpa/inet.h"
#include "ctype.h"
#include "fcntl.h"
#include "termios.h"
struct termios tio;
HB_FUNC( SERIAL_OPEN )
{
int fd;
if ((fd = open(hb_parc(1), O_RDWR|O_NDELAY|O_NOCTTY)) < 0)
{
hb_retnl(0); //port open error return = 0
}
memset( &tio, 0, sizeof(tio) );
tio.c_cflag = B115200 | CS8 | CREAD | CLOCAL;
//tio.c_cflag &= ~HUPCL;
tio.c_lflag = 0; // local mode setting
tio.c_iflag = IGNPAR | ICRNL; // Parity
tio.c_oflag = 0;
tio.c_cc[VTIME] = 0;
tio.c_cc[VMIN] = 1;
tcflush(fd, TCIFLUSH);
tcsetattr(fd, TCSANOW, &tio);
fcntl(fd, F_SETFL, FNDELAY);
hb_retnl((long)fd);
}
HB_FUNC( SERIAL_CLOSE )
{
close(hb_parnl(1));
}
HB_FUNC( SERIAL_WRITE )
{
long result;
result = write( hb_parnl(1), hb_parcx( 2 ), hb_parnl( 2 ) );
if (result < 0) {
result = 0;
}
hb_retnl(result);
}
HB_FUNC( SERIAL_READ )
{
PHB_ITEM pBuffer = hb_param( 2, HB_IT_STRING );
pBuffer = hb_itemUnShare( pBuffer );
long result;
if ((result = read(hb_parnl(1), hb_itemGetCPtr( pBuffer ), 100)) > 0) {
}
hb_retni(result);
}