YR8001 RFID阅读器


0

我正在使用YR8001 RFID阅读器开展无源RFID系统项目。我是初学者,对此不太了解。在阅读了各种文章和博客后,我了解到大多数读者都允许用户使用RS232(YR 8001也可以)。 RS232和TTL工作在两个不同的电压水平,如果有人想通过微控制器将读卡器连接到计算机,你需要一个RS232 -TTL转换器(我使用MAX232)。

我订购零件的网站为产品提供了一个软件,可以帮助您与阅读器进行交互,但它没有提供任何选项将输出发送到微控制器。我需要读取RFID标签,如果是,它应该输出到微控制器。因此,我正在尝试使用Arduino制作自己的程序。

要检查我的阅读器是否已连接到我的PC,我使用的是coolTerm(串行通信软件)。虽然我可以通过点击coolTerm中的连接按钮成功连接它,但我不确定它是否实际连接,因为我在Serial Monitor屏幕上看不到任何内容,并且根据我的理解,阅读各种博客后,读者应该发送一些通知说明您的计算机已连接到阅读器,他们现在都可以进行通信。

我应该做的任何线索对我都有很大的帮助,因为我被困住了,我现在想不出怎么办。

Answers:


0

这是我几个月前工作的一个例子。我认为它运作正常。程序重置天线,然后设置工作天线,然后作为实时库存。如果您对arduino有所了解,可以阅读代码。 (它有一些西班牙语评论,因为我在墨西哥)

#include <SPI.h>
#include <SD.h>

File myFile;

byte reset_Message[] = {0xA0, 0x03, 0x01, 0x70, 0xEC };
byte set_WorkingAntenna[] = {0xA0, 0x04, 0x01, 0x74, 0x00, 0xE7 };
byte real_TimeInventory[] = {0xA0, 0x04, 0x01, 0x89, 0x01, 0xD1 };

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");
  }
} 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.