荣士USB免驱动15693-02读写器支持Windows、安卓(Android)、Linux系统,为方便读写器能快速的接入安卓(Android)系统,我们提供了各种安卓版本的So库及示例源码,安卓工程师可直接拷贝以下代码使用到项目中。
按以下4部操作,可快速将So库加载到您的Android工程项目内:
1、将我们提供的开发包里的文件夹libs及OURMIFARE_V1.aar,一起复制你的项目APP-->libs目录下;
2、修改APP-->src下的build.gradle文件,在buildTypes{}的后面,加入
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
同时在dependencies {}中加入
implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs')
3、加入NDK工具包。
4、java的源文件中加入import com.reader.ourmifare;,就可以调用我们在AAR包里的函数了。
Android Studio读、写15693协议ICODE 2卡源码:
package com.ic.usb1569302;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.reader.ourmifare; //引入我们的读卡器类
public class MainActivity extends AppCompatActivity {
private TextView tv;
private static final byte BLOCK0_EN = 0x01;
private static final byte BLOCK1_EN = 0x02;
private static final byte BLOCK2_EN = 0x04;
private static final byte NEEDSERIAL = 0x08;
private static final byte EXTERNKEY = 0x10;
private static final byte NEEDHALT = 0x20;
@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("操作结果");
}
//15693卡:寻卡
public void iso15693inventory(View view)
{
byte status;//存放返回值
byte flags;
byte afi;
byte masklen;
byte[] maskuidbuf = new byte[8];
byte[] uidbuf = new byte[9];
flags = 0x36;
afi = 0;
masklen = 0;
status = ourmifare.iso15693inventory(this,flags,afi,masklen,maskuidbuf,uidbuf);
String strls = "";
if(status == 0)
{
strls = "寻卡成功!卡号为";
String strls1;
for(int i = 1;i < 8;i++)
{
strls1 = "0"+Integer.toHexString(uidbuf[i] & 0xff);
strls = strls + strls1.substring(strls1.length()-2) +"-";
}
strls1 = "0"+Integer.toHexString(uidbuf[8] & 0xff);
strls = strls + strls1.substring(strls1.length()-2);
}
else
{
if(status == 8)
{
strls = "请将卡放在IC卡读卡器感应区";
}
else if(status == 23)
{
strls = "错误提示:读卡器未插入";
}
else
{
strls = "错误代码:" + Integer.toString(status);
}
}
tv.setText(strls);
}
//15693卡:轻松读卡
public void iso15693readex(View view)
{
byte status;//存放返回值
byte myctrlword;
byte afi;
byte startblock;
byte blocknum;
byte[] maskuidbuf = new byte[8];
byte[] uidbuf = new byte[8];
byte[] databuf = new byte[100];
myctrlword = 0;//'读任何卡,不需指定卡号,读完后不静止该卡,可赋值NEEDSERIAL及NEEDHALT的组合模式,或为0
afi = 0;
startblock = 0;
blocknum = 12;
status = ourmifare.iso15693readex(this,myctrlword,afi,startblock,blocknum,uidbuf,databuf);
String strls = "";
if(status == 0)
{
strls = "读取成功!卡号为";
String strls1;
for(int i = 0;i < 7;i++)
{
strls1 = "0"+Integer.toHexString(uidbuf[i] & 0xff);
strls = strls + strls1.substring(strls1.length()-2) +"-";
}
strls1 = "0"+Integer.toHexString(uidbuf[7] & 0xff);
strls = strls + strls1.substring(strls1.length()-2);
strls += ",块数据为";
for(int i = 0;i < (databuf[0]-1);i++)
{
//从databuf[i+1]开始才是数据,databuf[0]为数据长度
strls1 = "0"+Integer.toHexString(databuf[i+1] & 0xff);
strls = strls + strls1.substring(strls1.length()-2) +"-";
}
strls1 = "0"+Integer.toHexString(databuf[databuf[0]] & 0xff);
strls = strls + strls1.substring(strls1.length()-2);
}
else
{
if(status == 8)
{
strls = "请将卡放在IC卡读卡器感应区";
}
else if(status == 23)
{
strls = "错误提示:读卡器未插入";
}
else
{
strls = "错误代码:" + Integer.toString(status);
}
}
tv.setText(strls);
}
//15693卡:轻松写卡
public void iso15693writeex(View view)
{
byte status;//存放返回值
byte myctrlword;
byte afi;
byte startblock;
byte blocknum;
byte[] maskuidbuf = new byte[8];
byte[] uidbuf = new byte[8];
byte[] databuf = new byte[49];//如果本次写的是12个块,每块为4字节,就需要4*12=48个字节,再加上1个字节的长度=49个字节
//控制字指定,控制字的含义请查看本公司网站提供的动态库说明
myctrlword = 0;
afi = 0;
startblock = 0;
blocknum = 12;
databuf[0] = (byte)(blocknum * 4);
for(int i = 1;i < 49;i++)
{
databuf[i] = (byte)i;
}
String strls = "";
status = ourmifare.iso15693writeex(this,myctrlword,afi,startblock,blocknum,uidbuf,databuf);
if(status == 0)
{
strls = "写卡成功!卡号为";
String strls1;
for(int i = 0;i < 7;i++)
{
strls1 = "0"+Integer.toHexString(uidbuf[i] & 0xff);
strls = strls + strls1.substring(strls1.length()-2) +"-";
}
strls1 = "0"+Integer.toHexString(uidbuf[7] & 0xff);
strls = strls + strls1.substring(strls1.length()-2);
strls += ",写入块中的数据为";
for(int i = 0;i < (databuf[0]-1);i++)
{
//从databuf[i+1]开始才是数据,databuf[0]为数据长度
strls1 = "0"+Integer.toHexString(databuf[i+1] & 0xff);
strls = strls + strls1.substring(strls1.length()-2) +"-";
}
strls1 = "0"+Integer.toHexString(databuf[databuf[0]] & 0xff);
strls = strls + strls1.substring(strls1.length()-2);
}
else
{
if(status == 8)
{
strls = "请将卡放在IC卡读卡器感应区";
}
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 = ourmifare.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 beep(View view)
{
byte status;//存放返回值
String strls = "";
status = ourmifare.pcdbeep(this,50);
if(status == 0)
{
strls = "读卡器嘀一声成功!!!";
}
else
{
if(status == 23)
{
strls = "错误提示:读卡器未插入";
}
else
{
strls = "错误代码:" + Integer.toString(status);
}
}
tv.setText(strls);
}
}
APP运行:
|