Hallo Zusammen,
ich hatet mal dank eurer Hilfe vor Jahren eine Programm, welches engehende seriele Commands in eine Schaltung von LED´s umwandelte. Das war für mich auch völlig okay. Doch jetzt habe ich ein anderes Problem. Ich möchte nun etwas auswerten, was keinen Stop-Bit besitzt. Leider komme ich hier bei meiner aktuellen Vorlage nicht mehr weiter. Die Daten sind immer in gleicher Länge. Es geht rein um seriell zu Digital Out. Kann mir hier jemand nochmal freundlicher Weise helfen?
01 0F 00 00 00 04 01 01 FF 56 -> Ausgang 3
01 0F 00 00 00 04 01 02 BF 57 -> Ausgang 4
Ich würde mich freuen, wenn mir hier jemand helfen könnte.
Hier noch ein kleiner Auszug meines alten Programms für den Mega:
int out1 = 22;
int out2 = 24;
int out3 = 26;
const byte messages[][13] PROGMEM =
{
{ 0x30, 0x0A, 0x20, 0x0A, 0x25, 0x0A, 0x2E, 0x0A, 0x20, 0x37, 0x0A, 0x21, 0x37 },
{ 0x30, 0x0A, 0x20, 0x0A, 0x25, 0x0A, 0x2E, 0x0A, 0x20, 0x37, 0x0A, 0x20, 0x24 },
{ 0x30, 0x0A, 0x20, 0x0A, 0x25, 0x0A, 0x2E, 0x0A, 0x20, 0x38, 0x0A, 0x23, 0x91 },
};
const int MESSAGE_LENGTH = sizeof(messages[0]) / sizeof(messages[0][0]);
const int MESSAGE_COUNT = sizeof(messages) / MESSAGE_LENGTH;
const byte START_BYTE = 0x02 ;
const byte END_BYTE = 0x03;
byte inputData[MESSAGE_LENGTH];
void setup() {
Serial.begin(19200);
pinMode(out1,OUTPUT);
pinMode(out2,OUTPUT);
pinMode(out3,OUTPUT);
}
void loop() {
if (readSerial(Serial) == true)
{
Serial.print(F("read: "));
for (unsigned int i = 0; i < MESSAGE_LENGTH; i++)
{
Serial.print(inputData[i], HEX); Serial.print(',');
}
Serial.print(F(" --- "));
bool match = false;
for (unsigned int i = 0; i < MESSAGE_COUNT; i++)
{
if (memcmp_P(inputData, messages[i], MESSAGE_LENGTH) == 0)
{
Serial.print(F("match found: ")); Serial.println(i);
if ((i) == 0)
{digitalWrite(out1, HIGH);}
if ((i) == 1)
{digitalWrite(out1, LOW);}
if ((i) == 2)
{digitalWrite(out2, HIGH);}
match = true;
break;
}
}
if (!match)
Serial.println(F("no match"));
}
}
bool readSerial(Stream& stream)
{
static byte index;
static bool start;
while (stream.available())
{
byte data = stream.read();
if (!start && data == START_BYTE)
{
start = true;
memset(inputData, 0, sizeof(inputData));
}
else if (start && data == END_BYTE)
{
index = 0;
start = false;
return true;
}
else if (start && index < MESSAGE_LENGTH)
{
inputData[index++] = data;
}
}
return false;
}