2

如何从扇区 1 读取数据?验证是真的,我得到异常 IOException(“收发失败”)。

private String readSector() {   
    byte [] array={(byte)0xD3,(byte)0xF7,(byte)0xD3,(byte)0xF7,(byte)0xD3,(byte)0xF7};
    byte[] data = null;
    final ByteArrayBuffer b = new ByteArrayBuffer(mMaxSize);
    String sb=new String();
    boolean succes = false;
    try {
        mClassic.connect();
        succes = mClassic.authenticateSectorWithKeyA(1, array);
        if (succes) {
            b.append(mClassic.readBlock(3), 1, 16);
            data = b.toByteArray();
        }
        else
             sb+="Authentication failed";
        mClassic.close();
    catch (final TagLostException tag) {
        tag.printStackTrace();
        sb+="Tag Lost";
    }
    catch (final IOException e) {
        e.printStackTrace();
        sb+="IOEception";
    }
}
4

1 回答 1

2

在扇区 1 块 4 到 6 上找到它的数据,并使用此代码读取数据,

private String readMadSector() {
        byte [] array={(byte)0xD3,(byte)0xF7,(byte)0xD3,(byte)0xF7,(byte)0xD3,(byte)0xF7};
        byte[] data = null;
        byte [] b;
        String sb=new String();
    boolean succes = false;
    try {
                  mClassic.connect();
                succes = mClassic.authenticateSectorWithKeyA(1, array);
                                  b=mClassic.readBlock(4);

                  sb+=convertHex(b);


                  b=mClassic.readBlock(5);

                  sb+=convertHex(b);

                  b=mClassic.readBlock(6);

                  sb+=convertHex(b);
        else
              sb+="Authentication failed";

        mClassic.close();

    }

    catch (final TagLostException tag) {
        tag.printStackTrace();
        sb+="Tag Lost";
    }

    catch (final IOException e) {
        e.printStackTrace();
        sb+="IOEception";
    }





    return (sb.toString());
}
于 2012-11-04T10:55:12.853 回答