Talking to device over Serial: Write works, Read doesn't
I'm trying to talk to a device over a USB serial device (/dev/ttyUSB0). I can send commands to it with write(), but I'm having problems with read().
When I set VMIN and VTIME, read fails with "Resource Temporarily Unavailable". Otherwise, it "succeeds" with 0 Bytes returned.
I have configured the serial device as such:
Is this sufficient to read() input? Someone suggested I use poll(), but I haven't tried it yet.
int fd, ret;
struct termios options;
/*fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);*/
fd = open(device, O_RDWR | O_NOCTTY);
options.c_cflag |= (CREAD | CLOCAL);
options.c_cflag &= ~CSIZE;
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
options.c_cflag |= CS8;
options.c_oflag &= ~OPOST;
options.c_iflag &= ~(IXON | IXOFF | IXANY);
options.c_iflag |= (IGNPAR);
options.c_cc[VMIN] = 0;
options.c_cc[VTIME] = 1;
ret = tcsetattr(fd, TCSANOW, &options);