Как отправить, затем получить и сохранить ответ правильно? - PullRequest
0 голосов
/ 16 января 2020

Я учусь, как люди из форумов, подобных этому, руководили мной.

Я только что узнал, как отправить запрос на датчик с помощью последовательной связи, я использовал следующий код для запроса датчика. Ожидаемый запрос это:

  digitalWrite(mdDeRe, HIGH);  //tells the sensor serial data is coming.

Serial.write(17);
  Serial.write(3);
  Serial.write(0);    
  Serial.write(84); 
  Serial.write(0);
  Serial.write(4); 
  Serial.write(7);  
  Serial.write(73);  
  Serial.flush();
  delayMicroseconds(120);
  digitalWrite(mdDeRe,LOW);  

  ///sensor response is: 11 03 08 00 64 00 3E 00 0D 00 55 9C E8
  /// I would like to store the response in an array.

   if (Serial.available()) {
    for (int response=0; response<12; response ++){
    incomingByte[response] = Serial.read();
      }
    }
  }
/// Will this work?
/// Is there a more efficient or proper way to do the same?
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...