我是靠谱客的博主 小巧绿草,这篇文章主要介绍RFID读取,现在分享给大家,希望可以做个参考。

RFID 不同厂家的调运方法不同,一般都要调用厂家的api或者是引用厂家的源码,一下代码仅作思路提示

Mr915ApiV20 为厂家api类

复制代码
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
110
//连接发卡器,厂家:深圳智远 private boolean ConnectFKQ() { boolean ReturnState = true; //获取串口列表 commList = findPort(); if (commList == null || commList.size() < 1) { txtMsg.setText("没有搜索到有效串口,请断开桌面发卡器重新连接!"+ "n" + txtMsg.getText()); ComPortState = false; ReturnState = false; } else { try { String ComNameStr = Common.CommName; logger.error("上一次存储的串口:" + ComNameStr); if (Mr915ApiV20.ConnectReader(ComNameStr)) { // 打开串口 if (Mr915ApiV20.matchBaudRate()) { txtMsg.setText("链接发卡器串口"+ComNameStr+"成功!!" + "n" + txtMsg.getText()); // 先找到计算机com口与设备匹配的波特率,然后在根据界面参数设置波特率 Mr915ApiV20.setDeviceRate(9600); // 设置设备波特率 if (Mr915ApiV20.read()[3] != 1) { Mr915ApiV20.GetFirmwareVersion(); byte[] a = Mr915ApiV20.read(); // 接收返回数据 String aa = String.valueOf(a[4]); String bb = String.valueOf(a[5]); if (aa.length() == 1) { aa = "0" + aa; } if (bb.length() == 1) { bb = "0" + bb; } String cc = "V" + String.valueOf(aa) + "." + bb; System.out.println("输出 --- " + cc); txtMsg.setText("链接发卡器波特率9600成功!" + "n" + txtMsg.getText()); logger.error("链接发卡器波特率9600成功!" + "n" + txtMsg.getText()); ComPortState = true; ReturnState = true; } } } else { String CanUserCom = ""; for (String ComName : commList) { logger.error("第一次使用,正在尝试连接" + ComName + "串口"); txtMsg.setText("第一次使用,正在尝试连接" + ComName + "串口" + "n" + txtMsg.getText()); CanUserCom = CanUserCom + "," + ComName; //链接桌面读卡器 if (Mr915ApiV20.ConnectReader(ComName)) { // 打开串口 if (Mr915ApiV20.matchBaudRate()) { txtMsg.setText("链接发卡器串口" + ComName + "成功!" + "n" + txtMsg.getText()); // 先找到计算机com口与设备匹配的波特率,然后在根据界面参数设置波特率 Mr915ApiV20.setDeviceRate(9600); // 设置设备波特率 if (Mr915ApiV20.read()[3] != 1) { Mr915ApiV20.GetFirmwareVersion(); byte[] a = Mr915ApiV20.read(); // 接收返回数据 String aa = String.valueOf(a[4]); String bb = String.valueOf(a[5]); if (aa.length() == 1) { aa = "0" + aa; } if (bb.length() == 1) { bb = "0" + bb; } String cc = "V" + String.valueOf(aa) + "." + bb; System.out.println("输出 --- " + cc); txtMsg.setText("链接发卡器波特率9600成功!" + "n" + txtMsg.getText()); logger.error("链接发卡器波特率9600成功!" + "n" + txtMsg.getText()); ComPortState = true; ReturnState = true; Common.EditCommNameConfig(ComName); break; } } } } if (ComPortState == false) { logger.error("没有可用的串口设备,请检查发卡器及数据线是否连接正确!"); txtMsg.setText("没有可用的串口设备,请检查发卡器及数据线是否连接正确!" + "n" + txtMsg.getText()); JOptionPane.showMessageDialog(null, "没有可用的串口设备,请检查发卡器及数据线是否连接正确!", "警告", JOptionPane.ERROR_MESSAGE); txtMsg.setText("链接发卡器失败,搜索到的串口" + CanUserCom + "无法连接设备,请重新安装驱动或检查设备是否完好。" + "n" + txtMsg.getText()); ComPortState = false; ReturnState = false; } } } catch(Exception e) { txtMsg.setText("链接发卡器失败,搜索到的串口无法连接设备,请重新安装驱动或检查设备是否完好。" + "n" + txtMsg.getText()); logger.error("获得当前所有可用串口错误:" + e.getMessage(), e); ComPortState = false; e.printStackTrace(); return false; } } return ReturnState; }

最后

以上就是小巧绿草最近收集整理的关于RFID读取的全部内容,更多相关RFID读取内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(78)

评论列表共有 0 条评论

立即
投稿
返回
顶部