problem with read from file descriptor

Status
Not open for further replies.
I would write the initialisation sequence like this:

Code:
Serial::Serial(char *device_name)
{
  struct termios options;

  fd = open(device_name, O_RDWR | O_NOCTTY | O_NDELAY);
  if (fd < 0)
    {
      exit(1);
    }

  fcntl(fd, F_SETFL, 0);

  // Get the current options for the port...
  tcgetattr(fd, &options);

  // Set the baud rates to 9600...
  cfsetispeed(&options, B9600);
  cfsetospeed(&options, B9600);

  // Adjust settings to required...
  options.c_cflag |= ( CLOCAL | CREAD );
  // No parity (8N1):
  options.c_cflag &= ~PARENB;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;

  options.c_lflag &= ~( ICANON | ECHO | ECHOE | ISIG );
  options.c_oflag &= ~OPOST;
  options.c_cc[VMIN] = 0;
  options.c_cc[VTIME] = 50;

  // Set the new options for the port...
  tcsetattr(fd, TCSANOW, &options);
}


and it's
while ((nbytes = read(fd, &response[writePos], BUFFERSIZE - writePos)) > 0)
 

does it work now?
 

Yepp! And I needed to add tcflush too, cause some garbage from prior starts where on the line.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…