0

I am using the following code now, and I am wondering where it is wrong.

struct termios options;
int fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);
fcntl(fd, F_SETFL, 0);
tcgetattr(fd, &options);
cfsetispeed(&options, B9600);
tcsetattr(fd, TCSANOW, &options);
Cacheing
  • 3,431
  • 20
  • 46
  • 65

1 Answers1

0

Can you try below code and see if it helps?

int open_port(void)
{
    int fd;

fd = open("/dev/ttyUSB0", 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, B9600);
cfsetospeed(&options, B9600);

tcsetattr(fd, TCSANOW, &options);

return (fd);
}
Travis G
  • 1,592
  • 1
  • 13
  • 18