Introduction
The PCSC/Ada library provides bindings to PC/SC-middleware for the Ada programming language. The library allows you to communicate with smart cards using the SCard API with Ada.
PC/SC is a specification for SmartCard integration in computing environment. PC/SC is implemented in Microsoft Windows 200x/XP and available under Microsoft Windows NT/9x. A free implementation of PC/SC, PC/SC Lite, is available under Linux and bundled with Mac OS X.
Overview and Examples
PCSC/Ada provides a thin and a thick binding for the PC/SC API. The thin binding is not explained here though, since Ada programmers should not use this binding directly. It is much more convenient to use the thick binding provided by the PCSC.SCard package.
The following code is used to demonstrate how to establish a PC/SC context, connect to the first reader of a sytem and then send some arbitrary command to the smart card:
with PCSC.SCard; use PCSC; procedure Sample is pragma Linker_Options ("-lpcsclite"); Context : SCard.Context; -- PC/SC context Card : SCard.Card; -- Card handle Readers : SCard.Reader_ID_Set; -- Set of readers begin -- Establish context SCard.Establish_Context (Context => Context, Scope => SCard.Scope_System); -- List readers Readers := SCard.List_Readers (Context => Context); -- Connect to first reader SCard.Connect (Context => Context, Card => Card, Reader => Readers.First_Item, Mode => SCard.Share_Shared); -- Send APDU to card declare Recv_Buffer : SCard.Byte_Set (1 .. 10); Send_Buffer : constant SCard.Byte_Set := (16#00#, 16#A4#, 16#00#, 16#00#, 16#02#, 16#3F#, 16#00#); Recv_Length : Natural := 0; Recv_PCI : SCard.IO_Request; begin SCard.Transmit (Card => Card, Send_Buffer => Send_Buffer, Recv_Pci => Recv_PCI, Recv_Buffer => Recv_Buffer, Recv_Len => Recv_Length); end; -- Disconnect SCard.Disconnect (Card => Card, Action => SCard.Reset_Card); -- Release context SCard.Release_Context (Context => Context); end Sample;
For more detailed examples on how to use PC/SC Ada in your own applications, examine the sample applications which are included in the distribution tarball examples directory (for information about the included examples, check the Examples section in the README).
API documentation
-
You can find the API documentation of PCSC/Ada online here.
Browse the source
-
You can browse the PCSC/Ada source code with gitweb here.