Paramètre struct termios pour la communication série avec Arduino

sur un logiciel basé sur unix, qui doit envoyer un nombre entre 0 et 179 à arduino et arduino appliquer ce nombre comme un angle à un servomoteur, mais je ne sais pas quels parameters je dois changer dans la structure terminale pour permettre la série la communication.

c’est le code c ++:

#include  #include  #include  #include  using namespace std; int main() { unsigned int angle; ofstream arduino; struct termios ttable; //cout<<"test-1"; arduino.open("/dev/tty.usbmodem3a21"); //cout<<"test-2"; if(!arduino) { cout<<"\n\nERR: could not open port\n\n"; } else { if(tcgetattr(arduino,&ttable)<0) { cout<<"\n\nERR: could not get terminal options\n\n"; } else { //there goes the terminal options setting for the output; ttable.c_cflag = -hupcl //to prevent the reset of arduino cfsetospeed(&ttable,9600); if(tcsetattr(arduino,TCSANOW,&ttable)<0) { cout<<"\n\nERR: could not set new terminal options\n\n"; } else { do { cout<>angle; arduino<<angle; }while(angle<=179); arduino.close(); } } } } 

et voici les arduino:

 #include  Servo servo; const int pinServo = 2; unsigned int angle; void setup() { Serial.begin(9600); servo.attach(pinServo); servo.write(0); } void loop() { if(Serial.available()>0) { angle = Serial.read(); if(angle <= 179) { servo.write(angle); } } } 

Alors, aimeriez-vous me dire ce que je dois changer de “ttable”?

quelque chose comme ça pour termios est la meilleure option

 options.c_cflag &= ~CRTSCTS; options.c_cflag |= (CLOCAL | CREAD); options.c_iflag |= (IGNPAR | IGNCR); options.c_iflag &= ~(IXON | IXOFF | IXANY); options.c_oflag &= ~OPOST; options.c_cflag &= ~CSIZE; options.c_cflag |= CS8; options.c_cflag &= ~PARENB; options.c_iflag &= ~INPCK; options.c_iflag &= ~(ICRNL|IGNCR); options.c_cflag &= ~CSTOPB; options.c_iflag |= INPCK; options.c_cc[VTIME] = 0.001; // 1s=10 0.1s=1 * options.c_cc[VMIN] = 0;