bonjour .
encore moi! ![]()
je viens d'essaye de suivre un tuto en anglaishttp://jhaskellsblog.blogspot.fr/2011/05/serial-comm-fundamentals-on-arduino.html pour capturer une trame complète c'est à dire:
on regarde pour un starchar et un endchar .
voici le code:
//buffer size for NMEA compliant GPS string
#define DATABUFFERSIZE 1024
char dataBuffer[DATABUFFERSIZE+1]; //Add 1 for NULL terminator
byte dataBufferIndex = 0;
void setup(){
Serial.begin(57600);
Serial2.begin(57600);
Serial.print("wait data on com2");
}
//******************************************//
boolean getSerialString(){
char startChar = '
le
boolean getSerialString(){
ça se place bien après le void setup()? c'est un peut comme une "sorte de macro" , non?; // or '!', or whatever your start character is
char endChar = '\x1a';
boolean storeString = false; //This will be our flag to put the data in our buffer
static byte dataBufferIndex = 0;
while(Serial2.available()>0)
{
char incomingbyte = Serial2.read();
Serial.print(incomingbyte);// teste
if(incomingbyte==startChar)
{
dataBufferIndex = 0; //Initialize our dataBufferIndex variable
storeString = true;
}
if(storeString)
{
//Let's check our index here, and abort if we're outside our buffer size
//We use our define here so our buffer size can be easily modified
if(dataBufferIndex==DATABUFFERSIZE)
{
//Oops, our index is pointing to an array element outside our buffer.
dataBufferIndex = 0;
break;
}
if(incomingbyte==endChar)
{
dataBuffer[dataBufferIndex] = 0; //null terminate the C string
//Our data string is complete. return true
return true;
}
else{
dataBuffer[dataBufferIndex++] = incomingbyte;
dataBuffer[dataBufferIndex] = 0; //null terminate the C string
}}
else{
}}
//We've read in all the available Serial data, and don't have a valid string yet, so return false
return false;
}
//************************/////
void loop(){
if(getSerialString()){
//String available for parsing. Parse it here
Serial.print(dataBuffer);
}
}
le
> boolean getSerialString(){
ça se place bien après le void setup()? c'est un peut comme une "sorte de macro" , non?