c++cardreader

Convert byteArray to String


I am a beginner in C++ and try to get a output from a card reader: For this i use a DLL. My problem is that my response returns a byteArray and I would like to convert it to a normal string. So my actual code currently is:

res = CT_data(ctn, &dad, &sad, 5, command, &lenr, response);
printf("\nThe Response: %s", response);

This prints to my console:

The Response: ò

But in the documentation it says that if the connection with the device works it should return 9500 or 9000!

So I think I have to transform the response! How can I do this? Thanks.

From the documentation:

nSuccess = CT_data(CT_data(ctn,dad,sad,lenc,commando,lenr,response)

ctn: Integer, 16 Bit, Unsigned (interne Terminalnummer aus CT_INIT)
dad: Integer, 8 Bit, Unsigned (Destination-Adress)
sad: Integer, 8 Bit, Unsigned (Source-Adress)
lenc: Integer 16 Bit, Unsigned ( Länge des Commandos )
commando: Byte-Array , (Kommando)
lenr: Integer 16 Bit, Unsigned (Länge der Response)
response: Byte-Array ( Antwort)
nSuccess: Integer, 8 Bit, Signed ( 0 = Erfolgreich, -1 = Fehlerhaft)

nSuccess = CT_data(ctn,dad,sad,lenc,command[],lenr,response[])  

Wenn nSuccess = 0, dann response[] prüfen. Wenn response = 9000 oder 9500 war das CT_Reset erfolgreich. Als nächstes dann die Kartenanforderung

typedef CHAR (WINAPI *CT_DATA) (USHORT, UCHAR*, UCHAR*, USHORT, UCHAR*, USHORT*, UCHAR*);

Solution

  • Could the reponse mentioned in the documentation be 2 bytes in hex? Then the response length, i.e. the return value of the CT_data() call, should be 2; and the first byte of the reponse array should be 0x90 or 0x95, i.e. 144 or 149, while the second byte should always be 0. Not sure what byte renders ò in your code page.