Android Studio读写低频RFID T5557卡源码

本示例使用的发卡器:https://item.taobao.com/item.htm?id=675212889085&spm=a1z10.5-c.w4002-21818769070.13.21166f89nKgnJ7 

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="3dp"
    tools:context=".T5557Activity">
    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:background="?attr/colorPrimary"
        app:navigationIcon="@drawable/baseline_arrow_back_ios_24"
        app:titleTextColor="@color/white"
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteY="0dp">

        <TextView
            android:id="@+id/TextViewlabelDispleft"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="返回"
            android:textColor="@color/white"
            android:textSize="16sp"
            android:gravity="center"
            android:onClick="retmain" />

        <TextView
            android:id="@+id/TextViewlabelDisp"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="T5557卡测试页  "
            android:textColor="@color/white"
            android:textSize="16sp"
            android:gravity="center_horizontal|right|center"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="@+id/TextViewlabelDispleft"
            app:layout_constraintTop_toTopOf="parent" />

    </androidx.appcompat.widget.Toolbar>

    <TextView
        android:id="@+id/sample_text"
        android:layout_width="fill_parent"
        android:layout_height="150dp"
        android:padding="3dp"
        android:text="操作结果"
        android:textSize="12sp"
        android:background="@drawable/shape4border"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"

        />


    <ScrollView
        android:id="@+id/scrollViewIC"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_marginBottom="5dp"

        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/toolbar"
        app:layout_constraintBottom_toTopOf="@+id/sample_text"
        android:scrollbars="horizontal"
        >

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="3dp" >

            <CheckBox
                android:id="@+id/chkPwdT5557"
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:layout_marginLeft="2dp"
                android:textSize="12sp"
                android:checked="false"
                android:text="带密码操作"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toTopOf="parent"/>

            <EditText
                android:id="@+id/editTextPwdT5557"
                android:layout_width="80dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:background="@drawable/shape4border"
                android:digits="0123456789ABCDEFabcdef"
                android:gravity="center"
                android:inputType="textCapCharacters"
                android:maxLength="8"
                android:maxLines="1"
                android:text="00000000"
                android:textSize="14sp"
                app:layout_constraintBottom_toBottomOf="@+id/chkPwdT5557"
                app:layout_constraintLeft_toRightOf="@+id/chkPwdT5557"
                app:layout_constraintTop_toTopOf="@+id/chkPwdT5557"

                />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="(十六进制)"
                android:textSize="12sp"
                android:layout_marginLeft="10dp"
                app:layout_constraintLeft_toRightOf="@+id/editTextPwdT5557"
                app:layout_constraintTop_toTopOf="@+id/chkPwdT5557"
                app:layout_constraintBottom_toBottomOf="@+id/chkPwdT5557"/>



            <CheckBox
                android:id="@+id/chkUidNeedT5557"
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:layout_marginLeft="2dp"
                android:textSize="12sp"
                android:checked="false"
                android:text="仅操作指定卡号的卡"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/chkPwdT5557"/>

            <EditText
                android:id="@+id/editTextUidT5557"
                android:layout_width="110dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:background="@drawable/shape4border"
                android:digits="0123456789ABCDEFabcdef"
                android:gravity="center"
                android:inputType="textCapCharacters"
                android:maxLength="12"
                android:maxLines="1"
                android:text="000000000000"
                android:textSize="14sp"
                app:layout_constraintBottom_toBottomOf="@+id/chkUidNeedT5557"
                app:layout_constraintLeft_toRightOf="@+id/chkUidNeedT5557"
                app:layout_constraintTop_toTopOf="@+id/chkUidNeedT5557" />



            <TextView
                android:id="@+id/TextViewlabel0"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="返回数据:"
                android:textSize="12sp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintBottom_toTopOf="@+id/TextViewRetDataT5557"/>

            <TextView
                android:id="@+id/TextViewRetDataT5557"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="3dp"
                android:text=""
                android:textSize="12sp"
                android:background="@drawable/shape4border"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/btnRetDataClrT5557"

                />

            <Button
                android:id="@+id/btnRetDataClrT5557"
                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:onClick="textclear5557"
                android:text="清空数据"
                android:textSize="11sp"
                app:layout_constraintTop_toBottomOf="@+id/editTextUidT5557"
                app:layout_constraintRight_toRightOf="parent" />

            <Button
                android:id="@+id/btnPwdChangeT5557"
                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:onClick="changepwd5557"
                android:text="修改卡密码"
                android:textSize="11sp"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/TextViewRetDataT5557" />

            <TextView
                android:id="@+id/TextViewlabel1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="新密码:"
                android:textSize="12sp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toTopOf="@+id/btnPwdChangeT5557"
                app:layout_constraintBottom_toBottomOf="@+id/btnPwdChangeT5557"

                />

            <EditText
                android:id="@+id/editTextPwdNewT5557"
                android:layout_width="80dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:background="@drawable/shape4border"
                android:digits="0123456789ABCDEFabcdef"
                android:gravity="center"
                android:inputType="textCapCharacters"
                android:maxLength="8"
                android:maxLines="1"
                android:text="00000000"
                android:textSize="14sp"
                app:layout_constraintBottom_toBottomOf="@+id/btnPwdChangeT5557"
                app:layout_constraintLeft_toRightOf="@+id/TextViewlabel1"
                app:layout_constraintTop_toTopOf="@+id/btnPwdChangeT5557" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="(十六进制)"
                android:textSize="12sp"
                android:layout_marginLeft="10dp"
                app:layout_constraintLeft_toRightOf="@+id/editTextPwdNewT5557"
                app:layout_constraintTop_toTopOf="@+id/editTextPwdNewT5557"
                app:layout_constraintBottom_toBottomOf="@+id/editTextPwdNewT5557"/>


            <TextView
                android:id="@+id/TextViewlabel2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="第0页:"
                android:textSize="12sp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toTopOf="@+id/chkB0T5557"
                app:layout_constraintBottom_toBottomOf="@+id/chkB0T5557"
                />

            <CheckBox
                android:id="@+id/chkB0T5557"
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:layout_marginLeft="2dp"
                android:textSize="11sp"
                android:checked="false"
                android:text="块0"
                app:layout_constraintLeft_toRightOf="@+id/TextViewlabel2"
                app:layout_constraintTop_toBottomOf="@+id/btnPwdChangeT5557"/>

            <CheckBox
                android:id="@+id/chkB1T5557"
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:layout_marginLeft="2dp"
                android:textSize="11sp"
                android:checked="false"
                android:text="块1"
                app:layout_constraintLeft_toRightOf="@+id/chkB0T5557"
                app:layout_constraintBottom_toBottomOf="@+id/chkB0T5557"/>
            <CheckBox
                android:id="@+id/chkB2T5557"
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:layout_marginLeft="2dp"
                android:textSize="11sp"
                android:checked="false"
                android:text="块2"
                app:layout_constraintLeft_toRightOf="@+id/chkB1T5557"
                app:layout_constraintBottom_toBottomOf="@+id/chkB0T5557"/>

            <CheckBox
                android:id="@+id/chkB3T5557"
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:layout_marginLeft="2dp"
                android:textSize="11sp"
                android:checked="false"
                android:text="块3"
                app:layout_constraintLeft_toRightOf="@+id/chkB2T5557"
                app:layout_constraintBottom_toBottomOf="@+id/chkB0T5557"/>
            <CheckBox
                android:id="@+id/chkB4T5557"
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:layout_marginLeft="2dp"
                android:textSize="12sp"
                android:checked="false"
                android:text="块4"
                app:layout_constraintLeft_toRightOf="@+id/chkB3T5557"
                app:layout_constraintBottom_toBottomOf="@+id/chkB0T5557"/>
            <CheckBox
                android:id="@+id/chkB5T5557"
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:layout_marginLeft="2dp"
                android:textSize="12sp"
                android:checked="false"
                android:text="块5"
                app:layout_constraintLeft_toRightOf="@+id/chkB4T5557"
                app:layout_constraintBottom_toBottomOf="@+id/chkB0T5557"/>

            <CheckBox
                android:id="@+id/chkB6T5557"
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:layout_marginLeft="2dp"
                android:checked="false"
                android:text="块6"
                android:textSize="11sp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/chkB0T5557" />

            <CheckBox
                android:id="@+id/chkB7T5557"
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:layout_marginLeft="2dp"
                android:textSize="12sp"
                android:checked="false"
                android:text="块7"
                app:layout_constraintLeft_toRightOf="@+id/chkB6T5557"
                app:layout_constraintBottom_toBottomOf="@+id/chkB6T5557"/>

            <TextView
                android:id="@+id/TextViewlabel3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="第1页:"
                android:textSize="12sp"
                android:layout_marginLeft="20dp"
                app:layout_constraintLeft_toRightOf="@+id/chkB7T5557"
                app:layout_constraintTop_toTopOf="@+id/chkB7T5557"
                app:layout_constraintBottom_toBottomOf="@+id/chkB7T5557"
                />

            <CheckBox
                android:id="@+id/chkB11T5557"
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:checked="false"
                android:text="块1"
                android:textSize="11sp"
                app:layout_constraintBottom_toBottomOf="@+id/chkB7T5557"
                app:layout_constraintLeft_toRightOf="@+id/TextViewlabel3" />

            <CheckBox
                android:id="@+id/chkB12T5557"
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:layout_marginLeft="2dp"
                android:checked="false"
                android:text="块2"
                android:textSize="11sp"
                app:layout_constraintBottom_toBottomOf="@+id/chkB7T5557"
                app:layout_constraintLeft_toRightOf="@+id/chkB11T5557" />

            <CheckBox
                android:id="@+id/chkB13T5557"
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:layout_marginLeft="2dp"
                android:checked="false"
                android:text="块3"
                android:textSize="11sp"
                app:layout_constraintBottom_toBottomOf="@+id/chkB7T5557"
                app:layout_constraintLeft_toRightOf="@+id/chkB12T5557" />

            <CheckBox
                android:id="@+id/chkB14T5557"
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:layout_marginLeft="2dp"
                android:checked="false"
                android:text="块4"
                android:textSize="11sp"
                app:layout_constraintBottom_toBottomOf="@+id/chkB7T5557"
                app:layout_constraintLeft_toRightOf="@+id/chkB13T5557" />

            <Button
                android:id="@+id/btnReadT5557"
                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:layout_marginRight="20dp"
                android:onClick="read5557"
                android:text="读卡"
                android:textSize="11sp"
                app:layout_constraintRight_toLeftOf="@+id/btnWriteT5557"
                app:layout_constraintTop_toBottomOf="@+id/chkB7T5557" />

            <Button
                android:id="@+id/btnWriteT5557"
                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:onClick="write5557"
                android:text="写卡"
                android:textSize="11sp"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/chkB7T5557" />

            <TextView
                android:id="@+id/TextViewlabel4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="写入数据:"
                android:textSize="12sp"
                app:layout_constraintBottom_toBottomOf="@+id/btnReadT5557"
                app:layout_constraintLeft_toLeftOf="parent" />

            <EditText
                android:id="@+id/editTextDataT5557"
                android:layout_width="0dp"
                android:layout_height="40dp"
                android:background="@drawable/shape4border"
                android:digits="0123456789ABCDEFabcdef"
                android:gravity="left"
                android:inputType="textCapCharacters"
                android:maxLength="128"
                android:text="11111111"
                android:padding="3dp"
                android:textSize="12sp"
                app:layout_constraintLeft_toLeftOf="@+id/TextViewRetDataT5557"
                app:layout_constraintRight_toRightOf="@+id/TextViewRetDataT5557"
                app:layout_constraintTop_toBottomOf="@+id/btnWriteT5557" />

            <TextView
                android:id="@+id/TextViewlabel5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="配置区位于第0页第0块:\ne5550兼容模式,主控键值默认(不等于6及不等于9),波特率RF/32,调制模式为\n曼彻斯特码,相位键控RF/2,自动发送最大块为1,卡片复位无延时\n如需改动以上值请联系我们 !"
                android:textSize="12sp"
                app:layout_constraintTop_toBottomOf="@+id/editTextDataT5557"
                app:layout_constraintLeft_toLeftOf="parent" />

            <CheckBox
                android:id="@+id/chkAOR"
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:layout_marginLeft="2dp"
                android:textSize="12sp"
                android:checked="false"
                android:text="AOR请求应答模式"
                android:onClick="updateset5557"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/TextViewlabel5"/>

            <CheckBox
                android:id="@+id/chkFrameEnd"
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:layout_marginLeft="2dp"
                android:textSize="12sp"
                android:checked="true"
                android:text="帧终结符"
                android:onClick="updateset5557"
                app:layout_constraintLeft_toRightOf="@+id/chkAOR"
                app:layout_constraintBottom_toBottomOf="@+id/chkAOR"/>

            <CheckBox
                android:id="@+id/chkPwdSetT5557"
                android:layout_width="wrap_content"
                android:layout_height="30dp"
                android:layout_marginLeft="2dp"
                android:textSize="12sp"
                android:checked="false"
                android:text="启用密码读写功能,并设密码为"
                android:onClick="updateset5557"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/chkAOR"/>

            <EditText
                android:id="@+id/editTextPwdSetT5557"
                android:layout_width="80dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:background="@drawable/shape4border"
                android:digits="0123456789ABCDEFabcdef"
                android:gravity="center"
                android:inputType="textCapCharacters"
                android:maxLength="8"
                android:maxLines="1"
                android:text="00000000"
                android:textSize="14sp"
                app:layout_constraintBottom_toBottomOf="@+id/chkPwdSetT5557"
                app:layout_constraintLeft_toRightOf="@+id/chkPwdSetT5557"
                app:layout_constraintTop_toTopOf="@+id/chkPwdSetT5557"

                />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="(十六进制)"
                android:textSize="12sp"
                android:layout_marginLeft="10dp"
                app:layout_constraintLeft_toRightOf="@+id/editTextPwdSetT5557"
                app:layout_constraintTop_toTopOf="@+id/chkPwdSetT5557"
                app:layout_constraintBottom_toBottomOf="@+id/chkPwdSetT5557"/>

            <TextView
                android:id="@+id/TextViewlabel22"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="配置值:"
                android:textSize="12sp"
                app:layout_constraintTop_toTopOf="@+id/editTextConfigWordT5557"
                app:layout_constraintBottom_toBottomOf="@+id/editTextConfigWordT5557"
                app:layout_constraintLeft_toLeftOf="parent" />

            <EditText
                android:id="@+id/editTextConfigWordT5557"
                android:layout_width="68dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:background="@drawable/shape4border"
                android:digits="0123456789ABCDEFabcdef"
                android:gravity="left"
                android:inputType="textCapCharacters"
                android:maxLength="8"
                android:text="00088028"
                android:paddingLeft="3dp"
                android:textSize="12sp"
                app:layout_constraintLeft_toRightOf="@+id/TextViewlabel22"
                app:layout_constraintTop_toBottomOf="@+id/chkPwdSetT5557"
                />


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="(十六进制)"
                android:textSize="12sp"
                android:layout_marginLeft="10dp"
                app:layout_constraintLeft_toRightOf="@+id/editTextConfigWordT5557"
                app:layout_constraintTop_toTopOf="@+id/editTextConfigWordT5557"
                app:layout_constraintBottom_toBottomOf="@+id/editTextConfigWordT5557"/>

            <Button
                android:id="@+id/btnDefalutT5557"
                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:layout_marginRight="20dp"
                android:onClick="default5557"
                android:text="← 默认值"
                android:textSize="11sp"
                app:layout_constraintRight_toLeftOf="@+id/btnInitT5557"
                app:layout_constraintBottom_toBottomOf="@+id/btnInitT5557" />

            <Button
                android:id="@+id/btnInitT5557"
                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:onClick="init5557"
                android:text="设定配置"
                android:textSize="12sp"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/editTextConfigWordT5557"/>

            <Button
                android:id="@+id/btnT5557to4100"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:onClick="t5557to4100"
                android:text="t5557卡配置成ID卡"
                android:textSize="12sp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/btnInitT5557"/>

            <TextView
                android:id="@+id/TextViewlabel23"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="厂商编码"
                android:textSize="12sp"
                app:layout_constraintTop_toTopOf="@+id/btnT5557to4100"
                app:layout_constraintBottom_toBottomOf="@+id/btnT5557to4100"
                app:layout_constraintLeft_toRightOf="@+id/btnT5557to4100" />

        </androidx.constraintlayout.widget.ConstraintLayout>

    </ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>
package com.usbreadertest;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

import com.reader.ouridr;
import com.reader.ourmifare;
public class T5557Activity extends AppCompatActivity {
    private TextView tv;
    private byte NEEDSERIAL = 0x01;   //需要只对指定系列号的卡操作
    private byte NEEDKEY = 0x02;      //需要用密码认证
    private byte LOCKBIT = 0x04;      //锁定配置块或数据块,仅对   t5557_init,t5557_write ,t5557_changekey函数有效
    private byte KEYENABLE = 0x08;    //启用本卡的密码功能
    private byte RESETCARD = 0x10;    //操作成功后重启卡片

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_t5557);
        androidx.appcompat.widget.Toolbar toolbar=findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        tv = findViewById(R.id.sample_text);
        tv.setText("操作结果");
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if(item.getItemId()==android.R.id.home){
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    public void retmain(View view)
    {
        finish();
    }

    public void textclear5557(View view)
    {
        TextView tvls;
        tvls = findViewById(R.id.TextViewRetDataT5557);
        tvls.setText("");
    }

    public void default5557(View view)
    {
        EditText etls;
        CheckBox cbls;
        etls = findViewById(R.id.editTextConfigWordT5557);
        etls.setText("00088028");

        cbls = findViewById(R.id.chkAOR);//AOR请求应答模式
        cbls.setChecked(false);
        cbls = findViewById(R.id.chkFrameEnd);//帧终结符
        cbls.setChecked(true);
        cbls = findViewById(R.id.chkPwdSetT5557);//启用密码读写功能,并设密码为
        cbls.setChecked(false);
    }

    public void updateset5557(View view)
    {
        CheckBox cbls;
        CheckBox cbAOR;
        CheckBox cbPWD;

        EditText etls;
        byte[] Configdata = new byte[4];//配置值

        etls = findViewById(R.id.editTextConfigWordT5557);
        String strls = etls.getText().toString().trim();
        if(strls.length() < 8){
            strls = "00088028";
            Configdata[0] = 0x00;
            Configdata[1] = 0x08;
            Configdata[2] = (byte)0x80;
            Configdata[3] = 0x28;
        }
        else {
            for (byte i = 0; i < 4; i++) {
                Configdata[i] = (byte)Integer.parseInt(strls.substring(i * 2, i * 2 + 2),16);//只有用Integer.parseInt才能杜绝大于128时的错误
            }
        }
        
        cbAOR = findViewById(R.id.chkAOR);//AOR请求应答模式
        cbPWD = findViewById(R.id.chkPwdSetT5557);//启用密码读写功能,并设密码为
        if(cbAOR.isChecked()) {
            if(!cbPWD.isChecked()) {//密码没启用,AOR无效
                cbAOR.setChecked(false);
                Configdata[2] &= 0xfd;
                tv.setText("密码没启用,AOR无效");
            }
            else {
                Configdata[2] |= 0x02;
            }
        }
        else {
            Configdata[2] &= 0xfd;
        }

        cbls = findViewById(R.id.chkFrameEnd);//帧终结符
        if(cbls.isChecked()) {
            Configdata[3] |= 0x08;
        }
        else {
            Configdata[3] &= 0xf7;
        }

        if(cbPWD.isChecked()) {
            if ((Configdata[3] & 0xe0) > (6 * 32)) {//启用密码功能后,最大块不能为7
                Configdata[3] &= 0x1f;
                Configdata[3] |=(6 * 32);
            }
            Configdata[3] |= 0x10;//启用密码功能
        }
        else{
            Configdata[3] &= 0xef;//取消密码功能
            Configdata[2] &= 0xfd;
            cbAOR.setChecked(false);
        }

        etls.setText(String.format("%02X%02X%02X%02X",Configdata[0],Configdata[1],Configdata[2],Configdata[3]));

    }
    public void changepwd5557(View view)
    {
        byte i;
        byte j;
        byte status;//存放返回值

        byte myctrlword;//控制字

        byte[] oldpicckey = new byte[4];//密码
        byte[] mypiccserial = new byte[6];//卡序列号
        byte[] newpicckey = new byte[4];//指定写哪一块

        myctrlword = 0; //NEEDSERIAL:需要只对指定系列号的卡操作,NEEDKEY:需要用密码认证,LOCKBIT:锁定块,KEYENABLE:启用本卡的密码功能

        String strls;

        CheckBox cbls;
        EditText etls;

        cbls = findViewById(R.id.chkPwdT5557);
        if(cbls.isChecked()) {//本次操作需要密码验证
            etls = findViewById(R.id.editTextPwdT5557);
            strls = etls.getText().toString().trim();
            if(strls.length() < 8)
            {
                tv.setText("旧密码长度不足8位");
                return;
            }
            for (i = 0; i < 4; i++) {
                oldpicckey[i] = (byte)Integer.parseInt(strls.substring(i*2,i*2+2),16);//只有用Integer.parseInt才能杜绝大于128时的错误
            }
            myctrlword += ouridr.NEEDKEY;

        }

        cbls = findViewById(R.id.chkUidNeedT5557);
        if(cbls.isChecked()) {//仅操作指定卡号的卡
            etls = findViewById(R.id.editTextUidT5557);
            strls = etls.getText().toString().trim();
            if(strls.length() < 12)
            {
                tv.setText("卡号长度不足12位");
                return;
            }

            for (i = 0; i < 6; i++) {
                mypiccserial[i] = (byte)Integer.parseInt(strls.substring(i*2,i*2+2),16);//只有用Integer.parseInt才能杜绝大于128时的错误
            }
            myctrlword += ouridr.NEEDSERIAL;

        }

        etls = findViewById(R.id.editTextPwdNewT5557);
        strls = etls.getText().toString().trim();
        if(strls.length() < 8)
        {
            tv.setText("新密码长度不足8位!");
            return;
        }

        for (i = 0; i < 4; i++) {
            newpicckey[i] = (byte)Integer.parseInt(strls.substring(i*2,i*2+2),16);//只有用Integer.parseInt才能杜绝大于128时的错误
        }

        status = ouridr.t5557changekey(myctrlword,mypiccserial,oldpicckey,newpicckey);

        if(status == 0)
        {
            strls = "卡号[";
            strls += String.format("%02X%02X%02X%02X%02X%02X",mypiccserial[0],mypiccserial[1],mypiccserial[2],mypiccserial[3],mypiccserial[4],mypiccserial[5]);
            strls += "]";
            TextView tvls = findViewById(R.id.TextViewRetDataT5557);
            tvls.setText(strls);
            strls = "更改T5557卡密码成功";
            ouridr.beep(38);
        }
        else {
            strls=GetErrInf(status);
        }
        tv.setText(strls);

    }
    public void read5557(View view)
    {
        byte i;
        byte status;//存放返回值

        byte myctrlword;//控制字

        byte[] oldpicckey = new byte[4];//密码
        byte[] mypiccserial = new byte[6];//卡序列号
        byte[] mypiccdata = new byte[64];//读卡数据缓冲:卡无线转输分频比、卡内容长度(字节数),及最多返回12块的数据
        byte[] mypiccblockflag = new byte[2];//指定读哪一块

        myctrlword = 0; //NEEDSERIAL:需要只对指定系列号的卡操作,NEEDKEY:需要用密码认证,LOCKBIT:锁定块,KEYENABLE:启用本卡的密码功能

        String strls;

        CheckBox cbls;
        EditText etls;

        cbls = findViewById(R.id.chkPwdT5557);
        if(cbls.isChecked()) {//本次操作需要密码验证
            etls = findViewById(R.id.editTextPwdT5557);
            strls = etls.getText().toString().trim();
            if(strls.length() < 8)
            {
                tv.setText("密码长度不足8位");
                return;
            }
            for (i = 0; i < 4; i++) {
                oldpicckey[i] = (byte)Integer.parseInt(strls.substring(i*2,i*2+2),16);//只有用Integer.parseInt才能杜绝大于128时的错误
            }
            myctrlword += ouridr.NEEDKEY;

        }

        cbls = findViewById(R.id.chkUidNeedT5557);
        if(cbls.isChecked()) {//仅操作指定卡号的卡
            etls = findViewById(R.id.editTextUidT5557);
            strls = etls.getText().toString().trim();
            if(strls.length() < 12)
            {
                tv.setText("卡号长度不足12位");
                return;
            }

            for (i = 0; i < 6; i++) {
                mypiccserial[i] = (byte)Integer.parseInt(strls.substring(i*2,i*2+2),16);//只有用Integer.parseInt才能杜绝大于128时的错误
            }
            myctrlword += ouridr.NEEDSERIAL;

        }

        //操作块标志
        //第0页的块
        mypiccblockflag[0] = 0;

        cbls = findViewById(R.id.chkB0T5557);
        if(cbls.isChecked()) {
            mypiccblockflag[0] += 1;
        }

        cbls = findViewById(R.id.chkB1T5557);
        if(cbls.isChecked()) {
            mypiccblockflag[0] += 2;
        }

        cbls = findViewById(R.id.chkB2T5557);
        if(cbls.isChecked()) {
            mypiccblockflag[0] += 4;
        }

        cbls = findViewById(R.id.chkB3T5557);
        if(cbls.isChecked()) {
            mypiccblockflag[0] += 8;
        }

        cbls = findViewById(R.id.chkB4T5557);
        if(cbls.isChecked()) {
            mypiccblockflag[0] += 16;
        }

        cbls = findViewById(R.id.chkB5T5557);
        if(cbls.isChecked()) {
            mypiccblockflag[0] += 32;
        }

        cbls = findViewById(R.id.chkB6T5557);
        if(cbls.isChecked()) {
            mypiccblockflag[0] += 64;
        }

        cbls = findViewById(R.id.chkB7T5557);
        if(cbls.isChecked()) {
            mypiccblockflag[0] += 128;
        }

        //第1页
        mypiccblockflag[1] = 0;

        cbls = findViewById(R.id.chkB11T5557);
        if(cbls.isChecked()) {
            mypiccblockflag[1] += 2;
        }

        cbls = findViewById(R.id.chkB12T5557);
        if(cbls.isChecked()) {
            mypiccblockflag[1] += 4;
        }

        cbls = findViewById(R.id.chkB13T5557);
        if(cbls.isChecked()) {
            mypiccblockflag[1] += 8;
        }

        cbls = findViewById(R.id.chkB14T5557);
        if(cbls.isChecked()) {
            mypiccblockflag[1] += 16;
        }

        status = ouridr.t5557read(myctrlword,mypiccserial,oldpicckey,mypiccblockflag,mypiccdata);

        if(status == 0)
        {
            strls = "卡无线转输分频比[" + Integer.toString(mypiccdata[0]) + "],卡号[";
            strls += String.format("%02X%02X%02X%02X%02X%02X",mypiccserial[0],mypiccserial[1],mypiccserial[2],mypiccserial[3],mypiccserial[4],mypiccserial[5]);
            strls += "],卡数据[";
            for (i = 0; i < mypiccdata[1]; i++) {
                strls += String.format("%02X",mypiccdata[i+2]);
            }
            strls += "]";

            TextView tvls = findViewById(R.id.TextViewRetDataT5557);
            tvls.setText(strls);
            strls = "读T5557卡成功";
            ouridr.beep(38);
        }
        else {
            strls=GetErrInf(status);
        }
        tv.setText(strls);
    }
    public void write5557(View view)
    {
        byte i;
        byte j;
        byte status;//存放返回值

        byte myctrlword;//控制字

        byte[] oldpicckey = new byte[4];//密码
        byte[] mypiccserial = new byte[6];//卡序列号
        byte[] mypiccdata = new byte[64];//写入数据缓冲:最多12块的数据
        byte[] mypiccblockflag = new byte[2];//指定写哪一块

        myctrlword = 0; //NEEDSERIAL:需要只对指定系列号的卡操作,NEEDKEY:需要用密码认证,LOCKBIT:锁定块,KEYENABLE:启用本卡的密码功能

        String strls;

        CheckBox cbls;
        EditText etls;

        cbls = findViewById(R.id.chkPwdT5557);
        if(cbls.isChecked()) {//本次操作需要密码验证
            etls = findViewById(R.id.editTextPwdT5557);
            strls = etls.getText().toString().trim();
            if(strls.length() < 8)
            {
                tv.setText("密码长度不足8位");
                return;
            }
            for (i = 0; i < 4; i++) {
                oldpicckey[i] = (byte)Integer.parseInt(strls.substring(i*2,i*2+2),16);//只有用Integer.parseInt才能杜绝大于128时的错误
            }
            myctrlword += ouridr.NEEDKEY;

        }

        cbls = findViewById(R.id.chkUidNeedT5557);
        if(cbls.isChecked()) {//仅操作指定卡号的卡
            etls = findViewById(R.id.editTextUidT5557);
            strls = etls.getText().toString().trim();
            if(strls.length() < 12)
            {
                tv.setText("卡号长度不足12位");
                return;
            }

            for (i = 0; i < 6; i++) {
                mypiccserial[i] = (byte)Integer.parseInt(strls.substring(i*2,i*2+2),16);//只有用Integer.parseInt才能杜绝大于128时的错误
            }
            myctrlword += ouridr.NEEDSERIAL;

        }

        //操作块标志
        j = 0;
        //第0页的块
        mypiccblockflag[0] = 0;

        cbls = findViewById(R.id.chkB0T5557);
        if(cbls.isChecked()) {
            mypiccblockflag[0] += 1;
            j++;
        }

        cbls = findViewById(R.id.chkB1T5557);
        if(cbls.isChecked()) {
            mypiccblockflag[0] += 2;
            j++;
        }

        cbls = findViewById(R.id.chkB2T5557);
        if(cbls.isChecked()) {
            mypiccblockflag[0] += 4;
            j++;
        }

        cbls = findViewById(R.id.chkB3T5557);
        if(cbls.isChecked()) {
            mypiccblockflag[0] += 8;
            j++;
        }

        cbls = findViewById(R.id.chkB4T5557);
        if(cbls.isChecked()) {
            mypiccblockflag[0] += 16;
            j++;
        }

        cbls = findViewById(R.id.chkB5T5557);
        if(cbls.isChecked()) {
            mypiccblockflag[0] += 32;
            j++;
        }

        cbls = findViewById(R.id.chkB6T5557);
        if(cbls.isChecked()) {
            mypiccblockflag[0] += 64;
            j++;
        }

        cbls = findViewById(R.id.chkB7T5557);
        if(cbls.isChecked()) {
            mypiccblockflag[0] += 128;
            j++;
        }

        //第1页
        mypiccblockflag[1] = 0;

        cbls = findViewById(R.id.chkB11T5557);
        if(cbls.isChecked()) {
            mypiccblockflag[1] += 2;
            j++;
        }

        cbls = findViewById(R.id.chkB12T5557);
        if(cbls.isChecked()) {
            mypiccblockflag[1] += 4;
            j++;
        }

        cbls = findViewById(R.id.chkB13T5557);
        if(cbls.isChecked()) {
            mypiccblockflag[1] += 8;
            j++;
        }

        cbls = findViewById(R.id.chkB14T5557);
        if(cbls.isChecked()) {
            mypiccblockflag[1] += 16;
            j++;
        }

        //写卡数据准备
        if(j == 0)
        {
            tv.setText("请先选择需要写入的块");
            return;
        }
        etls = findViewById(R.id.editTextDataT5557);
        strls = etls.getText().toString().trim();
        if(strls.length() < (j*8))
        {
            tv.setText("写入数据长度不足,请补足数据!");
            return;
        }

        for (i = 0; i < (j*4); i++) {
            mypiccdata[i] = (byte)Integer.parseInt(strls.substring(i*2,i*2+2),16);//只有用Integer.parseInt才能杜绝大于128时的错误
        }

        status = ouridr.t5557write(myctrlword,mypiccserial,oldpicckey,mypiccblockflag,mypiccdata);
        if(status == 0) {
            strls = "卡号[";
            strls += String.format("%02X%02X%02X%02X%02X%02X", mypiccserial[0], mypiccserial[1], mypiccserial[2], mypiccserial[3], mypiccserial[4], mypiccserial[5]);
            strls += "]";
            TextView tvls = findViewById(R.id.TextViewRetDataT5557);
            tvls.setText(strls);
            strls = "写T5557卡成功";
            ouridr.beep(38);
        }else {
            strls=GetErrInf(status);
        }
            tv.setText(strls);
    }


    public void init5557(View view)
    {
        byte i;
        byte status;//存放返回值

        byte myctrlword;//控制字

        byte[] oldpicckey = new byte[4];//密码
        byte[] mypiccserial = new byte[6];//卡序列号
        byte[] mypiccdata = new byte[4];//写入数据缓冲
        byte[] newpicckey = new byte[4];//指定写哪一块

        myctrlword = 0; //NEEDSERIAL:需要只对指定系列号的卡操作,NEEDKEY:需要用密码认证,LOCKBIT:锁定块,KEYENABLE:启用本卡的密码功能

        String strls;

        CheckBox cbls;
        EditText etls;

        cbls = findViewById(R.id.chkPwdT5557);
        if(cbls.isChecked()) {//本次操作需要密码验证
            etls = findViewById(R.id.editTextPwdT5557);
            strls = etls.getText().toString().trim();
            if(strls.length() < 8)
            {
                tv.setText("密码长度不足8位");
                return;
            }
            for (i = 0; i < 4; i++) {
                oldpicckey[i] = (byte)Integer.parseInt(strls.substring(i*2,i*2+2),16);//只有用Integer.parseInt才能杜绝大于128时的错误
            }
            myctrlword += ouridr.NEEDKEY;

        }

        cbls = findViewById(R.id.chkPwdSetT5557);
        if(cbls.isChecked()) {//启用密码读写功能
            etls = findViewById(R.id.editTextPwdSetT5557);
            strls = etls.getText().toString().trim();
            if(strls.length() < 8)
            {
                tv.setText("新密码长度不足8位");
                return;
            }
            for (i = 0; i < 4; i++) {
                newpicckey[i] = (byte)Integer.parseInt(strls.substring(i*2,i*2+2),16);//只有用Integer.parseInt才能杜绝大于128时的错误
            }
            myctrlword += ouridr.KEYENABLE;

        }
        else {
            newpicckey[0] = 0x00;
            newpicckey[1] = 0x00;
            newpicckey[2] = 0x00;
            newpicckey[3] = 0x00;
        }

        cbls = findViewById(R.id.chkUidNeedT5557);
        if(cbls.isChecked()) {//仅操作指定卡号的卡
            etls = findViewById(R.id.editTextUidT5557);
            strls = etls.getText().toString().trim();
            if(strls.length() < 12)
            {
                tv.setText("卡号长度不足12位");
                return;
            }

            for (i = 0; i < 6; i++) {
                mypiccserial[i] = (byte)Integer.parseInt(strls.substring(i*2,i*2+2),16);//只有用Integer.parseInt才能杜绝大于128时的错误
            }
            myctrlword += ouridr.NEEDSERIAL;

        }

        //配置值:
        etls = findViewById(R.id.editTextConfigWordT5557);
        strls = etls.getText().toString().trim();
        if(strls.length() < 8)
        {
            tv.setText("配置值输入长度不足8位");
            return;
        }
        for (i = 0; i < 4; i++) {
            mypiccdata[i] = (byte)Integer.parseInt(strls.substring(i*2,i*2+2),16);//只有用Integer.parseInt才能杜绝大于128时的错误
        }

        status = ouridr.t5557init(myctrlword,mypiccserial,oldpicckey,mypiccdata,newpicckey);
        if(status == 0) {
            strls = "卡号[";
            strls += String.format("%02X%02X%02X%02X%02X%02X",mypiccserial[0],mypiccserial[1],mypiccserial[2],mypiccserial[3],mypiccserial[4],mypiccserial[5]);
            strls += "]";
            TextView tvls = findViewById(R.id.TextViewRetDataT5557);
            tvls.setText(strls);
            strls = "配置T5557卡成功";
            ouridr.beep(38);
        }
        else {
            strls=GetErrInf(status);
        }
        tv.setText(strls);
    }

    public void t5557to4100(View view){
        byte[] myuidbuf=new byte[7];
        byte[] oldpicckey=new byte[4];
        byte[] newpicckey=new byte[4];
        byte[] mypiccserial=new byte[6];
        byte myctrlword=RESETCARD;

        myuidbuf[0]=47;
        myuidbuf[1]=1;
        myuidbuf[2]=2;
        myuidbuf[3]=3;
        myuidbuf[4]=4;

        byte status=ouridr.t5557to4100(myctrlword,mypiccserial,oldpicckey,newpicckey,myuidbuf);
        if (status==0){
            ouridr.beep(38);

            tv.setText("T5557卡配置成ID卡成功!");
        }else{
            tv.setText("错误代码:"+Integer.toString(status));
        }
    }

    public String GetErrInf(byte errcode) {
        String dispstr="";
        switch(errcode){
            case 1:
                dispstr="错误代码:1,写入配置的值不正确,配置区或密码区可能已被锁定,请重新写入!";
                break;
            case 2:
                dispstr="错误代码:2,本卡尚未开启密码功能,函数myctrlword中无需加入NEEDKEY!";
                break;
            case 3:
                dispstr="错误代码:3,需要指定密码,函数myctrlword要加入NEEDKEY!";
                break;
            case 5:
                dispstr="错误代码:5,密码错误!";
                break;
            case 8:
                dispstr="错误代码:8,卡不在感应区 或 密码不正确,请重新拿开卡后再放到感应区!";
                break;
            case 23:
                dispstr="错误代码:23,发卡器未连接!";
                break;
            default:
                dispstr="未知错误,错误代码:"+Integer.toString(errcode);
                break;
        }
       return dispstr;
    }

}

源码下载:AndroidstudioRFIDNFC读写源码资源-CSDN文库

  • 9
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

津津有味道

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值