Warum nicht?
Ich werf mal als Idee was rein - reiner Pseudocode und nur um mal nen Gedankengang zu zeigen ![]()
const byte numChars = 32;
char receivedChars[numChars];
void setup()
{
Serial.begin(9600);
Serial3.begin(9600);
Serial3.setTimeout(10);
}
void loop()
{
// we're sending two commands to the servo via RS232
// Command: "!PIA\r" Servo response: "#19532150\r"
// Command: "!GS1\r" Servo response: "#R\r"
bool myBool = subServoReceive();
if (myBool == false)
{
subServoSend("!PIA");
Serial.println("Main loop: PIA done");
}
myBool = subServoReceive();
if (myBool == false)
{
subServoSend("!GS1");
Serial.println("Main loop: GS1 done");
}
}
bool subServoReceive()
{
static unsigned long startMillis = 0;
static bool inProgress = false;
static byte ndx = 0;
const char startMarker = '#';
const char endMarker = '\r';
char rc = '\0';
if (Serial3.available() > 0)
{
rc = Serial3.read();
}
if (rc == startMarker) // feststellen das es anfängt
{
ndx = 0;
memset(receivedChars, '\0', sizeof(receivedChars));
inProgress = true;
startMillis = millis();
}
if (inProgress == true && // wenn gesetzt
rc != startMarker) // und nicht der erste Marker
{
if (millis() - startMillis > 200) // erste Abbruchbedingung
{
inProgress == false;
Serial.println(F("TimeOut"));
return inProgress;
}
if (rc == endMarker) // zweite Abbuchfunktion
{
receivedChars[ndx] = '\0';
Serial.println(receivedChars);
inProgress = false;
}
else // Zeichen einlesen
{
receivedChars[ndx] = rc;
ndx++;
}
}
return inProgress;
}
void subServoSend(String command)
{
Serial3.print(command + '\r');
}
Danke - der war wirklich aufregend - zumal die Zuordnung der Pegel nicht stimmte ![]()