Dies ist ein Beispiel, dass ich vor einigen Monaten gearbeitet habe. Ich denke es funktioniert gut. Das Programm setzt die Antenne zurück, setzt die Arbeitsantenne und arbeitet dann als Echtzeitinventar. Wenn Sie etwas über Arduino wissen, können Sie den Code lesen. (Es hat einige spanische Kommentare, weil ich in Mexiko bin)
#include <SPI.h> #include <SD.h> File myFile; byte reset_Message[] = ; byte set_WorkingAntenna[] = ; byte real_TimeInventory[] = ; int cont = 0; int contSD = 1; byte tag_ID[21]; String tag_IDInt=""; unsigned long previousMillis = 0; // will store last time LED was updated // constants won't change : const long interval = 100; // interval at which to blink (milliseconds) boolean found = false; void setup() { // initialize both serial ports: Serial.begin(115200); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } Serial2.begin(115200); Serial.print("Inicializando Memoria SD..."); if (!SD.begin(4)) { Serial.println("Inicializacion Fallida!"); return; } Serial.println("Inicializacion Correcta."); delay(100); Serial2.write(reset_Message, sizeof(reset_Message)); delay(500); Serial2.write(set_WorkingAntenna, sizeof(set_WorkingAntenna)); delay(50); Serial2.write(real_TimeInventory, sizeof(real_TimeInventory)); tag_IDInt.reserve(200); } void loop() { unsigned long currentMillis = millis(); if (currentMillis - previousMillis >= interval) { previousMillis = currentMillis; Serial2.write(set_WorkingAntenna, sizeof(set_WorkingAntenna)); delay(50); Serial2.write(real_TimeInventory, sizeof(real_TimeInventory)); } // read from port 2, send to port 0: if (Serial2.available()) { byte inByte = (byte)Serial2.read(); tag_ID [cont] = inByte; //Serial.write(inByte); cont++; if (cont == 6 && tag_ID[3] == 116){ cont = 0;} if (cont == 12 && tag_ID[4] == 0 ){ cont = 0;} if (cont == 21){ for (int i=7; i<19; i++){ tag_IDInt += String(tag_ID[i],HEX); //Serial.print(tag_ID[i], HEX); //Serial.print(" "); } tag_IDInt += (char)'\r'; Serial.print("Tu ID es: "); Serial.print(tag_IDInt); if (lookForID(tag_IDInt)){ Serial.println(", Acceso Permitido"); }else{ Serial.println(", Acceso Denegado"); } found = false; tag_IDInt = ""; cont = 0; } } } boolean lookForID(String read_ID){ // open the file. note that only one file can be open at a time, // so you have to close this one before opening another. myFile = SD.open("TAGIDS.csv", FILE_WRITE); // re-open the file for reading: myFile = SD.open("TAGIDS.csv"); if (myFile) { // read from the file until there's nothing else in it: while (myFile.available() && !found) { String line = myFile.readStringUntil('\n'); if (line == read_ID){ //Serial.print(" Found in Line "); //Serial.print(contSD); found = true; contSD = 1; return true; } else contSD++; } // close the file: myFile.close(); if(!found){ contSD = 1; return false; } } else { // if the file didn't open, print an error: Serial.println("Error Abriendo TAGIDS.csv"); } }