avec thread

Dependencies:   mbed

Fork of T2_STM32 by Atechsys

Serial.h

Committer:
ketingue
Date:
2018-01-14
Revision:
4:b01a3ce6ef01
Parent:
2:ab0ccf9bb38c

File content as of revision 4:b01a3ce6ef01:

#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