puzzle by serial

puzzle by serial

[code] #include #include #include #include #include #include #include #include

#define FALSE -1 #define TRUE 0

int OpenDev(char *Dev) { int fd = open( Dev, O_RDWR ); //| O_NOCTTY | O_NDELAY if (-1 == fd) { perror("Can't Open Serial Port"); return -1; } else return fd; } int main(int argc, char **argv) { int fd, i = 10, attrfd; int nwrite; static struct termios terattr; char buff[512] = "hello world"; char *dev = "/dev/ttyS0"; fd = OpenDev(dev); printf("fd == %d\n", fd); if(-1 == fd) return -1; attrfd = tcgetattr(fd, &terattr); if(-1 == attrfd) perror("attrfd"); printf("iflag == %d\n", terattr.c_iflag); printf("oflag == %d\n", terattr.c_oflag); printf("cflag == %d\n", terattr.c_cflag); printf("lflag == %d\n", terattr.c_lflag);

} [/code]

compile and run the program, it will put out:

 fd == 3 attrfd: Input/output error iflag == 134513255 oflag == 134519244 cflag == 10906172 lflag == 12074996 

i have a problem that:

1) it can open /dev/ttyS0, why tcgetattr return error, the reference is that Input/output error. but i dont konw why get the error, is that there is something wrong with the serial driver? 2) tcgetattr return error, why it can get terattr, and it seem them wrong(but im not sure it) 3)
Reply to
freegnu
Loading thread data ...

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.