Android 从读卡器解码数据

Android 从读卡器解码数据,android,cardreader,magnetic-cards,android-usb,Android,Cardreader,Magnetic Cards,Android Usb,我正在尝试与一个USB附件(磁条读卡器,型号-E-Seek M250)通信,Nexus 7充当USBHost 用例:刷卡时,我需要从卡中获取详细信息,并将其转换为用户可读的格式 我已经能够成功地获得设备、其接口和输入端点。 之后,我将进行以下操作以获取数据: int receivedBytes = mConnection.bulkTransfer(usbEndpointIN, readBytes, readBytes.length, 3000); if (receivedBytes > 2

我正在尝试与一个USB附件(磁条读卡器,型号-E-Seek M250)通信,Nexus 7充当USBHost

用例:刷卡时,我需要从卡中获取详细信息,并将其转换为用户可读的格式

我已经能够成功地获得设备、其接口和输入端点。 之后,我将进行以下操作以获取数据:

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);
}
经过几次尝试,我找不到一种方法以用户可读的格式获取数据,下面是数据在日志中的显示方式


有人能告诉我如何将这些数据转换成用户可读的格式吗?

读卡器没有加密,所以可能是编码问题。查看读卡器的文档,了解读卡器对卡数据使用的编码类型,并在将字节数组传递给读卡器时使用该编码。下面是使用UTF-8的示例

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();

    }   

}