I am running Ubuntu 9.10 and it seems to be having problems with termios. So I can start minicomputing the serial port to 57600 Baud, 8N1, without controlling the flow of hardware or software, and it works great. I dial @ 17 5 and my device answers. When I try to configure my serial port in my C ++ code, I get no response. I know that the software communicates with the port because the LED turns on.
Here is my main one:
int main(void)
{
int fd;
fd = open("/dev/keyspan1", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
perror("open_port: Unable to open /dev/ttyS0 - ");
}
else
fcntl(fd, F_SETFL, 0);
struct termios options;
tcgetattr(fd, &options);
cfsetispeed(&options, B57600);
cfsetospeed(&options, B57600);
options.c_cflag |= (CLOCAL | CREAD);
tcsetattr(fd, TCSANOW, &options);
int n;
n = write(fd, "@17 5 \r", 7);
if (n < 0)
fputs("write() of 8 bytes failed!\n", stderr);
char buff[20];
sleep(1);
n = read(fd, buff, 10);
printf("Returned = %d\n", n);
close(fd);
return(0);
}
Any suggestions would be appreciated. Thank.
source
share