KOBIL Smart Card Terminal Manual
Page
33
7.6
Using the CT-API: The Example of the Public Health Insurance Card
The following example demonstrates the use of the functions CT_init, CT_data as
well as CT_close (without discussing the return codes). One C++ exemplary project
is found on the enclosed CD, or can be obtained from KOBIL Systems upon request.
/*
Example of Reading a Public Health Insurance Card
*/
#include <windows.h>
/* platform-specific */
#include <stdio.h>
#include "ct_api.h"
int
main(
void
)
{
unsigned char
sad, dad; /*
source address, destination
address,
are
transmitted
as
pointers
so that these can be evaluated
as
responses
as
well
*/
unsigned char
response[300]; /* field for the response of the
function
*/
unsigned char
command[300]; /*
Commands have a maximum length of 300
characters here
*/
int
i;
unsigned int
lenr;
int
ct_port = 2;
/* Example: COM 2 */
int
ctn = 1;
/* first terminal */
/*
Select logical terminal number and port COM2
*/
if
(CT_init(ctn, ct_port) != OK) {
/*
Return Code OK ?
*/
printf(“\nCard reader cannot be reached. Port?”);
return
(1); /*
Quit program
*/
}
/*
RESET
CT */
sad = 2; /*
source = Host (PC)
*/
dad = 1; /*
destination = CardTerminal
(card reader)
*/
lenr =
sizeof
(response); /* Set maximum length of response */
command[0] = 0x20; /*
CLA
*/
command[1] = 0x11; /*
INS
*/
command[2] = 0x00; /*
P1
*/
command[3] = 0x00; /*
P2
*/
command[4] = 0x00; /*
LEN
*/
/*
Call up function CT_data and display return code
*/
printf("Reset CT return code: %d\nSW1-SW2:", CT_data(ctn, &dad,
&sad, 5, command, &lenr, response));