Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

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)
 

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

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top