Book Programming Examples & Libraries
All of the DLLs (Dynamic Link Libraries) for Elektor-RFID-Reader were developed in C#. The Elektor-RFID-Reader can thus be programmed in any .NET language.
The following three examples illustrate the use of the .NET reader libraries in C/C++, Visual Basic.NET and C#. In each example, the card is activated with the ActivateCard() method. If a card can be successfully addressed, the card’s serial number (UID) is output to the Console Window. These three examples show only the possibility that the reader can also be programmed in a language other than C#.
In this chapter you will learn the basic techniques of programming different MIFARE and ISO/IEC 14443 Type A cards. The following topics and types of cards are covered in this chapter:
ISO/IEC 14443-3 Type A card activation (Elektor-RFID-Reader)
Card type identification (Elektor-RFID-Reader)
MIFARE Ultralight card (Elektor-RFID-Reader & PC/SC Reader)
MIFARE Classic card (Elektor-RFID-Reader & PC/SC Reader)
MIFARE Ultralight C card Triple-DES authentication (Elektor-RFID-Reader)
ISO/IEC 14443-4 transmission protocol (T=CL) (Elektor-RFID-Reader )
MIFARE DESFire EV1 card (Elektor-RFID-Reader & PC/SC Reader)
Readers without an Elektor RFID Reader will still benefit from the examples. The principles and programs presented are largely transferable to a regular PC/SC reader (see Section 11.4.3).
Both the Elektor Library and the CsharpPCSC Library implement the IMifareUltraLight as well as the IMifareClassic interfaces. The generic card utility classes presented in this chapter are reader independent.
PC/SC Reader Smart Card Magic.NET Scritp Examples (NEW: 28.8.2013)
Examples Chapter 9.1
Programming the MF RC522 Reader IC
The MF RC522 reader IC is programmed and configured using a total of 48 special function registers (SFRs). A host computer can control the MF RC522 registers via RS-232, I2C or SPI interface. In the Elektor RFID Reader, connection to the P89LPC396 microcontroller is done via I2C.
The RC522.ReadSFR() and RC522.WriteSFR() methods in the Elektor RFID Reader library enable direct access to the MF RC522 registers. In this case, the reader firmware’s function is reduced to that of a special USB-to-I2C converter for controlling the MF RC522 UART.
With the help of these two methods, it is possible to develop and test parts of the reader firmware directly on the PC. This eliminates time-consuming microcontroller programming (flashing). All of the reader IC’s analog parameters can be changed by configuring the corresponding SFR. Tuning the antenna and optimizing the reader’s range requires repeated changing of the MF RC522’s analog parameters, and thus the repeated updating of the corresponding register values. Using the conventional approach, the firmware would have to be updated for every new iteration. It is much more efficient in this case to adjust the register values using a PC program (e.g. a Smart Card Magic.Net script) and then perform the RF measurements. It’s only necessary to load a modified version of the reader firmware into flash memory after successful analog performance optimization.
You can find the Smartcard Magic.NET script examples in the subfolder MFRC522 (see chapter 8 download).
Examples Chapter 9.2
Elektor-RFID-Reader as Access Control System
The Elektor-RFID-Reader is especially suitable to realize of an offline access control system. A gate and door opener can be controlled either directly via the open collector output (T3) or via an additional relay.
The Access Control mode configuration is done using "Access Control Manager", a Windows application developed for the purpose. This application was written in C# using the Elektor-RFID-Reader library. Access Control Manager can easily be extended with further functions. Access Control Manager's window is also integrated into Smart Card Magic.NET.
Example Chapter 9.3
An Electronic ID Card
The operation of contactless smart cards can be demonstrated elegantly by implementing a simple electronic ID card. The following project implements an electronic ID card (without security features) using a MIFARE 4K card. A simple Window Form application was created in C# for personalizing and reading the card data.
Example Chapter 11.2
PC/SC Reader: Programming the WinSCard API in C
Example Chapter 11.3
PC/SC Reader: Java Smartcard I/O API
Examples Chapter 11.4
The CSharp PC/SC Wrapper for .NET
The. NET Framework class library does not support smart cards in version 4.0. Therefore, in this book a CSharp PC / SC wrapper was developed, which WinSCard the main Windows API functions embedded in the WinSCard class. In addition to WinSCard class provides the class PCSCReader a high-level PC / SC API.