[fpc-pascal] Linux serial interface

Rainer Stratmann RainerStratmann at t-online.de
Tue Dec 26 21:53:25 CET 2006


Am Dienstag, 26. Dezember 2006 19:28 schrieb John Coppens:
> On Tue, 26 Dec 2006 15:10:27 +0100
>
> Rainer Stratmann <RainerStratmann at t-online.de> wrote:
> > In my program it works for writing, but reading is not possible at the
> > moment.
>
> Did you check if (hardware) handshaking is enabled? I've found quite
> regularly that one of the lines is stopping the input. If you have
> connected only RX/TX/GND, this can also be the source of problem if the
> peripheral expects proper level on the handshake lines.
How to do that?
The code for initialisation of the serial interface:

const
 iflagoff = BRKINT or INPCK or ISTRIP or IGNCR or INLCR or ICRNL or IUCLC or
            IXON or IXANY or IXOFF or IMAXBEL;
 iflagon  = IGNBRK or IGNPAR;
 oflagoff = OPOST or OLCUC or ONLCR or OCRNL or ONOCR or ONLRET or OFILL or
            OFDEL or NLDLY or TABDLY or BSDLY or VTDLY or FFDLY;
 oflagon  = 0;
 cflagoff = CBAUD or CSIZE or CSTOPB or PARENB or PARODD or HUPCL or CBAUDEX 
or
            CIBAUD or CRTSCTS ;
 cflagon  = CREAD or CLOCAL;
 lflagoff = ISIG or ICANON or XCASE or ECHO or ECHOE or ECHOK or ECHONL or
            NOFLSH or TOSTOP or ECHOCTL or ECHOPRT or ECHOKE or IEXTEN;
 lflagon  = 0;

 linuxfile:array[serportmin..serportmax] of string =
 ('ttyS0','ttyS1','ttyUSB0','ttyUSB1','ttyUSB2');
begin

  s:='/dev/'+linuxfile[ger_port];

  ger_fd:=fdOpen(s,Open_RdWr or Open_NonBlock);

  tcgetattr(ger_fd,newtio_ger);

  memclr(@newtio_ger,sizeof(newtio_ger));

  newtio_ger.c_iflag:= newtio_ger.c_iflag and not(iflagoff) or iflagon;
  newtio_ger.c_oflag:= newtio_ger.c_oflag and not(oflagoff) or oflagon;
  newtio_ger.c_cflag:= newtio_ger.c_cflag and not(cflagoff) or cflagon;
  newtio_ger.c_lflag:= newtio_ger.c_lflag and not(lflagoff) or lflagon;

  newtio_ger.c_cflag:= newtio_ger.c_cflag or speednr[ger_baudnr] or CS8 or 
CREAD or CLOCAL;


  tcsetattr(ger_fd,TCSAFLUSH,newtio_ger);

Rainer
> John
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal



More information about the fpc-pascal mailing list