Hey guys,
I'm trying to make a C++ (Linux) application which communicates with my Arduino UNO. Problem is, I cannot for the life of me understand how to configure it "properly".
The configuration I want, is essentially the excact same thing as the Arduino IDE sets when using the Serial Monitor.
This is my function which opens the connection with my Arduino.
std::cout << "Opening device " << port << ": ";
/* Open the file descriptor in non-blocking mode */
device = open(port.c_str(), O_RDWR | O_NOCTTY | O_NDELAY);
if (device == -1) {
std::cerr << "failed" << std::endl;
return;
} else
std::cout << "connected" << std::endl;
/* Set up the control structure */
struct termios options;
/* Get currently set options for the tty */
tcgetattr(device, &options);
/* Set custom options */
/* 9600 baud */
cfsetispeed(&options, B9600);
cfsetospeed(&options, B9600);
// /* 8 bits, no parity, no stop bits */
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
//
// // Ignore break
// options.c_cflag |= IGNBRK;
//
// // Do not map CR to NL on input
// options.c_cflag &= ~INLCR;
//
// //
// options.c_cflag &= ~IMAXBEL;
//
// /* no hardware flow control */
// options.c_cflag &= ~CRTSCTS;
// /* enable receiver, ignore status lines */
// options.c_cflag |= CREAD | CLOCAL;
// /* disable input/output flow control, disable restart chars */
// options.c_iflag &= ~(IXON | IXOFF | IXANY);
// /* disable canonical input, disable echo,
// disable visually erase chars,
// disable terminal-generated signals */
// options.c_iflag &= ~(ICANON | ECHO | ECHOE | ISIG);
// /* disable output processing */
// options.c_oflag &= ~OPOST;
//
// /* no minimum time to wait before read returns */
// options.c_cc[VTIME] = 0;
/* commit the options */
tcsetattr(device, TCSANOW, &options);
std::cout << "Waiting 3 seconds for serial device ..." << std::endl;
usleep(3000 * 1000);
/* Flush anything already in the serial buffer */
tcflush(device, TCIFLUSH);
Can somebody guide me towards which settings I need to communicate with the Arduino, the same way the Arduino IDE does?