Последовательный порт Arduino нужно распечатать, чтобы прочитать - PullRequest
0 голосов
/ 22 июня 2019

Мне нужно использовать метод Serial.println(), чтобы правильно прочитать последовательный буфер.Без Serial.println() он не читает его.

Получен кадр с синхронизацией byte, byte, который является адресом отправителя, byte, который является адресом назначения, иданные byte

void client(){

  String string, ax,aux;
  char ax1,ax2,ax3,ax4;
  string="";
  ax="o1"; //the character is for frame synchronization and 1 is the client's address
  aux="";
  while (Serial.available() > 0) {
    char c= Serial.read();
    string=string+c;
    Serial.println(c); //without this line the code does not work
  }

  aux=string;   
  ax1=string[0]; //sync byte
  string="";;
  string=aux;
  ax2=string[1]; //sender address byte
  string="";;
  string=aux;
  ax3=string[2];// destination address byte
  string="";;
  string=aux;
  ax4=string[3]; //data byte
  string="";;
  string=aux;
  Serial.println(string); //without this line the code does not work

              if (ax1==ax[0] && ax3==ax[1] && ax4=='1'){
                digitalWrite(A0,HIGH);
              }
               if (ax1==ax[0] && ax3==ax[1] && ax4=='0'){
                digitalWrite(A0,LOW);
              }
}
...