![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
avec thread
Fork of T2_STM32 by
Diff: Serial.h
- Revision:
- 2:ab0ccf9bb38c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Serial.h Sun Jan 14 15:50:49 2018 +0000 @@ -0,0 +1,47 @@ +#ifndef Serial_h +#define Serial_h + +void FlushIncomingSerial(){ +///////////////////////////////// Vider le buffer de réception //////////////////////// + while(Serial.available()) + Serial.read(); +} + +void ReadSerial(){ +///////////////////////////////// Attente et lecture de trame ////////////////////////////// + CurrentMillis = millis(); + while (!Serial.available()) + { + if((millis() - CurrentMillis) >= 500){ + break; + } + } + + ActualAdress = 0; + if (Serial.read() == Start_Command) + { + for(;;) + { + RxdBuffer[ActualAdress] = Serial.read(); + if (RxdBuffer[ActualAdress] == 255) + ActualAdress--; + if (RxdBuffer[ActualAdress] == Start_Command) + break; + else + { + ActualAdress++; + } + } + } +} + + +void SendSerial(){ +///////////////////////////////// Envoi de trame dans les 2 ports série ////////////////////////////// + Serial.print(Start_Command); + Serial.print(Address); + Serial.print(Command); + Serial.println(State); +} + +#endif \ No newline at end of file