Dear all:
I am trying to comunicate Arduino Mega with Scientific Linux 6.0, using termios structure for that. The main idea is to have a set of command that arduino recognize and respond with a Serial.println(ACK) after command. In the C++ code, the program wait until ACK to continue. The code in C++ read 1 character at time until reach the character "\n". Unfortunately, when I run Arduino software I cannot type in the console.
In Arduino I have the following code that recognize commands:
void loop(){
char comm;
if ( Serial.available() > 0){
comm= Serial.read();
instruccion += comm;
received = true;
delay(10);
}else{
received = false;
}
if (!received && (instruccion.length()>0)){ ...
In the PC, after following some advise from several places on internet a get this flags for termios structure:
c_cflag = ~(PARENB | CSTOPB | CSIZE | CRTSCTS) | CS8 | CREAD | CLOCAL;
c_iflag = ~(IXON | IXOFF | IXANY);
c_lflag = ~(ICANON | ECHO | ECHOE | ISIG);
c_oflag = ~OPOST;
c_cc[VMIN] = 0;
c_cc[VTIME] = 0;
This two set of code strutures the core of the application. I have tried so many times this and sometime work and I don't know why, sometimes doesn't work. After force some commands I discover that when I have other console with the command:tail -f /dev/ttyUSB0
reading the same serial port, my code works so fine.
In order to bring reliability to my software I need to avoid the use of the second console. If there are an idea of what is happened I will appreciate very much.