Android Studio安卓读写NFC Ntag标签源码

news2024/9/20 6:17:31

本示例使用的发卡器: https://item.taobao.com/item.htm?spm=a1z10.5-c-s.w4002-21818769070.11.3513789erHXVGx&id=615391857885

<?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=".NtagActivity">
    <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="ntag213、215、216卡、复旦11rf32测试页"
            android:textColor="@color/white"
            android:gravity="center_horizontal|bottom"
            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="120dp"
        android:padding="3dp"
        android:text="操作结果"
        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"
            >

            <Button
                android:id="@+id/butt_requestntag"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:text="搜寻Ntag卡获取卡号"
                android:textSize="12sp"
                android:onClick="RequestNtag"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toTopOf="parent"  />

            <TextView
                android:id="@+id/textViewtitleuid"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:text="UID:"
                app:layout_constraintBottom_toBottomOf="@+id/butt_requestntag"
                app:layout_constraintLeft_toRightOf="@+id/butt_requestntag"
                app:layout_constraintTop_toTopOf="@+id/butt_requestntag" />

            <TextView
                android:id="@+id/textViewuid"
                android:layout_width="130dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:background="@drawable/shape4border"
                android:gravity="center"
                android:textColor="#FF0000"
                android:text=""
                app:layout_constraintBottom_toBottomOf="@+id/textViewtitleuid"
                app:layout_constraintLeft_toRightOf="@+id/textViewtitleuid"
                app:layout_constraintTop_toTopOf="@+id/textViewtitleuid" />

            <Button
                android:id="@+id/butt_getversiontype"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:onClick="getversiontype"
                android:text="卡片版本及型号"
                android:textSize="12sp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/butt_requestntag" />

            <Button
                android:id="@+id/butt_getsign"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:onClick="getcardsign"
                android:text="卡片签名信息"
                android:textSize="12sp"
                app:layout_constraintBottom_toBottomOf="@+id/butt_getversiontype"
                app:layout_constraintLeft_toRightOf="@+id/butt_getversiontype"
                app:layout_constraintTop_toTopOf="@+id/butt_getversiontype" />

            <Button
                android:id="@+id/butt_getcountervalue"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:onClick="getcountervalue"
                android:text="卡片单向计数器值"
                android:textSize="11sp"
                app:layout_constraintBottom_toBottomOf="@+id/butt_getsign"
                app:layout_constraintLeft_toRightOf="@+id/butt_getsign"
                app:layout_constraintTop_toTopOf="@+id/butt_getsign" />

            <Button
                android:id="@+id/butt_getStaticlock"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:onClick="getStaticlock"
                android:text="读取卡片静态锁值"
                android:textSize="12sp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/butt_getversiontype" />

            <TextView
                android:id="@+id/textViewtitlelock"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:text="静态锁标识:"
                app:layout_constraintBottom_toBottomOf="@+id/butt_getStaticlock"
                app:layout_constraintLeft_toRightOf="@+id/butt_getStaticlock"
                app:layout_constraintTop_toTopOf="@+id/butt_getStaticlock" />

            <EditText
                android:id="@+id/edit_Staticlock"
                android:layout_width="120dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="2dp"
                android:background="@drawable/shape4border"
                android:digits="01"
                android:gravity="center"
                android:inputType="textCapCharacters"
                android:maxLength="16"
                android:text="0000000000000000"
                android:textColor="#0000FF"
                android:textSize="12sp"
                app:layout_constraintBottom_toBottomOf="@+id/textViewtitlelock"
                app:layout_constraintLeft_toRightOf="@+id/textViewtitlelock"
                app:layout_constraintTop_toTopOf="@+id/textViewtitlelock" />

            <Button
                android:id="@+id/butt_Staticlock"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:onClick="Staticlock"
                android:text="将卡片加上静态锁"
                android:textSize="12sp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/butt_getStaticlock" />

            <TextView
                android:id="@+id/textViewtitlenote"
                android:layout_width="250dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:text="警告:16位静态锁标识代表0-15块的锁定状态,0表示块未锁定、1表示块锁定,块如果锁定将不能再次修改!"
                android:textColor="#FF0000"
                app:layout_constraintBottom_toBottomOf="@+id/butt_Staticlock"
                app:layout_constraintLeft_toRightOf="@+id/butt_Staticlock"
                app:layout_constraintTop_toTopOf="@+id/butt_Staticlock" />

            <CheckBox
                android:id="@+id/check_seleauthkeyen"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:text="选择先认证密钥再继续以下操作,8位16进制认证密钥:"
                android:textColor="#0000FF"
                android:textSize="11sp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/butt_Staticlock" />

            <EditText
                android:id="@+id/edit_authkey"
                android:layout_width="70dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="4dp"
                android:background="@drawable/shape4border"
                android:digits="0123456789ABCDEFabcdef"
                android:textColor="#FF0000"
                android:gravity="center"
                android:inputType="textCapCharacters"
                android:maxLength="8"
                android:maxLines="1"
                android:text="12345678"
                android:textSize="12sp"
                app:layout_constraintBottom_toBottomOf="@+id/check_seleauthkeyen"
                app:layout_constraintLeft_toRightOf="@+id/check_seleauthkeyen"
                app:layout_constraintTop_toTopOf="@+id/check_seleauthkeyen" />

            <Button
                android:id="@+id/butt_initntag"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:onClick="InitNtagCard"
                android:text="设置Ntag卡密钥机制"
                android:textSize="12sp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/check_seleauthkeyen" />

            <Spinner
                android:id="@+id/spin_seleopencloskey"
                android:layout_width="220dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="8dp"
                android:entries="@array/NtagKeyEn"
                android:theme="@style/my_spinner_style"
                app:layout_constraintLeft_toRightOf="@+id/butt_initntag"
                app:layout_constraintTop_toTopOf="@+id/butt_initntag" />

            <Spinner
                android:id="@+id/spin_selereadauth"
                android:layout_width="220dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="8dp"
                android:entries="@array/NtagReadAuthEn"
                android:theme="@style/my_spinner_style"
                app:layout_constraintBottom_toBottomOf="@+id/butt_initntag"
                app:layout_constraintLeft_toRightOf="@+id/butt_initntag" />

            <TextView
                android:id="@+id/textViewtitlefrom"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="3dp"
                android:textSize="12sp"
                android:text="选择从第:"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/butt_initntag" />

            <EditText
                android:id="@+id/edit_initbeginblock"
                android:layout_width="50dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="4dp"
                android:background="@drawable/shape4border"
                android:digits="0123456789"
                android:gravity="center"
                android:textColor="#FF0000"
                android:inputType="textCapCharacters"
                android:maxLength="4"
                android:maxLines="1"
                android:text="20"
                android:textSize="12sp"
                app:layout_constraintBottom_toBottomOf="@+id/textViewtitlefrom"
                app:layout_constraintLeft_toRightOf="@+id/textViewtitlefrom"
                app:layout_constraintTop_toTopOf="@+id/textViewtitlefrom" />

            <TextView
                android:id="@+id/textViewtitle0"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="2dp"
                android:layout_marginTop="3dp"
                android:text="块开始有密钥保护功能,卡片新密钥:"
                android:textSize="12sp"
                app:layout_constraintBottom_toBottomOf="@+id/edit_initbeginblock"
                app:layout_constraintLeft_toRightOf="@+id/edit_initbeginblock"
                app:layout_constraintTop_toTopOf="@+id/edit_initbeginblock" />

            <EditText
                android:id="@+id/edit_newkey"
                android:layout_width="70dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="4dp"
                android:background="@drawable/shape4border"
                android:digits="0123456789ABCDEFabcdef"
                android:textColor="#FF0000"
                android:gravity="center"
                android:inputType="textCapCharacters"
                android:maxLength="8"
                android:maxLines="1"
                android:text="12345678"
                android:textSize="12sp"
                app:layout_constraintBottom_toBottomOf="@+id/textViewtitle0"
                app:layout_constraintLeft_toRightOf="@+id/textViewtitle0"
                app:layout_constraintTop_toTopOf="@+id/textViewtitle0" />

            <TextView
                android:id="@+id/textViewpack"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="3dp"
                android:textSize="12sp"
                android:text="PACK密钥确认码:"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/textViewtitlefrom" />

            <EditText
                android:id="@+id/edit_packkey"
                android:layout_width="40dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="4dp"
                android:background="@drawable/shape4border"
                android:digits="0123456789ABCDEFabcdef"
                android:gravity="center"
                android:textColor="#FF0000"
                android:inputType="textCapCharacters"
                android:maxLength="4"
                android:maxLines="1"
                android:text="1616"
                android:textSize="12sp"
                app:layout_constraintBottom_toBottomOf="@+id/textViewpack"
                app:layout_constraintLeft_toRightOf="@+id/textViewpack"
                app:layout_constraintTop_toTopOf="@+id/textViewpack" />

            <TextView
                android:id="@+id/textViewtitle1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="2dp"
                android:layout_marginTop="3dp"
                android:text=",允许密钥认证失败次数(0不限制):"
                android:textSize="12sp"
                app:layout_constraintBottom_toBottomOf="@+id/edit_packkey"
                app:layout_constraintLeft_toRightOf="@+id/edit_packkey"
                app:layout_constraintTop_toTopOf="@+id/edit_packkey" />

            <EditText
                android:id="@+id/edit_limitauthfailed"
                android:layout_width="40dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="4dp"
                android:background="@drawable/shape4border"
                android:digits="0123456789"
                android:gravity="center"
                android:inputType="textCapCharacters"
                android:maxLength="4"
                android:maxLines="1"
                android:text="0"
                android:textColor="#FF0000"
                android:textSize="12sp"
                app:layout_constraintBottom_toBottomOf="@+id/textViewtitle1"
                app:layout_constraintLeft_toRightOf="@+id/textViewtitle1"
                app:layout_constraintTop_toTopOf="@+id/textViewtitle1" />

            <Button
                android:id="@+id/butt_readntag"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:text="轻松从Ntag卡读数据"
                android:textSize="12sp"
                android:onClick="ReadNtagCard"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/textViewpack" />

            <Button
                android:id="@+id/butt_writentag"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="轻松写数据到Ntag卡"
                android:textSize="12sp"
                android:onClick="WriteNtagCard"
                app:layout_constraintBottom_toBottomOf="@+id/butt_readntag"
                app:layout_constraintLeft_toRightOf="@+id/butt_readntag"
                app:layout_constraintTop_toTopOf="@+id/butt_readntag" />

            <TextView
                android:id="@+id/textViewtitle2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="3dp"
                android:text="本次读写操作起始块:"
                android:textSize="12sp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/butt_readntag" />

            <EditText
                android:id="@+id/edit_RWbeginblock"
                android:layout_width="48dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="4dp"
                android:background="@drawable/shape4border"
                android:digits="0123456789"
                android:gravity="center"
                android:inputType="textCapCharacters"
                android:maxLength="4"
                android:maxLines="1"
                android:text="4"
                android:textColor="#FF0000"
                android:textSize="12sp"
                app:layout_constraintBottom_toBottomOf="@+id/textViewtitle2"
                app:layout_constraintLeft_toRightOf="@+id/textViewtitle2"
                app:layout_constraintTop_toTopOf="@+id/textViewtitle2" />

            <TextView
                android:id="@+id/textViewtitle3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="40dp"
                android:layout_marginTop="3dp"
                android:text="本次读写块数:"
                android:textSize="12sp"
                app:layout_constraintBottom_toBottomOf="@+id/edit_RWbeginblock"
                app:layout_constraintLeft_toRightOf="@+id/edit_RWbeginblock"
                app:layout_constraintTop_toTopOf="@+id/edit_RWbeginblock" />

            <EditText
                android:id="@+id/edit_RWblocks"
                android:layout_width="48dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="4dp"
                android:background="@drawable/shape4border"
                android:digits="0123456789"
                android:gravity="center"
                android:inputType="textCapCharacters"
                android:maxLength="4"
                android:maxLines="1"
                android:text="10"
                android:textColor="#FF0000"
                android:textSize="12sp"
                app:layout_constraintBottom_toBottomOf="@+id/textViewtitle3"
                app:layout_constraintLeft_toRightOf="@+id/textViewtitle3"
                app:layout_constraintTop_toTopOf="@+id/textViewtitle3" />

            <TextView
                android:id="@+id/textViewtitle4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="3dp"
                android:text="读写标签内数据:"
                android:textSize="12sp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/textViewtitle2" />

            <EditText
                android:id="@+id/edit_rwdata"
                android:layout_width="match_parent"
                android:layout_height="130dp"
                android:background="@drawable/shape4border"
                android:digits="0123456789ABCDEFabcdef "
                android:inputType="textCapCharacters"
                android:maxLines="8"
                android:gravity="left"
                android:text="00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
                android:textSize="12sp"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/textViewtitle4" />


        </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.ourmifare;

public class NtagActivity extends AppCompatActivity {
    private TextView tv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ntag);

        androidx.appcompat.widget.Toolbar toolbar=findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        tv = findViewById(R.id.sample_text);
        tv.setText("操作结果");

        Spinner spls = findViewById(R.id.spin_seleopencloskey);
        spls.setSelection(1);
    }

    @Override
    public void onBackPressed(){
        super.onBackPressed();
        finish();
    }

    @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 RequestNtag(View view){
        byte status;                          //存放返回值
        byte[] mypiccserial = new byte[7];    //7字节卡号

        tv.setText("");
        TextView ctruid=findViewById(R.id.textViewuid);
        ctruid.setText("");

        status = ourmifare.piccrequestul(mypiccserial);//& 0xff用于转为无符号行数据

        if (status == 0) {
            ourmifare.pcdbeep(38);
            String uidstr = "";
            for (int i = 0; i < 7; i++) {
                String bytestr = "00" + Integer.toHexString(mypiccserial[i] & 0xff);
                uidstr = uidstr + bytestr.substring(bytestr.length() - 2, bytestr.length()) ;
            }
            ctruid.setText(uidstr);
            tv.setText("获取7字节卡序号:" + uidstr);
        } else {
            PrintErrInf(status);   //返回代码提示
        }
    }

    public void getversiontype(View view){
        byte status;                          //存放返回值
        byte[] mypiccserial = new byte[7];    //7字节卡号
        byte[] mypiccversiondata=new byte[8];

        tv.setText("");
        TextView ctruid=findViewById(R.id.textViewuid);
        ctruid.setText("");

        status = ourmifare.piccrequestul(mypiccserial);

        if (status == 0) {
            String uidstr = "";
            for (int i = 0; i < 7; i++) {
                String bytestr = "00" + Integer.toHexString(mypiccserial[i] & 0xff);
                uidstr = uidstr + bytestr.substring(bytestr.length() - 2, bytestr.length()) ;
            }
            ctruid.setText(uidstr);

            status = ourmifare.piccgetversionntag(mypiccversiondata);
            if (status == 0) {
                ourmifare.pcdbeep(38);
                String verdstr = "";
                for (int i = 0; i < 8; i++) {
                    String bytestr = "00" + Integer.toHexString(mypiccversiondata[i] & 0xff);
                    verdstr = verdstr + bytestr.substring(bytestr.length() - 2, bytestr.length()) + " ";
                }
                tv.setText("读取卡片版本型号成功!"+"\n卡片序号:" + uidstr+"\n"+"版本型号:"+verdstr);
            }else {
                PrintErrInf(status);   //返回代码提示
            }
        } else {
            PrintErrInf(status);   //返回代码提示
        }
    }

    public void getcardsign(View view){
        byte status;                          //存放返回值
        byte[] mypiccserial = new byte[7];    //7字节卡号
        byte[] piccsigdata=new byte[32];

        tv.setText("");
        TextView ctruid=findViewById(R.id.textViewuid);
        ctruid.setText("");

        status = ourmifare.piccrequestul(mypiccserial);

        if (status == 0) {
            String uidstr = "";
            for (int i = 0; i < 7; i++) {
                String bytestr = "00" + Integer.toHexString(mypiccserial[i] & 0xff);
                uidstr = uidstr + bytestr.substring(bytestr.length() - 2, bytestr.length()) ;
            }
            ctruid.setText(uidstr);

            status = ourmifare.piccgetversionntag(piccsigdata);
            if (status == 0) {
                ourmifare.pcdbeep(38);
                String verdstr = "";
                for (int i = 0; i < 32; i++) {
                    String bytestr = "00" + Integer.toHexString(piccsigdata[i] & 0xff);
                    verdstr = verdstr + bytestr.substring(bytestr.length() - 2, bytestr.length()) + " ";
                }
                tv.setText("读取卡片签名信息成功!"+"\n卡片序号:" + uidstr+"\n"+"签名信息:"+verdstr);
            }else {
                PrintErrInf(status);   //返回代码提示
            }
        } else {
            PrintErrInf(status);   //返回代码提示
        }
    }
    public void getcountervalue(View view){
        byte status;                          //存放返回值
        byte[] mypiccserial = new byte[7];    //7字节卡号
        byte[] mypicccntdata=new byte[3];

        tv.setText("");
        TextView ctruid=findViewById(R.id.textViewuid);
        ctruid.setText("");

        status = ourmifare.piccrequestul(mypiccserial);

        if (status == 0) {
            String uidstr = "";
            for (int i = 0; i < 7; i++) {
                String bytestr = "00" + Integer.toHexString(mypiccserial[i] & 0xff);
                uidstr = uidstr + bytestr.substring(bytestr.length() - 2, bytestr.length()) ;
            }
            ctruid.setText(uidstr);

            status = ourmifare.piccreadcntntag(mypicccntdata);
            if (status == 0) {
                ourmifare.pcdbeep(38);
                String verdstr = "";
                for (int i = 0; i < 3; i++) {
                    String bytestr = "00" + Integer.toHexString(mypicccntdata[i] & 0xff);
                    verdstr = verdstr + bytestr.substring(bytestr.length() - 2, bytestr.length()) + " ";
                }
                tv.setText("读取卡片单向计数器值成功!"+"\n卡片序号:" + uidstr+"\n"+"计数器值:"+verdstr);
            }else {
                tv.setText("读取卡片单向计数器值失败!错误代码:"+Integer.toString(status)+"\n卡片序号:" + uidstr+"\n"+"可能是计数器功能尚未启用或卡本身不支持计数功能!");
            }
        } else {
            PrintErrInf(status);   //返回代码提示
        }
    }

    public void getStaticlock(View view){
        byte status;                          //存放返回值
        byte[] mypiccserial = new byte[7];    //7字节卡号
        byte[] mypiccdata=new byte[16];

        tv.setText("");
        TextView ctruid=findViewById(R.id.textViewuid);
        ctruid.setText("");

        status = ourmifare.piccrequestul(mypiccserial);
        if (status == 0) {
            String uidstr = "";
            for (int i = 0; i < 7; i++) {
                String bytestr = "00" + Integer.toHexString(mypiccserial[i] & 0xff);
                uidstr = uidstr + bytestr.substring(bytestr.length() - 2, bytestr.length());
            }
            ctruid.setText(uidstr);

            status = ourmifare.piccreadul((byte) 0,mypiccdata);
            if (status == 0) {
                ourmifare.pcdbeep(38);
                String verdstr = "";
                for (int i = 10; i < 12; i++) {
                    String bytestr = "00000000" + Integer.toBinaryString(mypiccdata[i] & 0xff);
                    verdstr = verdstr + bytestr.substring(bytestr.length() - 8, bytestr.length()) ;
                }
                EditText ctrstationlock=findViewById(R.id.edit_Staticlock);
                ctrstationlock.setText(verdstr);

                String tagtypestr="";
                switch(mypiccdata[14]){
                    case 0x12:
                        tagtypestr="Ntag213,144 Bytes";
                        break;
                    case 0x3e:
                        tagtypestr="Ntag215,504 Bytes";
                        break;
                    case 0x6D:
                        tagtypestr="Ntag216,888 Bytes";
                        break;
                    default:
                        tagtypestr="OtherNtag";
                        break;
                }
                tv.setText("读取卡片静态锁标识成功!"+"\n卡片序号:" + uidstr+"\n芯片类型:"+tagtypestr+"\n静态锁标识:"+verdstr);
            }else {
                PrintErrInf(status);   //返回代码提示
            }
        } else {
            PrintErrInf(status);   //返回代码提示
        }
    }

    public void Staticlock(View view){
        byte status;                          //存放返回值
        byte[] mypiccserial = new byte[7];    //7字节卡号
        byte[] mypiccdata=new byte[4];

        tv.setText("");
        TextView ctruid=findViewById(R.id.textViewuid);
        ctruid.setText("");

        EditText ctrstaticlock=findViewById(R.id.edit_Staticlock);
        String staticlockstr=ctrstaticlock.getText().toString().trim();
        if (staticlockstr.length()!=16){
            tv.setText("静态锁标识输入错误,请输入16位2进制静态锁标识值!");
            return;
        }
        status = ourmifare.piccrequestul(mypiccserial);
        if (status == 0) {
            String uidstr = "";
            for (int i = 0; i < 7; i++) {
                String bytestr = "00" + Integer.toHexString(mypiccserial[i] & 0xff);
                uidstr = uidstr + bytestr.substring(bytestr.length() - 2, bytestr.length());
            }
            ctruid.setText(uidstr);

            mypiccdata[0]=0;
            mypiccdata[1]=0;
            mypiccdata[2]=(byte)Integer.parseInt(staticlockstr.substring(0,8),2);
            mypiccdata[3]=(byte)Integer.parseInt(staticlockstr.substring(staticlockstr.length() - 8, staticlockstr.length()),2);
            status = ourmifare.picclockntag((byte) 0,mypiccdata);
            if (status == 0) {
                ourmifare.pcdbeep(38);
                tv.setText("卡片加入静态锁成功!"+"\n卡片序号:" + uidstr+"\n");
            }else {
                PrintErrInf(status);   //返回代码提示
            }
        } else {
            PrintErrInf(status);   //返回代码提示
        }
    }
    public void InitNtagCard(View view){
        byte status;                          //存放返回值
        byte[] mypicckey = new byte[4];      //4个字节的卡旧密码
        byte[] newPickey = new byte[44];     //4个字节的新密码
        byte[] mypiccserial = new byte[7];   //7字节卡号
        byte ReadNeedKey = 0;                //取值0读卡不需要认证密码,非0读卡也要认证密码
        byte myctrlword ;                    //取值0不需要认证密码,16要认证卡密码  对卡操作
        byte KeyErrNum=0;                    //对卡操作允许密码错误次数(0为不限次)
        byte[] mypiccdata=new byte[16];      //本次对卡的配置信息

        tv.setText("");

        TextView ctruid=findViewById(R.id.textViewuid);
        ctruid.setText("");

        CheckBox ctrauthen=findViewById(R.id.check_seleauthkeyen);
        if (ctrauthen.isChecked()){
            myctrlword=16;
            EditText ctrauthkey=findViewById(R.id.edit_authkey);
            String authkeystr=ctrauthkey.getText().toString().trim();
            if (authkeystr.length() != 8)
            {
                tv.setText("认证密钥是8位16进制数据,请输入正确的认证密钥!");
                return;
            }else {
                for (int i = 0; i < 4; i++) {
                    mypicckey[i] = (byte) Integer.parseInt(authkeystr.substring(i * 2, i * 2 + 2), 16);//只有用Integer.parseInt才能杜绝大于128时的错误
                }
            }
        }else{myctrlword=0;}

        EditText ctrbeginblock=findViewById(R.id.edit_initbeginblock);
        byte beginblock=(byte) Integer.parseInt(ctrbeginblock.getText().toString().trim());

        EditText ctrliminub=findViewById(R.id.edit_limitauthfailed);
        KeyErrNum=(byte) Integer.parseInt(ctrliminub.getText().toString().trim());

        Spinner ctrreadkeyen=findViewById(R.id.spin_selereadauth);
        ReadNeedKey=(byte)ctrreadkeyen.getSelectedItemId();

        Spinner spls = findViewById(R.id.spin_seleopencloskey);
        if (spls.getSelectedItemId()==0){       //卡片开启密码保护功能,开启后要记住卡密码,否则卡报废!!!
            myctrlword=(byte)(myctrlword+4);
            mypiccdata[3]=beginblock;           //配置:密码保护起始页,要根据不同类型的卡来设置
            myctrlword=(byte)(myctrlword+1);

            mypiccdata[4]=(byte)(KeyErrNum % 8); //配置:最大卡密码认证错误次数
            if(ReadNeedKey>0){                   //配置:读卡时需要认证卡密码
                mypiccdata[4]=(byte)(mypiccdata[4]+(byte)(0x80));
            }
            myctrlword=(byte)(myctrlword+2);   //配置:启用计数器

            EditText ctrnewkey=findViewById(R.id.edit_newkey);
            String newkeystr=ctrnewkey.getText().toString().trim();
            if (newkeystr.length() != 8)
            {
                tv.setText("密钥是8位16进制数据,请输入正确的新密钥!");
                return;
            }else {
                for (int i = 0; i < 4; i++) {
                    newPickey[i] = (byte) Integer.parseInt(newkeystr.substring(i * 2, i * 2 + 2), 16);//只有用Integer.parseInt才能杜绝大于128时的错误
                    mypiccdata[8+i]= (byte) Integer.parseInt(newkeystr.substring(i * 2, i * 2 + 2), 16);//只有用Integer.parseInt才能杜绝大于128时的错误
                }
            }

            EditText ctrpack=findViewById(R.id.edit_packkey);
            String packkeystr=ctrpack.getText().toString().trim();
            if (packkeystr.length() != 4)
            {
                tv.setText("PACK密钥确认码是4位16进制数据,请输入正确的密钥确认码!");
                return;
            }else {
                for (int i = 0; i < 2; i++) {
                    mypiccdata[12+i] = (byte) Integer.parseInt(packkeystr.substring(i * 2, i * 2 + 2), 16);//只有用Integer.parseInt才能杜绝大于128时的错误
                }
            }
        }else{   //卡片取消密码保护功能
            mypiccdata[3]=(byte)(0xff);
            myctrlword=(byte)(myctrlword+1);
            myctrlword=(byte)(myctrlword+2);
        }

        status = ourmifare.piccinitntag(myctrlword,mypiccserial,mypicckey,mypiccdata) ;
        if (status == 0) {
            ourmifare.pcdbeep(38);
            String uidstr = "";
            for (int i = 0; i < 7; i++) {
                String bytestr = "00" + Integer.toHexString(mypiccserial[i] & 0xff);
                uidstr = uidstr + bytestr.substring(bytestr.length() - 2, bytestr.length()) ;
            }
            ctruid.setText(uidstr);
            tv.setText("设置卡密码及保护机制成功!"+"\n卡片序号:" + uidstr);
        } else {
            PrintErrInf(status);   //返回代码提示
        }
    }

    public void ReadNtagCard(View view){
        byte status=1;                       //存放返回值
        byte[] mypiccserial = new byte[7];   //7字节卡号
        byte[] mypicckey=new byte[4];        //4个字节的卡密码
        byte[] mypiccdata=new byte[48];      //48个字节读卡的数据缓冲
        byte myblockaddr;                    //读起始页地址
        byte myblocksize;                    //读卡页数
        byte myctrlword;                     //取值0不认证密码,16要认证卡密码

        tv.setText("");

        TextView ctruid=findViewById(R.id.textViewuid);
        ctruid.setText("");

        EditText ctrrwdata=findViewById(R.id.edit_rwdata);
        ctrrwdata.setText("");

        CheckBox ctrauthen=findViewById(R.id.check_seleauthkeyen);
        if (ctrauthen.isChecked()){
            myctrlword=16;
            EditText ctrauthkey=findViewById(R.id.edit_authkey);
            String authkeystr=ctrauthkey.getText().toString().trim();
            if (authkeystr.length() != 8)
            {
                tv.setText("认证密钥是8位16进制数据,请输入正确的认证密钥!");
                return;
            }else {
                for (int i = 0; i < 4; i++) {
                    mypicckey[i] = (byte) Integer.parseInt(authkeystr.substring(i * 2, i * 2 + 2), 16);//只有用Integer.parseInt才能杜绝大于128时的错误
                }
            }
        }else{myctrlword=0;}

        EditText ctrblokadd=findViewById(R.id.edit_RWbeginblock);
        myblockaddr=(byte)Integer.parseInt(ctrblokadd.getText().toString().trim());

        EditText ctrbloknum=findViewById(R.id.edit_RWblocks);
        myblocksize=(byte)Integer.parseInt(ctrbloknum.getText().toString().trim());

        //使用循环的方式读取,每次读一个块,这样可以连续读取标签N个块数据
        if (myblocksize<1){
            tv.setText("请输入本次读写块数!");
            return;
        }
        int j=0;
        String readdatastr="";
        while (j<myblocksize){
            status = ourmifare.piccreadexntag(myctrlword,mypiccserial,mypicckey,(byte)(myblockaddr+j),(byte)1,mypiccdata) ;
            if (status==0){
                for (int i=0;i<4;i++ ){
                    String bytestr = "00" + Integer.toHexString(mypiccdata[i] & 0xFF);
                    readdatastr = readdatastr + bytestr.substring(bytestr.length() - 2, bytestr.length())+" ";
                }
                j++;
            }else{ j=myblocksize;}
        }

        if (status == 0) {
            ourmifare.pcdbeep(38);
            String uidstr = "";
            for (int i = 0; i < 7; i++) {
                String bytestr = "00" + Integer.toHexString(mypiccserial[i] & 0xFF);
                uidstr = uidstr + bytestr.substring(bytestr.length() - 2, bytestr.length()) ;
            }
            ctruid.setText(uidstr);
            ctrrwdata.setText(readdatastr);
            tv.setText("读取Ntag卡块数据成功!"+"\n卡片序号:" + uidstr);
        } else {
            PrintErrInf(status);   //返回代码提示
        }


/*      执行一次读卡操作,每次最多可以读12个块
        if (myblocksize<1 || myblocksize>12){
            tv.setText("读写块数必须>=1,13<=");
            return;
        }
        status = ourmifare.piccreadexntag(myctrlword,mypiccserial,mypicckey,myblockaddr,myblocksize,mypiccdata) ;
        if (status == 0) {
            ourmifare.pcdbeep(38);
            String uidstr = "";
            for (int i = 0; i < 7; i++) {
                String bytestr = "00" + Integer.toHexString(mypiccserial[i] & 0xFF);
                uidstr = uidstr + bytestr.substring(bytestr.length() - 2, bytestr.length()) ;
            }
            ctruid.setText(uidstr);

            String databuf="";
            for (int i = 0; i < myblocksize*4; i++) {
                String bytestr = "00" + Integer.toHexString(mypiccdata[i] & 0xFF);
                databuf = databuf + bytestr.substring(bytestr.length() - 2, bytestr.length()) + " ";
            }
            ctrrwdata.setText(databuf);
            tv.setText("读取Ntag卡块数据成功!"+"\n卡片序号:" + uidstr);
        } else {
            PrintErrInf(status);   //返回代码提示
        }*/
    }

    public void WriteNtagCard(View view){
        byte status=1;                       //存放返回值
        byte[] mypiccserial = new byte[7];   //7字节卡号
        byte[] mypicckey=new byte[4];        //4个字节的卡密码
        byte[] mypiccdata=new byte[48];      //48个字节读卡的数据缓冲
        byte myblockaddr;                    //读起始页地址
        byte myblocksize;                    //读卡页数
        byte myctrlword;                     //取值0不认证密码,16要认证卡密码

        tv.setText("");

        TextView ctruid=findViewById(R.id.textViewuid);
        ctruid.setText("");

        CheckBox ctrauthen=findViewById(R.id.check_seleauthkeyen);
        if (ctrauthen.isChecked()){
            myctrlword=16;
            EditText ctrauthkey=findViewById(R.id.edit_authkey);
            String authkeystr=ctrauthkey.getText().toString().trim();
            if (authkeystr.length() != 8)
            {
                tv.setText("认证密钥是8位16进制数据,请输入正确的认证密钥!");
                return;
            }else {
                for (int i = 0; i < 4; i++) {
                    mypicckey[i] = (byte) Integer.parseInt(authkeystr.substring(i * 2, i * 2 + 2), 16);//只有用Integer.parseInt才能杜绝大于128时的错误
                }
            }
        }else{myctrlword=0;}

        EditText ctrblokadd=findViewById(R.id.edit_RWbeginblock);
        myblockaddr=(byte)Integer.parseInt(ctrblokadd.getText().toString().trim());

        EditText ctrbloknum=findViewById(R.id.edit_RWblocks);
        myblocksize=(byte)Integer.parseInt(ctrbloknum.getText().toString().trim());
        if (myblocksize<1){
            tv.setText("请输入本次读写块数!");
            return;
        }

        EditText ctrrwdata=findViewById(R.id.edit_rwdata);
        String rwdatahex=ctrrwdata.getText().toString().trim();
        String[] strArr = rwdatahex.split("\\ ");    /*分割接收到的数据后再分析、处理、返回指令*/
        if (strArr.length<myblocksize*4) {
            tv.setText("写入数据不足,请输入" + Integer.toString(myblocksize*4 * 2) + "位16进制写入数据!");
            return;
        }

       //使用循环的方式写卡,每次写一个块,这样可以连续写入N个块数据
        int j=0;
        while (j<myblocksize) {
            for (int i=0;i<4;i++){
                mypiccdata[i]=(byte)(Integer.parseInt(strArr[j*4+i],16));
            }
            status = ourmifare.piccwriteexntag(myctrlword, mypiccserial, mypicckey, (byte)(myblockaddr+j), (byte)1, mypiccdata);
            if (status==0){
                j++;
            }else{j=myblocksize;}
        }
        if (status == 0) {
            ourmifare.pcdbeep(38);
            String uidstr = "";
            for (int i = 0; i < 7; i++) {
                String bytestr = "00" + Integer.toHexString(mypiccserial[i] & 0xFF);
                uidstr = uidstr + bytestr.substring(bytestr.length() - 2, bytestr.length()) ;
            }
            ctruid.setText(uidstr);
            tv.setText("写入Ntag卡块数据成功!"+"\n卡片序号:" + uidstr);
        } else {
            PrintErrInf(status);   //返回代码提示
        }


 /*     //执行一次写卡操作,每次最多可以读11个块
        if (myblocksize<1 || myblocksize>11){
            tv.setText("读写块数必须>=1,12<=");
            return;
        }
        for (int i=0;i<strArr.length;i++){
                mypiccdata[i]=(byte)(Integer.parseInt(strArr[i],16));
        }
        status = ourmifare.piccwriteexntag(myctrlword, mypiccserial, mypicckey, myblockaddr, myblocksize, mypiccdata);
        if (status == 0) {
            ourmifare.pcdbeep(38);
            String uidstr = "";
            for (int i = 0; i < 7; i++) {
                String bytestr = "00" + Integer.toHexString(mypiccserial[i] & 0xFF);
                uidstr = uidstr + bytestr.substring(bytestr.length() - 2, bytestr.length()) ;
            }
            ctruid.setText(uidstr);
            tv.setText("写入Ntag卡块数据成功!"+"\n卡片序号:" + uidstr);
        } else {
            PrintErrInf(status);   //返回代码提示
        }*/
    }



    public void PrintErrInf(byte errcode) {
        String dispstr="";
        switch(errcode){
            case 1:
                dispstr="错误代码:1,0~2块都没读出来,可能刷卡太块。但卡序列号已被读出来!";
                break;
            case 2:
                dispstr="错误代码:2,第0块已被读出,但1~2块读取失败。卡序列号已被读出来!";
                break;
            case 3:
                dispstr="错误代码:3,第0、1块已被读出,但2块读取失败。卡序列号已被读出来!";
                break;
            case 8:
                dispstr="错误代码:8,未寻到卡,请重新拿开卡后再放到感应区!";
                break;
            case 9:
                dispstr="错误代码:9,有多张卡在感应区,寻卡过程中防冲突失败,读序列吗错误!";
                break;
            case 10:
                dispstr="错误代码:10,该卡可能已被休眠,无法选中卡片!";
                break;
            case 11:
                dispstr="错误代码:11,密码装载失败!";
                break;
            case 12:
                dispstr="错误代码:12,卡片密码认证失败!";
                break;
            case 13:
                dispstr="错误代码:13,读本块失败,原因是刷卡太快或本块所对应的区还没通过密码认证!";
                break;
            case 14:
                dispstr="错误代码:14,写本块失败,原因是刷卡太快或本块所对应的区还没通过密码认证!";
                break;
            case 21:
                dispstr="错误代码:21,没有动态库!";
                break;
            case 22:
                dispstr="错误代码:22,动态库或驱动程序异常!";
                break;
            case 23:
                dispstr="错误代码:23,发卡器尚未插入!";
                break;
            case 24:
                dispstr="错误代码:24,操作超时,一般是动态库没有反映!";
                break;
            case 25:
                System.out.print("错误代码:25,发送字数不够!");
                break;
            case 26:
                System.out.print("错误代码:26,发送的CRC错!");
                break;
            case 27:
                System.out.print("错误代码:27,接收的字数不够!");
                break;
            case 28:
                System.out.print("错误代码:28,接收的CRC错!");
                break;
            default:
                System.out.print("未知错误,错误代码:"+Integer.toString(errcode));
                break;
        }
        tv = findViewById(R.id.sample_text);
        tv.setText(dispstr);
    }
}

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1367726.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

5.2 Android BCC环境搭建(adeb版,下)更新中

五&#xff0c;运行adeb shell adeb shell 六&#xff0c;其他指令 6.1 从开发机移除adeb adeb remove 6.2 更新开发机adeb deb git-pull 6.3 使用ssh替代adeb进行与android设备的通信 adeb --ssh <uri> --sshpass <pass> <cmd> 七&#xff0c;BCC配置…

项目知识—SSM及之后02

1、resultMap写的Base内容必须保证select都使用上 2、VALUE单个 &#xff0c;VALUES多个 3、 一对多&#xff0c;两张表&#xff0c;多的表加外键 比如班级和学生就是一对多&#xff0c;查就是按照学生表去查询 多对多&#xff0c;三张表&#xff0c;关系表加外键 4、数据…

《PCI Express体系结构导读》随记 —— 第I篇 第2章 PCI总线的桥与配置(11)

接前一篇文章&#xff1a;《PCI Express体系结构导读》随记 —— 第I篇 第2章 PCI总线的桥与配置&#xff08;10&#xff09; 2.3 PCI桥与PCI设备的配置空间 PCI设备都有独立的配置空间&#xff0c;HOST主桥通过配置读写总线事务访问这段空间。PCI总线规定了三种类型的PCI配置…

在当前bash(sh)中执行脚本和注册函数

在研究《管理Python虚拟环境的脚本》时&#xff0c;我们使用了source指令而没有使用sh或者bash来执行脚本&#xff0c;就是因为source指令可以让脚本在当前bash(sh)中执行&#xff1b;而sh或者bash则会新启动一个bash来执行。 我们可以通过下面这个脚本做测试 # test.sh # 用…

上海亚商投顾:沪指再度失守2900点 全市场超4800只个股下跌

上海亚商投顾前言&#xff1a;无惧大盘涨跌&#xff0c;解密龙虎榜资金&#xff0c;跟踪一线游资和机构资金动向&#xff0c;识别短期热点和强势个股。 一.市场情绪 三大指数昨日继续调整&#xff0c;沪指跌超1%再度失守2900点&#xff0c;深成指、创业板指均创出调整新低&…

图文详解:CRM系统的功能有哪些?

在如今多数行业市场充分竞争的情况下&#xff0c;同质化产品层出不穷&#xff0c;什么样的企业可以在市场中屹立不倒&#xff1f;必然是拥有广泛稳定的客户群体的企业&#xff0c;所以强大的客户关系管理能力就成为了企业的核心竞争力。 在SaaS发展到今日&#xff0c;基于云服…

MySQL之子查询、连接查询(内外)以及分页查询(实操)

文章目录 前言一、SQL脚本二、实操以及实现思路 前言 续上篇博主MySQL之视图&索引&执行计划这篇给大家讲解MySQL之子查询、连接查询(内&外)以及分页查询 一、SQL脚本 /*Navicat Premium Data TransferSource Server : localhostSource Server Type :…

前端JS加密对抗由浅入深-2

前言&#xff1a; 本文主要讲解&#xff0c;针对前端非对称、多段加密数据传输站点&#xff0c;如何进行动态调试&#xff0c;如何进行安全测试。本次讲解不涉及任何漏洞方面&#xff0c;仅为学习探讨&#xff0c;该站点现已经更改加密方式&#xff0c;严禁非法测试&#xff0…

基于SSM的校园线上订餐系统设计与实现

末尾获取源码 开发语言&#xff1a;Java Java开发工具&#xff1a;JDK1.8 后端框架&#xff1a;SSM 前端&#xff1a;vue\html 数据库&#xff1a;MySQL5.7和Navicat管理工具结合 服务器&#xff1a;Tomcat8.5 开发软件&#xff1a;IDEA / Eclipse 是否Maven项目&#xff1a;是…

振弦采集仪在桥梁结构监测中的应用研究

振弦采集仪在桥梁结构监测中的应用研究 振弦采集仪在桥梁结构监测中的应用研究是指利用振弦采集仪对桥梁结构进行监测和数据采集的研究。振弦采集仪是一种能够实时监测桥梁结构振动情况的设备&#xff0c;通过采集桥梁上的振弦传感器获取振动数据&#xff0c;并将数据传输到监…

ubuntu系统(9):ubuntu 20.02安装pydot

目录 警告信息 1、确保安装了Python和pip 2、安装Graphviz软件包 3、pip安装pydot 验证 在gem5中&#xff0c;pydot库用于生成图形化输出&#xff0c;特别是生成.dot文件和相关的图像文件&#xff0c;如PDF、PNG等。它与gem5结合使用的一个常见用途是生成系统结构图、内存…

Git命令+github仓库克隆

Git github Git常用命令 开始 git init #创建仓库 git status #查看仓库的状态 git status -s #简单的查看仓库的状态 git ls-files #查看暂存区的内容 git reflog #查看操作的历史记录 暂存区 git add git add <file&g…

1-05使用VS调式程序

一、概述 写代码总不是一帆风顺的&#xff0c;总会碰到一些问题&#xff0c;检查问题&#xff0c;排除错误&#xff08;也就是Debug程序&#xff09;&#xff0c;对于任何程序员而言都是基本功。 我们前面讲过&#xff0c;C语言是一门很容易出错&#xff0c;且自身不提供异常…

[DM8] 达梦8配置兼容Oracle

查看版本信息 select *&#xff0c;id_code from v$version; 查询解释&#xff1a; DM Database Server 64 V8 1-1-190-21.03.12-136419-ENT 64 版本位数标识&#xff0c;64表示为64位版本&#xff0c;无64则表示为32位版本 V8 大版本号&#xff0c;目前主要是V7、V8 1-1-190…

STL——stack,queue详解

目录 &#x1f4a1;stack &#x1f4a1;基本概念 常用接口 &#x1f4a1;queue &#x1f4a1;基本概念 &#x1f4a1;常用接口 &#x1f4a1;stack &#x1f4a1;基本概念 栈&#xff08;stack&#xff09;&#xff1a;一种特殊的线性表&#xff0c;其只允许在固定的一端…

vue3用户权限管理(路由控制等)

在前端开发的过程中&#xff0c;我们需要做前端的权限管理&#xff0c;我们需要根据后端提供的信息来控制权限&#xff0c;这时候就需要根据用户的操作来进行权限控制了。逻辑稍微有一点绕&#xff0c;多理解就好了。 用户路由权限管理 大致的实现原理&#xff1a; 一般将路由…

Java方法用法及解析

在 Java 中&#xff0c;方法&#xff08;Method&#xff09;是用于执行特定任务的代码块。它是一个函数&#xff0c;用于封装一段可重复执行的代码&#xff0c;并可以被其他代码调用。方法定义了一系列操作的步骤&#xff0c;并提供了一种结构化和可复用的方式来组织和执行这些…

机器学习原理到Python代码实现之NaiveBayes【朴素贝叶斯】

Naive Bayes 朴素贝叶斯算法 该文章作为机器学习的第二篇文章&#xff0c;主要介绍的是朴素贝叶斯算法的原理和应用。学习本章内容建议对概率论中的联合概率以及先验概率、后验概率有初步的学习和掌握。 难度系数&#xff1a;⭐⭐⭐ 更多相关工作请参考&#xff1a;Github 算法…

ELK的搭建—Elasticsearch-8.11.3的安装及集群的搭建

es的安装及其集群的搭建 一、Elasticsearch服务的安装部署1. Elasticsearch的rpm包下载2. 安装Elasticsearch服务3. 设置系统资源及内存大小分配4. Elasticsearch的配置修改 二、建立Elasticsearch集群1. 安装Elasticsearch主节点server12. 配置server1&#xff0c;及配置文件的…

Linux文件系统与日志服务管理

目录 一.Linux文件系统 1.inode表和block &#xff08;1&#xff09;inode &#xff08;2&#xff09;block 2.查看inode号命令 3.Linux系统文件三种主要时间属性 4.磁盘空间还剩余很多但无法继续创建文件 5.inode大小 二.日志 1.日志保存位置 2.日志文件的分类 &a…