I pick up one of these at https://www.alibaba.com/product-detail/UHF-RFID-reader-module-for-arduino_60655915507.html?spm=a2700.7724838.2017115.96.3acb596e0SZTWV
I am using Arduino Mega the reader is on serial2 I can read EPC memory but I am having no luck in reading user memory! Here is the code:
//byte readOnce[] = {0xBB, 0x00, 0x22, 0x00, 0x00, 0x22, 0x7E};
byte readOnce[] = {0xBB, 0x00, 0x39, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x4D, 0x7E};
byte container[1024]; //A buff container to cnotain received bytes
bool isDoorOpen = false;
int switchPin = 8;//The pin used for door state input.
//byte tt[] ={0xBB,0x02,0x22,0x00,0x02,0x12,0x34,0x99,0x88,0x56,0x41,0xEF,0x7E};
//byte tad[] = {0xBB, 0x02,0x22,0x00,0x11,0xC9,0x34,0x00,0x30,0x75,0x1F,0xEB,0x70,0x5C,0x59,0x04,0xE3,0xD5,0x0D,0x70,0x3A,0x76,0xEF,0x7E};
void setup() {
Serial.begin(115200);
Serial2.begin(115200);
pinMode(switchPin, INPUT);
Serial2.setTimeout(2000);
onDoorOpen();
}
void loop() {
int doorState = digitalRead(switchPin);
if (doorState == HIGH) {
onDoorOpen();
}
}
void onDoorOpen() {
Serial2.write(readOnce, sizeof(readOnce));
delay(100);
int len = Serial2.available();
if (len > 0) {
Serial2.readBytes(container, len);
frameParse(container, len);
}
}
void extractEPC(byte frm[], int le) {
if (frm[1] == 0x02 && frm[2] == 0x22) {
int frmLen = le;
int epcLen = frmLen - 8 - 4;
byte epc[epcLen];
int ind = 0;
Serial.write(42); Serial.write(42); Serial.write(42);
for (int i = 8; i < epcLen + 8; i++) {
epc[ind++] = frm[i];
// Serial.write(frm[i]);
Serial.print(frm[i]); //GET NUMBER HERE!!!!!!!!!!!!!!
Serial.write(32);
}
Serial.write(10);
}
}
void frameParse(byte dataCom[], int lent) {
//Serial.write(98);
bool frameBeginFlag = false;
bool frameEndFlag = true;
long frameLength; //实际接收到的数据长度
long strNum; //实际接收到的帧个数
byte strBuff[4096];
int n = lent;
for (int j = 0; j < n; j++)
{
if (frameBeginFlag)
{
strBuff[strNum] = dataCom[j];
if (strNum == 4)
{
frameLength = 256 * strBuff[3] + strBuff[4];
if (frameLength > 3072)
{
frameBeginFlag = false;
continue;
}
}
else if (strNum == frameLength + 6 && strBuff[strNum] == 0x7E)
{
int checksum = 0;
for (int i = 1; i < strNum - 1; i++)
{
checksum += strBuff[i];
}
checksum = checksum % 256;
if (checksum != strBuff[strNum - 1])
{
// Console.WriteLine("ERROR FRAME, checksum is not right!");
frameBeginFlag = false;
frameEndFlag = true;
continue;
}
frameBeginFlag = false;
frameEndFlag = true;
//Send out
byte packet[strNum + 1];
for (int i = 0; i <= strNum; i++)
{
packet[i] = strBuff[i];
}
extractEPC(packet, strNum + 1);
}
else if (strNum == frameLength + 6 && strBuff[strNum] != 0x7E)
{
// Console.WriteLine("ERROR FRAME, cannot get FRAME_END when extends frameLength");
frameBeginFlag = false;
frameEndFlag = true;
continue;
}
strNum++;
}
else if (dataCom[j] == 0xBB && frameBeginFlag != true)
{
strNum = 0;
strBuff[strNum] = dataCom[j];
frameBeginFlag = true;
frameEndFlag = false;
strNum = 1;
}
}
}
The data sheet is attached.
I am trying to read from the User memory so I tried to change:
byte readOnce[] = {0xBB, 0x00, 0x22, 0x00, 0x00, 0x22, 0x7E};
to: byte readOnce[] = {0xBB, 0x00, 0x39, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x4D, 0x7E};
it does read from the user data but not all of it. I would be grateful for any help as to why.
Thanks, Chris