Skip to content

Instantly share code, notes, and snippets.

@pgaultier
Last active July 19, 2023 10:25
Show Gist options
  • Save pgaultier/b870578515a18becc39ce4501a751574 to your computer and use it in GitHub Desktop.
Save pgaultier/b870578515a18becc39ce4501a751574 to your computer and use it in GitHub Desktop.
Cheap RFID Read/Writer EM4305 T5567

Cheap RFID (125kHz) Reader/Writer from China

The reader is labeled :

  • on the front : RF ID Reader
  • on the back : D302 EM Card Encoder MADE IN CHINA

This reader / writer should Work with cards : EM4305 and T5567.

Drivers

After some quick research it appears the reader has a CH341 USB / Serial Chip. To make it work under OSX the driver must be installed.

Check

Once driver are installed, the RFID reader can be accessed with the following parameters :

  • Speed : 4800 bauds
  • Bits : 8
  • Parity : none
  • Stop : 1

Initialline states

  • DTR Off
  • RTS Off

Take care to wait some time ~ 500ms after opening serial port before sending any command. If the command is sent too early the reader discard it.

Protocol

After some quick investigations, it appears the commands look like the following scheme :

02 | NN NN | LL | PP .. PP | CC | 03
  • 02 : start byte
  • NN NN : command to execute
  • LL : payload length
  • PP .. PP : payload if needed
  • CC : checksum 02 ^ NN ^ NN ^ LL ^ PP ... ^ PP = CC (all bytes including the start one are xor'ed to compute the checksum)
  • 03 : stop byte

Commands

CMD 01 00 : HELLO / ACK

-> 02 01 00 00 03 03 [send hello to the reader]
<- 02 01 00 00 03 03 [recv acknowledge from the reader]

CMD 01 a4 : READ

-> 02 01 a4 0b 00 00 00 00 00 00 00 00 00 00 00 ac 03 [send read card]
<- 02 01 00 05 XX XX XX XX XX CC O3 [recv card number XX XX XX XX XX with checksum CC]

CMD 01 a5 : WRITE

WP can be 0x00 (Read / Write) or 0xff (Read only). Once Write protect byte has been set, the card cannot be updated anymore

-> 02 01 a5 0b 00 00 00 00 00 WP XX XX XX XX XX CC 03 [send write card number XX XX XX XX XX with checksum CC]
<- 02 01 00 00 03 03 [recv acknowledge from the reader]

// TODO : check errors codes, ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment