Click here to Skip to main content
13,097,230 members (59,146 online)
Click here to Skip to main content
Add your own
alternative version


33 bookmarked
Posted 2 Nov 2010

SmartCard Direct Serial Interface

, 2 Nov 2010
Rate this:
Please Sign up or sign in to vote.
How to integrate SmartCard interface in an application


This article describes a way of implementing a SmartCard control based application upon a Serial interface.
The hardware interface used is widely known as "Phoenix", and I'm going to describe the hardware architecture about this, and how to integrate it with a Visual Basic application needless to use PC/SC specification.
Otherwise, the target of this article is to show how to directly interact with the smartcard toward the hardware interface told before.

Each SmartCard vendor implements its own command set named APDU (Append Protocol Data Unit) based on ISO-7816 specification. In this way, we can explode each SmartCard type with the correct APDU commands set; in this way, we can use Mifare, TIBC or any other type of Smartcard as an RFID Tag for identity purposes by this VB interface.

To get it working, it's only necessary to feed the circuit with 5V continuous current and an RS-232 PC serial interface.


Phoenix interface is a serial interface with a 9 pin serial jack, and a 10 pin SmartCard connector (pins 4, 6 and 8 unplugged). This interface is just developed and it's the base of this project.
It's composed of a 10 pin SmartCard module, a MAX232 IC used to convert RS-232 (serial) levels to TTL voltages, a 3.579 Mhz quartz crystal used as pulse generator, a voltage regulator and several capacitors, resistors and leds used as pull-up/pull-down resistors, or voltage generators basically.

The serial port pin connections are shown in phoenix electronic schema:


The idea is to connect the Tx and Rx serial pins with the SmartCard interface I/O pin managed by a bidirectional logic.
Otherwise, SmartCard reset pin is connected via MAX232 to RTS serial line, so reading the ATR is so easy as driving this line to inverse voltage levels during a few clock cycles.

SmartCard connector pinout is shown in this table:

Smartcard Module PinOut

Pin # Pin Name Pin Description
1 VCC +5v or 3.3v DC
2 Reset Card Reset
3 CLOCK Card Clock
5 GND Ground
7 I/O In/Out [Data]
9,10 AS Presence Switch

Using the Code

The program resident on host machine is responsible for the serial port initialization and reading/writing process. Getting finite states machine ready to accept commands, here is the sequence:

Once the serial port is initialized, getting the interface ready for reading/writing is composed of only 4 steps:

  1. Feeding the SmartCard; this is got by connecting RS-232 interface and Vcc SmartCard pin will be directly fed by Vcc Serial pin.
  2. Initializing serial communications; this interface needs to be initialized to 9600 bauds, equal parity, 8 data bits and 1 parity bit:


  3. Reseting the SmartCard; you can do it by putting tension on serial 4 pin and then putting it off. After about 40000 cycles (depends on card), you can read the ATR at serial buffer register; so, 100 msg is enough time.
    ObjSerial.RTSEnable = True
    ObjSerial.RTSEnable = False
    Sleep (100)
    buffer$ = ObjSerial.Input

    Translating ATR byte[] to strings of pairs is done by InterpretarHex function:

    Private Function InterpretarHex(buffer, Optional conEspacios As Boolean) As String
    	Dim sol As String
    	Dim byteAux
    	If Len(buffer) > 0 Then
    		byteAux = Hex(Int(Asc(Mid(buffer, 1, 1))))
    		sol = byteAux
    		For i = 2 To Len(buffer)
    			byteAux = Hex(Int(Asc(Mid(buffer, i, 1))))
    			If Len(byteAux) = 1 Then byteAux = "0" + byteAux
    			If (conEspacios) Then
    				sol = sol + " " + byteAux
    				sol = sol + byteAux
    			End If
    		Next i
    	End If
    	InterpretarHex = sol
    End Function	
  4. Reading serial buffer gets the Answer To Reset bytes (ATR).
    buffer$ = ObjSerial.Input


Once having read serial buffer and having RTS pin at low level, the interface is ready for the transmission of the desired APDU command.
Here's an APDU example :

ObjSerial.RTSEnable = False

For i = 1 To (Len(txtCmd.Text) / 2)
    ObjSerial.Output = Chr(Comanda(Mid$(txtCmd.Text, i, 2)))
Next i


buffer$ = ObjSerial.Input
txtResponse.Text = InterpretarHex(buffer$)


This is a picture of the working project:


Points of Interest

This software/hardware interface could be used to integrate SmartCard login in any application you could think about, or you can use it for SmartCard investigation projects.


  • 1st November, 2010: Initial version


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
Spain Spain
I am a software developer grown with programming paradigm evolution. Think that C is God's Programming Language.

You may also be interested in...


Comments and Discussions

QuestionWhere i can download vb file? Pin
LytYrs12-Feb-14 3:07
memberLytYrs12-Feb-14 3:07 
QuestionQuestion Pin
Paramvir Nagpal22-Jul-13 7:20
memberParamvir Nagpal22-Jul-13 7:20 
AnswerRe: Question Pin
Skynet_Code22-Jul-13 23:09
memberSkynet_Code22-Jul-13 23:09 
GeneralRe: Question Pin
Paramvir Nagpal23-Jul-13 1:12
memberParamvir Nagpal23-Jul-13 1:12 
GeneralMy vote of 5 Pin
m_harriss17-Jul-13 21:15
memberm_harriss17-Jul-13 21:15 
GeneralRe: My vote of 5 Pin
Skynet_Code18-Jul-13 3:54
memberSkynet_Code18-Jul-13 3:54 
GeneralMy vote of 5 Pin
manoj kumar choubey3-Jul-13 19:34
membermanoj kumar choubey3-Jul-13 19:34 
GeneralRe: My vote of 5 Pin
Skynet_Code3-Jul-13 20:23
memberSkynet_Code3-Jul-13 20:23 
GeneralMy Vote of 5 Pin
RaviRanjankr17-Dec-10 22:51
memberRaviRanjankr17-Dec-10 22:51 
GeneralRe: My Vote of 5 Pin
Skynet_Code20-Dec-10 1:50
memberSkynet_Code20-Dec-10 1:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170813.1 | Last Updated 2 Nov 2010
Article Copyright 2010 by Skynet_Code
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid