beautypg.com

ACS ACR83 PINeasy Smart Card Reader User Manual

Page 48

background image

ACR83 – Reference Manual

[email protected]

Version 1.05

www.acs.com.hk

Page 48 of 49

// Display LCD message to ACR83

char *msg = "Hello";

printf("Displaying message (%s) to LCD...\n", msg);

lReturn = SCardControl(hCard, IOCTL_SMARTCARD_DISPLAY_LCD_MESSAGE,

msg, strlen(msg),

bOutputBuffer, sizeof(bOutputBuffer), &dwNumBytesReturned);

if (lReturn != SCARD_S_SUCCESS)

printf("Error: SCardControl failed with error 0x%08x\n",

lReturn);

else

{

// Check status

if ((dwNumBytesReturned >= 2) &&

(bOutputBuffer[0] == 0) && (bOutputBuffer[1] == 0))

printf("The message is displayed successfully\n");

else

printf("Error: cannot display LCD message\n");

}

// Read key from ACR83

READ_KEY_OPTION readKeyOption;

char keyString[100];

DWORD len;

BYTE keyReturnCondition;

// Initialize read key option

readKeyOption.bTimeOut = 0;

readKeyOption.wPINMaxExtraDigit = 0x0408;

readKeyOption.bKeyReturnCondition = 0x01;

readKeyOption.bEchoLCDStartPosition = 0;

readKeyOption.bEchoLCDMode = 0x01;

printf("Reading key...\n");

lReturn = SCardControl(hCard, IOCTL_SMARTCARD_READ_KEY,

&readKeyOption, sizeof(READ_KEY_OPTION),

bOutputBuffer, sizeof(bOutputBuffer), &dwNumBytesReturned);

if (lReturn != SCARD_S_SUCCESS)

printf("Error: SCardControl failed with error 0x%08x\n",

lReturn);

else

{

// Check status

if ((dwNumBytesReturned >= 2) &&

(bOutputBuffer[0] == 0) && (bOutputBuffer[1] == 0))

{

if (dwNumBytesReturned >= 3)

keyReturnCondition = bOutputBuffer[2];

else

keyReturnCondition = 0;

len = 0;

if (dwNumBytesReturned >= 4)

{

len = dwNumBytesReturned - 3;

memcpy(keyString, bOutputBuffer + 3, len);

}

// Set the last NULL character

keyString[len] = '\0';