RFID WL-134A模块Arduino解码异常:标签ID计算错误排查
动物标签阅读器Arduino解码标签ID错误排查求助
问题概述
- 已将动物标签阅读器连接到Arduino模块,借助用户red_car的代码成功读取数据,系统校验和通过、国家码输出正确,数据结构与手册及red_car示例匹配,但标签ID解码始终错误
- 使用手册示例数据测试:
- 示例十六进制数据:
02 31 37 31 41 39 32 35 33 41 33 34 38 33 30 30 31 30 30 30 30 30 30 30 30 30 30 07 f8 03 - 转换为ASCII后:
171A9253A34830010000000000 - 手册定义:标签ID为第1-10字节,国家码为第11-14字节,预期结果为国家码900,标签ID250000023921
- 示例十六进制数据:
测试代码
byte buffer[30] = {0x02, 0x31, 0x37, 0x31, 0x41, 0x39, 0x32, 0x35, 0x33, 0x41, 0x33, 0x34, 0x38, 0x33, 0x30, 0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x07, 0xf8, 0x03}; byte b; uint8_t idx; boolean started = false; byte XOR; byte inverted; uint32_t value; void setup() { // Initialize serial communication at 9600 baud Serial.begin(9600); delay(1000); Serial.println("start:"); } void loop() { // Print the contents of the buffer to Serial Monitor for verification for (int i = 0; i < sizeof(buffer); i++) { Serial.print(buffer[i], HEX); Serial.print(" "); } Serial.println(); // Check we received the message ok. XOR checksum on bytes 01-26 should match byte 27. XOR = buffer[1]; for (int x = 2; x <= 26; x++) { XOR ^= buffer[x]; } Serial.print("Calculated checksum: "); Serial.print(XOR, HEX); if (XOR == buffer[27]) Serial.println(" (Correct)"); else Serial.println(" (Error)"); // Check the inverted XOR checksum inverted = ~XOR; Serial.print("Inverted checksum: "); Serial.print(inverted, HEX); if (inverted == buffer[28]) Serial.println(" (Correct)"); else Serial.println(" (Error)"); // Extract the card number from bytes 01 (LSB) - 10 (MSB). value = 0; for (int x = 10; x >= 1; x--) { if(buffer[x] <= '9') value = (value<<4) + buffer[x] - '0'; else value = (value<<4) + buffer[x] - '7'; } Serial.print("Card number: "); Serial.println(value); // Extract the country number from bytes 11 (LSB) - 14 (MSB). value = 0; for (int x = 14; x >= 11; x--) { if(buffer[x] <= '9') value = (value<<4) + buffer[x] - '0'; else value = (value<<4) + buffer[x] - '7'; } Serial.print("Country number: "); Serial.println(value); // Extract the Data Block from byte 15. Serial.print("Data block: "); Serial.println(buffer[15] - '0'); // Extract the Animal Flag from byte 16. Serial.print("Animal flag: "); Serial.println(buffer[16] - '0'); Serial.println("\r"); delay(100000); }
实际输出结果
2 31 37 31 41 39 32 35 33 41 33 34 38 33 30 30 31 30 30 30 30 30 30 30 30 30 30 7 F8 3 Calculated checksum: 7 (Correct) Inverted checksum: F8 (Correct) Card number: 891920753 Country number: 900 Data block: 0 Animal flag: 1
核心诉求
当前校验和正确,但标签ID与预期结果不符,请求协助排查解码逻辑问题。
内容的提问来源于stack exchange,提问作者RyanMe321
相关产品推荐
相关产品推荐

