Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2006-12

Re: Linux serial interface

12 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Van Canneyt
to Rainer Stratmann: How to open correct the serial interface ('/dev/ttyS0') In my program it works for…
Rainer Stratmann wrote
How to open correct the serial interface ('/dev/ttyS0')

As far as I know, this is a terminal, so the terminal emulator will mess up the IO. You should open the raw device.

In my program it works for writing, but reading is not possible at the moment. Has someone an idea or example code?

If you have access to Toolbox, it comes with a TSerial component. It should work with FPC and Linux.

I also think there is a serial unit distributed with FPC, but I am sure about it's inner workings.

Michael.

Reply by email

Johann Glaser
to Rainer Stratmann: Isn't tty1 (without S) a terminal? I don't know to access the tools. It should not be…

Hi!

Rainer Stratmann wrote 8 lines
Am Dienstag, 26. Dezember 2006 14:07 schrieb Michael Van Canneyt: > On Tue, 26 Dec 2006, Rainer Stratmann wrote: > > How to open correct the serial interface ('/dev/ttyS0') > > As far as I know, this is a terminal, so the terminal emulator will mess up > the IO. You should open the raw device. Isn't tty1 (without S) a terminal?

The ttySx devices also do a lot of terminal emulation stuff internally (see e.g. stty(1) for how many things are possible, in your program you have to do these with ioctl()).

Especially I have made the observation that flow control often is in your way when you "just want to transmit data". Switch off flow control completely (neither hardware nor software/XON/XOFF). Probably your USB-serial converter has different default values for this and this is why your program works with it.

Bye
Hansi

Reply by email

Daniël Mantione
to Michael Van Canneyt: As far as I know, this is a terminal, so the terminal emulator will mess up the IO. You…

Op Tue, 26 Dec 2006, schreef Michael Van Canneyt:

Show quoted text 8 lines
On Tue, 26 Dec 2006, Rainer Stratmann wrote: > How to open correct the serial interface ('/dev/ttyS0') As far as I know, this is a terminal, so the terminal emulator will mess up the IO. You should open the raw device.

The raw decives are no longer in use, they are even no longer on my system:

laptop:~ # ls -al /dev/cua*
/bin/ls: /dev/cua*: Onbekend bestand of map
laptop:~ #

/dev/ttyS0 is the correct device, you have to disable most of the terminal handling through ioctls.

Daniël

Reply by email

Rainer Stratmann

How to open correct the serial interface ('/dev/ttyS0') In my program it works for writing, but reading is not possible at the moment. Has someone an idea or example code?
Rainer

With USB-to serial Converter the program works (!), but not with the standard 9P serial connector on the mainboard (tested more computers).

Reply by email

Rainer Stratmann
to Michael Van Canneyt: As far as I know, this is a terminal, so the terminal emulator will mess up the IO. You…
Michael Van Canneyt wrote 5 lines
On Tue, 26 Dec 2006, Rainer Stratmann wrote: > How to open correct the serial interface ('/dev/ttyS0') As far as I know, this is a terminal, so the terminal emulator will mess up the IO. You should open the raw device.

Isn't tty1 (without S) a terminal?

Show quoted text 8 lines
> In my program it works for writing, but reading is not possible at the > moment. Has someone an idea or example code? If you have access to Toolbox, it comes with a TSerial component. It should work with FPC and Linux. I also think there is a serial unit distributed with FPC, but I am sure about it's inner workings.

I don't know to access the tools.
It should not be that difficult, because the same code works with USB-serial converters ('/dev/ttyUSB0') correctly.
Only reading is not possible with the built in serial ports at the PC. The connected Hardware indicates the receive of the writing data correctly.

Rainer

Michael. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Rainer Stratmann
to Johann Glaser: Hi! The ttySx devices also do a lot of terminal emulation stuff internally (see e.g.…
Johann Glaser wrote 15 lines
Hi! Am Dienstag, den 26.12.2006, 15:38 +0100 schrieb Rainer Stratmann: > Am Dienstag, 26. Dezember 2006 14:07 schrieb Michael Van Canneyt: > > On Tue, 26 Dec 2006, Rainer Stratmann wrote: > > > How to open correct the serial interface ('/dev/ttyS0') > > > > As far as I know, this is a terminal, so the terminal emulator will > > mess up the IO. You should open the raw device. > > Isn't tty1 (without S) a terminal? The ttySx devices also do a lot of terminal emulation stuff internally (see e.g. stty(1) for how many things are possible, in your program you have to do these with ioctl()).

how to do that?

Show quoted text 5 lines
Especially I have made the observation that flow control often is in your way when you "just want to transmit data". Switch off flow control completely (neither hardware nor software/XON/XOFF). Probably your USB-serial converter has different default values for this and this is why your program works with it.

do you have little example code?
thanks
Rainer

Show quoted text 7 lines
Bye Hansi _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

John Coppens
to Rainer Stratmann: How to open correct the serial interface ('/dev/ttyS0') In my program it works for…
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.

John

Reply by email

Rainer Stratmann
to John Coppens
John Coppens wrote 10 lines
On Tue, 26 Dec 2006 15:10:27 +0100 Rainer Stratmann 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 - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Martin Schreiber
to Rainer Stratmann
Rainer Stratmann wrote 30 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));

<<<<<----- now you have lost all values from tcgetattr.

Martin

Reply by email