lundi 2 mars 2015

C++ Error in the Code that communicates with pinpad Card Reader - Console application


I have programmed the following which will communicate with a pinpad Card Reader and send a direct command to the reader (not the card apdu). The command will send a plain text key to the card. I am faced with 2 problems actually:


1. When I run the code (console win32 application in Visual Studio 2013) I get the error:



error C2664: 'char CT_data(unsigned short,unsigned char *,unsigned char *,unsigned short,unsigned char *,unsigned short *,unsigned char *)' : cannot convert argument 2 from 'unsigned short *' to 'unsigned char *'


2. I am not sure how to send the direct command to the card reader to insert the key (the key is just a plain text sequence of the type 0026F7993ER365252 - just an example).


This is the code:



#include "stdafx.h"
#include "stdio.h"
#include "ct_api.h"


int main(int argc, char *argv[])
{
char ret;
unsigned short ctn;
unsigned short pn;
unsigned short sad;
unsigned short dad;
int i;

// REQUEST ICC
unsigned char command[] = { 0x20, 0x12, 0x01, 0x00, 0x00 };
unsigned short lenc = sizeof(command);

unsigned char response[300];
unsigned short lenr = sizeof(response);

ctn = 1;
pn = 1;

// Initialize card terminal
ret = CT_init(ctn, pn);
if (ret != OK)
{
printf("Error: CT_init failed with error %d\n", ret);
return 1;
}

sad = 2; // Source = Host
dad = 1; // Destination = Card Terminal

// Send command
ret = CT_data(ctn, &dad, &sad, lenc, command, &lenr, response);
if (ret != OK)
printf("Error: CT_data failed with error %d\n", ret);
else
{
// Display response
printf("Response: ");
for (i = 0; i < lenr; i++)
printf("%02X ", response[i]);
printf("\n");
}

// Close card terminal
ret = CT_close(ctn);
if (ret != OK)
printf("Error: CT_close failed with error %d\n", ret);

return 0;
}


Any help will be highly appreciated. Thanks :-)




Aucun commentaire:

Enregistrer un commentaire