读卡器介绍:免驱RFID读卡器 Web读卡器 可二次开发 Android、Linux 乐乐课堂-淘宝网 (taobao.com)https://item.taobao.com/item.htm?spm=a1z10.5-c.w4002-17663462238.35.39895b43AJPLGe&id=562957272162

Android Studio源码: 

package com.ic.ouridrtest;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.reader.ouridr;//引入我们的读卡器类

public class MainActivity extends AppCompatActivity {

    private TextView tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Example of a call to a native method
        tv = findViewById(R.id.sample_text);
        tv.setText("操作结果");
    }


    //读卡------------------------------------------------------------------------------------------
    public void idr_read(View view)
    {
        byte status;//存放返回值
        byte[] idserial = new byte[5];

        String strls = "";
        status = ouridr.read(this,idserial);
        if(status == 0)
        {
            strls = "读取成功!卡号为";
            String strls1 = "0"+Integer.toHexString(idserial[0]);
            strls = strls + strls1.substring(strls1.length()-2) +"-";
            strls1 = "0"+Integer.toHexString(idserial[1]);
            strls = strls + strls1.substring(strls1.length()-2) +"-";
            strls1 = "0"+Integer.toHexString(idserial[2]);
            strls = strls + strls1.substring(strls1.length()-2) +"-";
            strls1 = "0"+Integer.toHexString(idserial[3]);
            strls = strls + strls1.substring(strls1.length()-2) +"-";
            strls1 = "0"+Integer.toHexString(idserial[4]);
            strls = strls + strls1.substring(strls1.length()-2);
        }
        else
        {
            if(status == 8)
            {
                strls = "请将卡放在ID卡读卡器感应区";
            }
            else if(status == 23)
            {
                strls = "错误提示:读卡器未插入";
            }
            else
            {
                strls = "错误代码:" + Integer.toString(status);
            }
        }
        tv.setText(strls);
    }

    //仅读一次,重新取放卡才能读到第二次---------------------------------------------------------------
    public void idr_read_once(View view)
    {
        byte status;//存放返回值
        byte[] idserial = new byte[5];

        String strls = "";
        status = ouridr.readonce(this,idserial);
        if(status == 0)
        {
            strls = "读取成功!卡号为";
            String strls1 = "0"+Integer.toHexString(idserial[0]);
            strls = strls + strls1.substring(strls1.length()-2) +"-";
            strls1 = "0"+Integer.toHexString(idserial[1]);
            strls = strls + strls1.substring(strls1.length()-2) +"-";
            strls1 = "0"+Integer.toHexString(idserial[2]);
            strls = strls + strls1.substring(strls1.length()-2) +"-";
            strls1 = "0"+Integer.toHexString(idserial[3]);
            strls = strls + strls1.substring(strls1.length()-2) +"-";
            strls1 = "0"+Integer.toHexString(idserial[4]);
            strls = strls + strls1.substring(strls1.length()-2);
        }
        else
        {
            if(status == 8)
            {
                strls = "请将卡放在ID卡读卡器感应区";
            }
            else if(status == 23)
            {
                strls = "错误提示:读卡器未插入";
            }
            else
            {
                strls = "错误代码:" + Integer.toString(status);
            }
        }
        tv.setText(strls);
    }

    //读出设备全球唯一的设备编号,作为加密狗用----------------------------------------------------------
    public void pcdgetdevicenumber(View view)
    {
        byte status;//存放返回值
        byte[] devicenumber = new byte[4];

        String strls = "";
        status = ouridr.pcdgetdevicenumber(this,devicenumber);
        if(status == 0)
        {
            strls = "读取成功!设备编号为";
            String strls1 = "0"+Integer.toHexString(devicenumber[0]);
            strls = strls + strls1.substring(strls1.length()-2) +"-";
            strls1 = "0"+Integer.toHexString(devicenumber[1]);
            strls = strls + strls1.substring(strls1.length()-2) +"-";
            strls1 = "0"+Integer.toHexString(devicenumber[2]);
            strls = strls + strls1.substring(strls1.length()-2) +"-";
            strls1 = "0"+Integer.toHexString(devicenumber[3]);
            strls = strls + strls1.substring(strls1.length()-2);
        }
        else
        {
            if(status == 23)
            {
                strls = "错误提示:读卡器未插入";
            }
            else
            {
                strls = "错误代码:" + Integer.toString(status);
            }
        }
        tv.setText(strls);
    }

    //让设备发出声响----------------------------------------------------------------------------------
    public void idr_beep(View view)
    {
        byte status;//存放返回值
        String strls = "";
        status = ouridr.beep(this,50);

        if(status == 0)
        {
            strls = "读卡器嘀一声成功!!!";
        }
        else
        {
            if(status == 23)
            {
                strls = "错误提示:读卡器未插入";
            }
            else
            {
                strls = "错误代码:" + Integer.toString(status);
            }
        }
        tv.setText(strls);
    }
}


 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐