File: sample.adb

package info (click to toggle)
pcscada 0.7.7-10
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 460 kB
  • sloc: ada: 3,292; makefile: 71; sh: 18
file content (54 lines) | stat: -rw-r--r-- 1,339 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
with PCSC.SCard;

use PCSC;

procedure Sample is
   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;