Android Studio读写低频RFID T5557卡源码

2024-01-18 11:12

本文主要是介绍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.Toolbarandroid: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"><TextViewandroid: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" /><TextViewandroid: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><TextViewandroid: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"/><ScrollViewandroid: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.ConstraintLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:padding="3dp" ><CheckBoxandroid: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"/><EditTextandroid: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"/><TextViewandroid: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"/><CheckBoxandroid: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"/><EditTextandroid: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" /><TextViewandroid: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"/><TextViewandroid: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"/><Buttonandroid: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" /><Buttonandroid: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" /><TextViewandroid: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"/><EditTextandroid: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" /><TextViewandroid: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"/><TextViewandroid: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"/><CheckBoxandroid: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"/><CheckBoxandroid: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"/><CheckBoxandroid: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"/><CheckBoxandroid: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"/><CheckBoxandroid: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"/><CheckBoxandroid: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"/><CheckBoxandroid: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" /><CheckBoxandroid: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"/><TextViewandroid: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"/><CheckBoxandroid: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" /><CheckBoxandroid: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" /><CheckBoxandroid: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" /><CheckBoxandroid: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" /><Buttonandroid: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" /><Buttonandroid: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" /><TextViewandroid: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" /><EditTextandroid: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" /><TextViewandroid: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" /><CheckBoxandroid: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"/><CheckBoxandroid: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"/><CheckBoxandroid: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"/><EditTextandroid: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"/><TextViewandroid: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"/><TextViewandroid: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" /><EditTextandroid: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"/><TextViewandroid: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"/><Buttonandroid: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" /><Buttonandroid: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"/><Buttonandroid: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"/><TextViewandroid: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;    //操作成功后重启卡片@Overrideprotected 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("操作结果");}@Overridepublic 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)) {//启用密码功能后,最大块不能为7Configdata[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;}}

 

 

这篇关于Android Studio读写低频RFID T5557卡源码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/618804

相关文章

Eclipse+ADT与Android Studio开发的区别

下文的EA指Eclipse+ADT,AS就是指Android Studio。 就编写界面布局来说AS可以边开发边预览(所见即所得,以及多个屏幕预览),这个优势比较大。AS运行时占的内存比EA的要小。AS创建项目时要创建gradle项目框架,so,创建项目时AS比较慢。android studio基于gradle构建项目,你无法同时集中管理和维护多个项目的源码,而eclipse ADT可以同时打开

android 免费短信验证功能

没有太复杂的使用的话,功能实现比较简单粗暴。 在www.mob.com网站中可以申请使用免费短信验证功能。 步骤: 1.注册登录。 2.选择“短信验证码SDK” 3.下载对应的sdk包,我这是选studio的。 4.从头像那进入后台并创建短信验证应用,获取到key跟secret 5.根据技术文档操作(initSDK方法写在setContentView上面) 6.关键:在有用到的Mo

android一键分享功能部分实现

为什么叫做部分实现呢,其实是我只实现一部分的分享。如新浪微博,那还有没去实现的是微信分享。还有一部分奇怪的问题:我QQ分享跟QQ空间的分享功能,我都没配置key那些都是原本集成就有的key也可以实现分享,谁清楚的麻烦详解下。 实现分享功能我们可以去www.mob.com这个网站集成。免费的,而且还有短信验证功能。等这分享研究完后就研究下短信验证功能。 开始实现步骤(新浪分享,以下是本人自己实现

Android我的二维码扫描功能发展史(完整)

最近在研究下二维码扫描功能,跟据从网上查阅的资料到自己勉强已实现扫描功能来一一介绍我的二维码扫描功能实现的发展历程: 首页通过网络搜索发现做android二维码扫描功能看去都是基于google的ZXing项目开发。 2、搜索怎么使用ZXing实现自己的二维码扫描:从网上下载ZXing-2.2.zip以及core-2.2-source.jar文件,分别解压两个文件。然后把.jar解压出来的整个c

android 带与不带logo的二维码生成

该代码基于ZXing项目,这个网上能下载得到。 定义的控件以及属性: public static final int SCAN_CODE = 1;private ImageView iv;private EditText et;private Button qr_btn,add_logo;private Bitmap logo,bitmap,bmp; //logo图标private st

Android多线程下载见解

通过for循环开启N个线程,这是多线程,但每次循环都new一个线程肯定很耗内存的。那可以改用线程池来。 就以我个人对多线程下载的理解是开启一个线程后: 1.通过HttpUrlConnection对象获取要下载文件的总长度 2.通过RandomAccessFile流对象在本地创建一个跟远程文件长度一样大小的空文件。 3.通过文件总长度/线程个数=得到每个线程大概要下载的量(线程块大小)。

springboot家政服务管理平台 LW +PPT+源码+讲解

3系统的可行性研究及需求分析 3.1可行性研究 3.1.1技术可行性分析 经过大学四年的学习,已经掌握了JAVA、Mysql数据库等方面的编程技巧和方法,对于这些技术该有的软硬件配置也是齐全的,能够满足开发的需要。 本家政服务管理平台采用的是Mysql作为数据库,可以绝对地保证用户数据的安全;可以与Mysql数据库进行无缝连接。 所以,家政服务管理平台在技术上是可以实施的。 3.1

Visual Studio中,MSBUild版本问题

假如项目规定了MSBUild版本,那么在安装完Visual Studio后,假如带的MSBUild版本与项目要求的版本不符合要求,那么可以把需要的MSBUild添加到系统中,然后即可使用。步骤如下:            假如项目需要使用V12的MSBUild,而安装的Visual Studio带的MSBUild版本为V14。 ①到MSDN下载V12 MSBUild包,把V12包解压到目录(

时间服务器中,适用于国内的 NTP 服务器地址,可用于时间同步或 Android 加速 GPS 定位

NTP 是什么?   NTP 是网络时间协议(Network Time Protocol),它用来同步网络设备【如计算机、手机】的时间的协议。 NTP 实现什么目的?   目的很简单,就是为了提供准确时间。因为我们的手表、设备等,经常会时间跑着跑着就有误差,或快或慢的少几秒,时间长了甚至误差过分钟。 NTP 服务器列表 最常见、熟知的就是 www.pool.ntp.org/zo

高仿精仿愤怒的小鸟android版游戏源码

这是一款很完美的高仿精仿愤怒的小鸟android版游戏源码,大家可以研究一下吧、 为了报复偷走鸟蛋的肥猪们,鸟儿以自己的身体为武器,仿佛炮弹一样去攻击肥猪们的堡垒。游戏是十分卡通的2D画面,看着愤怒的红色小鸟,奋不顾身的往绿色的肥猪的堡垒砸去,那种奇妙的感觉还真是令人感到很欢乐。而游戏的配乐同样充满了欢乐的感觉,轻松的节奏,欢快的风格。 源码下载