RFID wrong code received over RS232

Hi everyone,

I need you help in my project. I have an RFID reader made by Chafon, and I try to use this over RS232. I receive every time a wrong code/response. The test TAG have ID like "E2801105200072DA390E0987" and I get this code over RS232 "-411267-411266-411241" with Arduino UNO.

This is my code:

#include <EEPROM.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#define DEBUG
#include <string.h>

int rxdata = 0;
char rxstate = 0;
unsigned char bReadLength = 0;
String strTagID = "";
String LastTag = "000000000000000000000000" ;
String ErrorTag = "1E000000000000000000001E" ;
SoftwareSerial Reader (3, 2); //Original 9, 8
const int IR = 10;
const int TrigerOut = 11;

//----------------------------------------------------------------------------

void setup() {
Serial.begin(9600); //Connect to PC
Reader.begin(9600); //Connect to Reader
Wire.begin(8);
Wire.onRequest(requestEvent);

pinMode(IR, INPUT);
pinMode(TrigerOut, OUTPUT);
digitalWrite(TrigerOut, HIGH);
}

//----------------------------------------------------------------------------

//Check the rev char is Legal tag data
unsigned char CheckIsHexChar(unsigned char bChar)
{
if (bChar >= '0' && bChar <= '9') return 1;
else if (bChar >= 'A' && bChar <= 'F') return 1;
else if (bChar >= 'a' && bChar <= 'f') return 1;
else return 0;
}

//----------------------------------------------------------------------------

void ReadTagCmd() {
if (digitalRead(7) == LOW) {
byte message[] = {0x53, 0x57, 0x00, 0x03, 0xff, 0x41, 0x13};
Reader.write(message, sizeof(message));
Serial.println("Read command sent...");
}
}

//----------------------------------------------------------------------------

void loop() {
ReadTagCmd();

while (Reader.available() > 0)
{
rxdata = (char(Reader.read()));
Serial.print(String(rxdata));
switch (rxstate)
{
case 0: //get head
if (String(rxdata) == ("0x02")) {
rxstate = 1;
strTagID = "";
bReadLength = 0;
}
break;

  case 1:  //Get TagID
    if (String (rxdata) != ("0x03")) //Not End
    {
      if (CheckIsHexChar(rxdata) == 1) //check legal char
      {
        strTagID = strTagID + char (rxdata);
        bReadLength++;
        if (bReadLength == 24) {
          //Serial.println(bReadLength);
          if (LastTag != strTagID) {
            LastTag = strTagID;
            //Serial.println(strTagID);
          } else {
            Serial.print("Current: ");
            Serial.println(strTagID);
          }
        }
      }
      else
      {
        strTagID = "";
        rxstate = 0;
      }
    }
    else
    {
      if ((bReadLength) % 2 == 0) //TagLength(HEX data) is odd
      {
        if (strTagID != "")
        {
          Serial.print("TagID: ");
          Serial.println(String (strTagID));
        }
      }
      else
      {
        Serial.print("Unlegal Data\r\n");
      }
      strTagID = ""; rxstate = 0; bReadLength = 0;
    }
    break;
}
delay(5);

}
delay(300);
}

//----------------------------------------------------------------------------

void requestEvent()
{
char buffer[25];
LastTag.toCharArray(buffer, 25);
Wire.write(buffer);
}

Thanks in advance.

How are you converting the RS232 signals to TTL signals ?

I`m beginner in this domain. I try to use the Arduino Uno Board for this.

Are you saying that you have a device outputting RS232 connected directly to the Uno pins 0 and 1 ?

the reader is connected to pin 3 and 2 on Arduino and I use USB to read on serial monitor

RS232 signal levels are not compatible with the TTL levels of the Arduino

Google Arduino RS232 for details of how to interface the two

you can tell me why this is worked with OEM Arduino Uno board and don't want to work with Arduino Uno China version?

Are you sure that the RFUD reader has an RS232 interface ? Please provide a link to the device

CHAFON 6m small integrated reader uhf rfid USB RS232 WG26 RELAY IP66 built in 6dbi antenna free SDK for car parking management|Control Card Readers| - AliExpress

It certainly looks like RS232 so should not work with a TTL interface

I understand. And what is your proposal? To try with a TTL - RS232 interface?

Yes, or use a reader with a TTL interface

Lot of thanks for your help.

@nickk52000, your topic has been moved to a more suitable location on the forum.

Now your issue is solved, can you spend some time reading How to get the best out of this forum and in future apply what you've read / learned (e.g. the use of code tags).

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.