Add you as group of dialout (20)
# usermod -aG dialout myuser
Note, if you use terminal only, this will effect directly, but if you use window Manager, you require to logout and re-login to make it effect especially on Netbeans, If aftar re-login fail, try restart.
Confirm which com the reader assign
# ls -l /dev/ttyACM0
crw-rw---- 1 root dialout 166, 0 May 19 13:43 /dev/ttyACM0
The card reader assign com at /dev/ttyACM0
This is simple java code to read card when tap on device
import java.io.FileInputStream;
import java.io.InputStream;
public class TestRD200 {
public static void main(String[] args) {
String device = "/dev/ttyACM0";
try {
// Configure serial port using stty
Process process = new ProcessBuilder(
"stty",
"-F",
device,
"115200",
"cs8",
"-cstopb",
"-parenb",
"raw"
).inheritIO().start();
process.waitFor();
System.out.println("Listening on " + device);
InputStream in = new FileInputStream(device);
byte[] buffer = new byte[1024];
while (true) {
int len = in.read(buffer);
if (len > 0) {
System.out.println("READ BYTES: " + len);
for (int i = 0; i < len; i++) {
System.out.printf("%02X ", buffer[i]);
}
System.out.println();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
This is sample output with uid masked
$ java TestRD200
Listening on /dev/ttyACM0
READ BYTES: 8
02 06 xx xx xx xx xx 52
What they are?
02 STX
06 LENGTH
Data 1-5 xx xx xx xx xx
Checksum 52
You need to know command in byte, to send to card reader/rfid reader.
General command format in byte
[stx] [length] [data] [checksum]
STX
01 Read Card UID
02 Run Action Command
03 Get USB Mode
0C Read user Data
0C Write user Data
0D get S/N
0E Get Model, Version
0F 01 Set Reboot
e.g. to read Mifare UID (0x11)
command in bytes: 02 01 11 10
02: run command
01: length
11: command to read Mifare UID
10 checksum ( 01 xor 11 )
if return 4 bytes: MIFARE Classic 1K/4K
if return 7 bytes: NTAG / Ultralight / DESFire
if return 8 bytes: ISO15693