serial port flush?

From: Thomas (thomas_at_tho-bai.de)
Date: 01/30/05


Date: Sun, 30 Jan 2005 03:19:36 +0100

Hi there,

I've written a programme, to communicates with a microcontroller, but
sometimes there is no reaction when I send the initial byte. I'm working
under Suse Linux 9.2 prof. and as I know from a windows programme this
problem shouldn't be caused by the microcontroller. As it always works with
this programme under windows.

So could it be, that when there is a failure at the microcontroller, so that
the byte isn't received (i.e. it isn't in bootstrap mode), that after this
the serial port might be blocked by the previous byte? Or somthing like
that. I know, that this byte cannot really "block" the serial port, but
there must be something that blocks the transfer.

So is there a way to "flush" the serial port before starting a transfer? Or
is it something else that causes my problems.

Hier is my procedure that initializes the serial port:

int openport(char* device)
{
        int fd;
        struct termios options;

        //Stream oeffnen
        fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
        
        //ueberpruefen
        if (fd == -1)
                return -1;

        //Alles auf Null setzen
        bzero(&options, sizeof(options));

        //aktuelle Einstellungen holen
        tcgetattr(fd, &options);
        
        //moeglicherweise vorhandene ungewuenschte Einstellungen zuruecksezten
        options.c_cflag &= ~PARENB; //kein Parity-Bit
        options.c_cflag &= ~CSTOPB; //ein Stopbit
        options.c_cflag &= ~CSIZE; //Datenmaske zuruecksetzen
        
        //weitere Controllflags setzen
        options.c_cflag = B19200 | CS8 | CLOCAL | CREAD;
        options.c_iflag = IGNPAR;
        options.c_oflag &= ~OPOST;
        options.c_lflag = 0;
        options.c_cc[VMIN] = 1;
        options.c_cc[VTIME] = 0;

        tcflush(fd, TCIFLUSH);
        tcsetattr(fd, TCSANOW, &options);

        return (fd);
}

So could anybody please help me?

Thanks in advance

Thomas



Relevant Pages

  • Re: serial port flush?
    ... Thomas wrote: ... > under Suse Linux 9.2 prof. and as I know from a windows programme this ... > problem shouldn't be caused by the microcontroller. ... > this the serial port might be blocked by the previous byte? ...
    (comp.arch.embedded)
  • Re: serial port flush?
    ... > under Suse Linux 9.2 prof. and as I know from a windows programme this ... > problem shouldn't be caused by the microcontroller. ... > the serial port might be blocked by the previous byte? ... Try omitting the O_NDELAY flag. ...
    (comp.arch.embedded)
  • Re: Writing pins to the RS232
    ... A serial port does not have data ports 0-n. ... So you slap a chip on between the UART and the RS232 pin that translates the voltages for you. ... UART (usually built into the microcontroller) ... I could use python to communicate serially to a BASIC stamp or a Javelin stamp and then use the stamp to set however many pins as 0's or 1's but should it be that hard to do with python. ...
    (comp.lang.python)
  • Re: Sensors and PocketPC
    ... pulses will be, but any high-rate (say, in excess of 100 pps, perhaps?), is ... purpose-built or a microcontroller (there are lots to choose ... to your PPC to display results could be done using a serial port on each ... device (assuming your PPC has that capability, ...
    (microsoft.public.pocketpc.developer)
  • bootloader in C
    ... The microcontroller gets the data over the serial port. ... Here's my code to configure the serial port under linux (I'm working on Suse ... while(read(sfd, &cbuf, 1)>0) { ... windows that works fine and I spied on its ...
    (comp.arch.embedded)