Code_Yoga
Code_Yoga

Reputation: 3248

Decoding data from Card reader

I am trying to communicate with a USB Accessory (Magnetic Strip Card reader, Model- E-Seek M250), with a Nexus 7 acting as a USBHost.

Use case : When a card is swiped , I need to get the details from the card and convert it to a user readable format.

I have been able to successfully get the device, its interface and the input endpoint. After that this is what I am doing to get the data:

int receivedBytes = mConnection.bulkTransfer(usbEndpointIN, readBytes, readBytes.length, 3000);
if (receivedBytes > 2) {
    dataString = new String(readBytes);
    Log.v(Util.TAG, " :: Received Byte Count ::" + receivedBytes);
    Log.v(Util.TAG, " :: Final Value Bytes" + readBytes);
    Log.v(Util.TAG, " :: Final Value String" + dataString);
}

After several tries, I could not find a way to get the data in user readable format, below is the way the data is shown in the logs.

logs

Can anybody let me know how to convert this data into user readable format?

Upvotes: 0

Views: 922

Answers (1)

Frackinfrell
Frackinfrell

Reputation: 327

That reader is not encrypted, so it is probably an encoding issue. Check the documentation for the reader to see what type of encoding they use for the card data and use that encoding when pass the byte array to it. Below is an example if UTF-8 is used.

int receivedBytes = mConnection.bulkTransfer(usbEndpointIN, readBytes, readBytes.length, 3000);
if (receivedBytes > 2) {
    String dataString = null;
    Log.v(Util.TAG, " :: Received Byte Count ::" + receivedBytes);
    Log.v(Util.TAG, " :: Final Value Bytes" + readBytes);

    try {

        dataString = new String( readBytes, "UTF-8");
        Log.v(Util.TAG, " :: Final Value String" + dataString);

    } catch (UnsupportedEncodingException e) {

        e.printStackTrace();

    }   

}

Upvotes: 1

Related Questions