puzzle by serial



puzzle by serial

[code]
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <errno.h>

#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:
[code]
fd == 3
attrfd: Input/output error
iflag == 134513255
oflag == 134519244
cflag == 10906172
lflag == 12074996
[/code]

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)


.



Relevant Pages

  • Re: puzzle by serial
    ... int main ... attrfd = tcgetattr; ... attrfd: Input/output error ... going wrong in the interaction between the serial port driver and the ...
    (comp.os.linux.development.system)
  • puzzle by serial
    ... int main ... attrfd = tcgetattr; ... attrfd: Input/output error ... tcgetattr return error, why it can get terattr, and it seem them ...
    (comp.os.linux.hardware)
  • puzzle by serial
    ... int main ... attrfd = tcgetattr; ... attrfd: Input/output error ... tcgetattr return error, why it can get terattr, and it seem them ...
    (comp.os.linux.development.system)
  • [PATCH 4/4] UML - Work around host tcsetattr bug
    ... Under the conditions that UML uses it, tcgetattr is guaranteed to ... int generic_console_write ... int err; ...
    (Linux-Kernel)