【问题标题】:Decoding data from Card reader从读卡器解码数据
【发布时间】:2014-11-08 09:13:12
【问题描述】:

我正在尝试与 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);
}

经过几次尝试,我找不到以用户可读格式获取数据的方法,以下是数据在日志中的显示方式。

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

【问题讨论】:

    标签: android cardreader magnetic-cards android-usb


    【解决方案1】:

    该阅读器未加密,因此可能是编码问题。检查阅读器的文档以查看他们对卡数据使用的编码类型,并在将字节数组传递给它时使用该编码。以下是使用 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();
    
        }   
    
    }
    

    【讨论】:

      猜你喜欢
      • 2012-11-09
      • 1970-01-01
      • 2013-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多