FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveLinux / FiveDroid (Android) Serial Port
Posts: 563
Joined: Sun Oct 09, 2005 07:23 PM
Serial Port
Posted: Fri Sep 19, 2008 08:46 AM

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.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Serial Port
Posted: Fri Sep 19, 2008 09:05 AM

Verhoven,

Please review this:

http://akimpech.izt.uam.mx/Web_jr/ttylinux.pdf

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 563
Joined: Sun Oct 09, 2005 07:23 PM
Serial Port
Posted: Fri Sep 19, 2008 10:37 AM

NO LO ABRE ANTONIO. DICE QUE NO TIENE FORMATO PDF.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Serial Port
Posted: Fri Sep 19, 2008 10:46 AM

Please use Internet Explorer to open it :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 109
Joined: Sun Nov 13, 2005 12:40 AM
Re: Serial Port
Posted: Fri Apr 09, 2010 08:14 AM
Code (fw): Select all Collapse
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);
}
FWH User

FWPPC User

FWLinux User

Continue the discussion