Antharax
Full Member level 4
I would write the initialisation sequence like this:
and it's
while ((nbytes = read(fd, &response[writePos], BUFFERSIZE - writePos)) > 0)
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)