ContactCpuDemo.java
2.91 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package d8demo;
import com.sun.jna.Native;
/**
* ´ó¿¨×ù²Ù×÷demo
* @author decard
*/
public class ContactCpuDemo {
/**
* @param b
* @param length
*/
public static void print_bytes(byte[] b, int length) {
for (int i = 0; i < length; ++i) {
String hex = Integer.toHexString(b[i] & 0xFF);
if (hex.length() == 1) {
hex = '0' + hex;
}
System.out.print(hex.toUpperCase());
}
}
public static void main(String[] args) {
Dcrf32_h dcrf32;
dcrf32 = (Dcrf32_h) Native.loadLibrary("./dcrf32.dll", Dcrf32_h.class);
int result;
int handle;
int[] snr = new int[1];
byte[] rlen = new byte[1];
byte[] send_buffer = new byte[2048];
byte[] recv_buffer = new byte[2048];
System.out.print("dc_init ... ");
result = dcrf32.dc_init((short) 100, 115200);
if (result < 0) {
System.out.println("error!");
return;
}
System.out.println("ok!");
handle = result;
System.out.print("set cpu address ... ");
result = dcrf32.dc_setcpu(handle, (byte) 0x0c);
if (result != 0) {
System.out.println("error!");
dcrf32.dc_exit(handle);
return;
}
System.out.println("ok");
System.out.print("cpu reset ... ");
result = dcrf32.dc_cpureset(handle, rlen, recv_buffer);
if (result != 0) {
System.out.println("error!");
dcrf32.dc_exit(handle);
return;
}
System.out.println("ok");
System.out.print("reset info :");
print_bytes(recv_buffer, rlen[0] & 0xFF);
System.out.println();
System.out.print("dc_pro_command ... ");
send_buffer[0] = (byte) 0x00;
send_buffer[1] = (byte) 0x84;
send_buffer[2] = (byte) 0x00;
send_buffer[3] = (byte) 0x00;
send_buffer[4] = (byte) 0x08;
result = dcrf32.dc_cpuapdu(handle, (byte) 5, send_buffer, rlen, recv_buffer);
if (result != 0) {
System.out.println("error!");
dcrf32.dc_exit(handle);
return;
}
System.out.println("ok!");
System.out.print("DATA: ");
print_bytes(recv_buffer, rlen[0] & 0xFF);
System.out.println();
System.out.print("dc_beep ... ");
result = dcrf32.dc_beep(handle, (short) 10);
if (result != 0) {
System.out.println("error!");
dcrf32.dc_exit(handle);
return;
}
System.out.println("ok!");
System.out.print("dc_exit ... ");
result = dcrf32.dc_exit(handle);
if (result != 0) {
System.out.println("error!");
return;
}
System.out.println("ok!");
}
}