554325746@qq.com
2019-08-07 2539f53391765abb74b6fe63f46e5a2c701e950f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.basic.project.idcardservice.idcard;
 
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
 
import com.byid.android.IDCard;
import com.byid.android.ReadPort;
 
import android_serialport_api.SerialPortFinder;
 
/**
 * Created by Administrator on 2018/8/1.
 */
 
public class ReadUtil {
 
 
    private ReadPort readPort;
    private SharedPreferences sp;
    private SharedPreferences.Editor ed;
 
    @SuppressLint("WrongConstant")
    public ReadUtil(Context context, int arg) {
        sp = context.getSharedPreferences("setting", Context.MODE_APPEND);
        ed = sp.edit();
        if (arg == 0) {
            readPort = new ReadPort(context, sp.getString("port", "/dev/ttyS0"), 115200);
        } else if (arg == 1) {
            readPort = new ReadPort(context);
        }
    }
 
    //通用判断是否连接
    public boolean isPort() {
        return readPort.isPort();
    }
 
    //读取身份证UID
    public String idUid() {
        return readPort.readCardUid();
    }
 
    //通用读取身份证
    public IDCard readCard() {
        return readPort.readCard();
    }
 
    //IC卡类型:TYPEA TYPEB 参数: 0或1
    public void icType(int type) {
        readPort.icType(type);
    }
 
    //读取IC卡ID
    public String icID() {
        return readPort.icID();
    }
 
    //验证扇区密码 参数: 扇区ID和密码
    public boolean icPassWord(int sector, String str) {
        return readPort.icPassWord(sector, str);
    }
 
    // 读取IC卡块数据 参数: 块ID
    public String icReadData(int sector) {
        return readPort.icReadData(sector);
    }
 
    //写入IC卡块数据 参数:块ID 数据
    public boolean icWriteData(int rng, String rnx) {
        return readPort.icWriteData(rng, rnx);
    }
 
    //写入IC卡块密码 参数:块ID 数据
    public boolean icWritePassword(int rng, String rnx) {
        return readPort.icWritePassword(rng, rnx);
    }
 
    //关闭USB连接
    public void closeUSBDevice() {
        if (readPort != null)
            readPort.closeUsbDevice();
    }
 
    //关闭串口连接
    public void closePort() {
        if (readPort != null)
            readPort.closePort();
    }
}