Skip to contentSkip to conversation

serial port canonical mode weirdness?

DISCUSSION David L 1 participant 1 message Apr 1, 2004

lore
Share & tools
lore

David L

author
#0 lore raw
Quoted 7 lines
Quoted 1 line

When I configure a serial port for canonical mode (newtio.c_lflag =

ICANON),

Quoted 1 line

I get behavior that isn't what I'd expect.

Can you supply the test program you're using on the receive end?

--

#include <termios.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>

#define BAUDRATE B38400
#define SERIALDEVICE "/dev/ttyS0"

int main()
{
int fd, res;
struct termios newtio;
unsigned char buf[10000];

fd = open(SERIALDEVICE, O_RDWR);
if (fd <0) {perror(SERIALDEVICE); return -1; }

bzero(&newtio, sizeof(newtio));

newtio.c_cflag = BAUDRATE | CS8 | CLOCAL | CREAD; newtio.c_iflag = IGNPAR;
newtio.c_lflag = ICANON;

newtio.c_cc[VEOL] = 0x0D;

tcsetattr(fd,TCSANOW,&newtio);

while (1) {
res = read(fd,buf,9000);
printf("%d bytes read (%d)\n", res, errno);
printf("%02X %02X %02X %02X %02X %02X\n",
buf[0],buf[1],buf[2],buf[3],buf[4],buf[5]);
}
}

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar � get it now! http://toolbar.msn.com/go/onm00200415ave/direct/01/