vue做的后台管理系统,电脑插上读卡器,通过读卡器设备去读取芯片的数据
在index.html页面加上,在body的上面,jquery文件可以是其他版本的
三个文件跟index.html页面同级,可能打包后会出现找不到这三个文件,最好在public目录里也加上这三个文件
<!-- 读卡器获取数据 -->
<script src="./jquery-1.12.4.min.js"></script>
<script src="./wsrProxy.min.js"></script>
<script src="./wsrProxyTest_iso15693.js"></script>
vue3项目里的弄了个hooks使用
import { onMounted } from 'vue'
import { ElMessage } from 'element-plus'
// 读取标签数据
// 读取标签数据
export const useIDCard = () => {
console.log('能拿到东西?', wsrProxy)
onMounted(() => {
wsrProxy.init()//初始化读卡
console.log('fffffffffffffffffffff')
})
const getId = () => {
var rt = 0; // 返回值
var port = 0; // 端口号
var uid_count = 0; // 标签个数
var uid = ''; // 标签UID
var v1 = 5000,
v2 = 0;
var block = 5; // 块号
var delaytime = 2; // 蜂鸣时长 2*10ms = 20ms
var obj = {};
// 打开端口
rt = wsrProxy.ws_openPort(port);
// console.log(rt);
if (rt < 0) {
ElMessage({ message: '请插上读卡器或读卡器连接异常', type: 'warning' })
}
// return rt;
try {
wsrProxy.ws_set_mode(wsrProxy.MODE_TIMEOUT, 300);
// wsrProxy.ws_set_device_mode(port, parseInt('31', 16));
// 点名
obj = { model: '', cputype: 0, version: 0.0, id: '', info: '' };
rt = wsrProxy.ws_callDeviceE(port, obj);
// 点名 if (rt < 0)
// return rt;
// console.log('device model:' + obj.model);
// console.log('device cputype:' + obj.cputype);
// console.log('device version:' + obj.version);
obj = { model: '', cputype: 0, version: 0.0, id: '', info: '' };
rt = wsrProxy.ws_callDeviceE(port, obj);
// 蜂鸣
rt = wsrProxy.ws_beep(port);
if (rt < 0) return rt;
rt = wsrProxy.ws_beepex(port, delaytime);
if (rt < 0) return rt;
// 读取设备唯一序列号
rt = wsrProxy.ws_get_dev_id(port, obj);
if (rt < 0) return rt;
// console.log('device id:' + obj.id);
// 读取设备信息
rt = wsrProxy.ws_get_dev_info(port, obj);
if (rt < 0) return rt;
obj.uids = '';
rt = wsrProxy.ws_iso15693_getTags(port, obj);
if (!obj.uids){
ElMessage({ message: '数据读取失败', type: 'warning', });
return
}
// for(let key in obj){
// console.log(key)
// console.log(obj[key])
// }
// console.log('device info:`````````````````````````````' + obj);
return obj;
// console.log(rt);
// if (rt <= 0) return rt;
// 获取标签个数,本程序只取第一个标签uid
// uid_count = rt;
// 取第一个标签,8个字节,16进制表示占8*2个字符,
// 索引0-15,下一个标签索引16-31,依次类推
// for (var i = 0; i < 16; i++){
// uid[i] = uids[i];
// }
} finally {
wsrProxy.ws_closePort(port);
}
}
return {
getId
}
}
使用页面
import { useIDCard } from '@/hooks/web/useIDCard'
const { getId } = useIDCard() //读取标签
需要用到的文件wsrProxy.min.js
var wsrProxy = {
port: 0,
baud: 57600,
proxy_ip: "127.0.0.1",
proxy_port: 35225,
get_full: "",
ret: -1,
MSG_GETCARDNO: 1024 + 1000,
MODE_CARDTYPE: 1,
MODE_CARDSEQ: 2,
MODE_DATATYPE: 3,
MODE_TIMEOUT: 4,
MODE_COMMAND: 5,
MODE_MULTI_PORT: 6,
MODE_REQUEST: 7,
client_datatype: 0,
get_prefix: function () {
return "http://" + this.proxy_ip + ":" + this.proxy_port + "/wsr:"
},
init: function () {
this.client_datatype = 0;
$.base64.utf8encode = true;
jQuery.support.cors = true;
$.ajaxSetup({
async: false,
cache: false,
timeout: 1000
})
},
ws_getWsrJsInfo: function (obj) {
obj.version = 0.19;
obj.builddate = 20190806;
ret = 1;
return ret
},
ws_getDLLInfo: function (obj) {
ret = -1;
this.get_full = this.get_prefix() + "ws_getDLLInfo" + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
obj.version = data.dll_version;
obj.builddate = data.dll_builddate;
ret = 1
});
return ret
},
ws_getWsrProxyInfo: function (obj) {
ret = -1;
this.get_full = this.get_prefix() + "ws_getWsrProxyInfo" + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
obj.version = data.proxy_version;
obj.builddate = data.proxy_builddate;
obj.isApp64 = data.isApp64;
ret = 1
});
return ret
},
ws_setBaud: function (port, baud) {
ret = -1;
this.get_full = this.get_prefix() + "ws_setBaud," + port + "," + baud + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_getBaud: function (port, obj) {
ret = -1;
this.get_full = this.get_prefix() + "ws_getBaud," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt;
obj.baud = data.baud
});
return ret
},
ws_openPort: function (port) {
ret = -1;
this.get_full = this.get_prefix() + "ws_openPort," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_closePort: function (port) {
ret = -1;
this.get_full = this.get_prefix() + "ws_closePort," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_callDevice: function (port) {
ret = -1;
this.get_full = this.get_prefix() + "ws_callDevice," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_callDeviceE: function (port, obj) {
ret = -1;
this.get_full = this.get_prefix() + "ws_callDeviceE," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt;
obj.model = data.dev_model;
obj.cputype = data.dev_cputype;
obj.version = data.dev_version
});
return ret
},
ws_beep: function (port) {
ret = -1;
this.get_full = this.get_prefix() + "ws_beep," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_beepex: function (port, delaytime) {
ret = -1;
this.get_full = this.get_prefix() + "ws_beepex," + port + "," + delaytime + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_setNumber: function (port, number) {
ret = -1;
this.get_full = this.get_prefix() + "ws_setNumber," + port + "," + number + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_get_dev_id: function (port, obj) {
ret = -1;
this.get_full = this.get_prefix() + "ws_get_dev_id," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt;
obj.id = data.dev_id
});
return ret
},
ws_get_dev_info: function (port, obj) {
ret = -1;
this.get_full = this.get_prefix() + "ws_get_dev_info," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt;
obj.info = data.dev_info
});
return ret
},
ws_reset: function (port) {
ret = -1;
this.get_full = this.get_prefix() + "ws_reset," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_set_device_mode: function (port, mode) {
ret = -1;
this.get_full = this.get_prefix() + "ws_set_device_mode," + port + "," + mode + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_get_device_mode: function (port, obj) {
ret = -1;
this.get_full = this.get_prefix() + "ws_get_device_mode," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt;
obj.mode = data.mode
});
return ret
},
ws_set_device_default_mode: function (port, mode) {
ret = -1;
this.get_full = this.get_prefix() + "ws_set_device_default_mode," + port + "," + mode + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_get_device_default_mode: function (port, obj) {
ret = -1;
this.get_full = this.get_prefix() + "ws_get_device_default_mode," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt;
obj.mode = data.mode
});
return ret
},
ws_displayText: function (port, lineno, length, text) {
ret = -1;
this.get_full = this.get_prefix() + "ws_displayText," + port + "," + lineno + "," + length + "," + text + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_clearText: function (port) {
ret = -1;
this.get_full = this.get_prefix() + "ws_clearText," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_set_mode: function (mark_mode, mode) {
ret = -1;
this.get_full = this.get_prefix() + "ws_set_mode," + mark_mode + "," + mode + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_get_mode: function (mark_mode, obj) {
ret = -1;
this.get_full = this.get_prefix() + "ws_get_mode," + mark_mode + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt;
obj.mode = data.mode
});
return ret
},
ws_set_id_mode: function (port, mode) {
ret = -1;
this.get_full = this.get_prefix() + "ws_set_id_mode," + port + "," + mode + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_get_id_mode: function (port, obj) {
ret = -1;
this.get_full = this.get_prefix() + "ws_get_id_mode," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt;
obj.mode = data.mode
});
return ret
},
ws_halt: function (port) {
ret = -1;
this.get_full = this.get_prefix() + "ws_halt," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_getCardNo_DWORD: function (port, obj) {
ret = -1;
this.get_full = this.get_prefix() + "ws_getCardNo_DWORD," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt;
obj.cardno = data.cardno >>> 0
});
return ret
},
ws_getCardNo_Double: function (port, obj) {
ret = -1;
this.get_full = this.get_prefix() + "ws_getCardNo_Double," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt;
obj.cardno = data.cardno
});
return ret
},
ws_getCardNo_String: function (port, obj) {
ret = -1;
this.get_full = this.get_prefix() + "ws_getCardNo_String," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt;
obj.cardno = data.cardno
});
return ret
},
ws_getCardNo_Hex: function (port, obj) {
ret = -1;
this.get_full = this.get_prefix() + "ws_getCardNo_Hex," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt;
obj.cardno = data.cardno
});
return ret
},
ws_getCardNo_ex: function (port, obj) {
ret = -1;
this.get_full = this.get_prefix() + "ws_getCardNo_ex," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt;
obj.cardtype = data.cardtype;
obj.cardbytes = data.cardbytes;
obj.cardno = data.cardno
});
return ret
},
ws_loadKey: function (port, key, keytype) {
ret = -1;
var tmpdata = this.toBase64(port + "," + key + "," + keytype);
this.get_full = this.get_prefix() + "ws_loadKey," + tmpdata + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_loadKeyE: function (port, key, keytype) {
ret = -1;
var tmpdata = this.toBase64(port + "," + key + "," + keytype);
this.get_full = this.get_prefix() + "ws_loadKeyE," + tmpdata + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_verifyKey: function (port, key, keytype, sector) {
ret = -1;
var tmpdata = this.toBase64(port + "," + key + "," + keytype + "," + sector);
this.get_full = this.get_prefix() + "ws_verifyKey," + tmpdata + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_verifyKeyE: function (port, key, keytype, sector) {
ret = -1;
var tmpdata = this.toBase64(port + "," + key + "," + keytype + "," + sector);
this.get_full = this.get_prefix() + "ws_verifyKeyE," + tmpdata + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_changeKey: function (port, sector, newkeya, newac, newkeyb) {
ret = -1;
var tmpdata = this.toBase64(port + "," + sector + "," + newkeya + "," + newac + "," + newkeyb);
this.get_full = this.get_prefix() + "ws_changeKey," + tmpdata + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_readBlock: function (port, block, obj) {
ret = -1;
this.get_full = this.get_prefix() + "ws_readBlock," + port + "," + block + "," + this.client_datatype + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
// console.log(this.get_full);
// console.log(data);
ret = data.rt;
// console.log(ret);
obj.data = data.data;
// console.log(obj.data);
});
obj.data = this.fromBase64(obj.data);
// console.log(obj.data);
return ret
},
ws_writeBlock: function (port, block, data) {
ret = -1;
var tmpdata = this.toBase64(data);
this.get_full = this.get_prefix() + "ws_writeBlock," + port + "," + block + "," + this.client_datatype + tmpdata + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_initValue: function (port, block, value) {
ret = -1;
this.get_full = this.get_prefix() + "ws_initValue," + port + "," + block + "," + value + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_readValue: function (port, block, obj) {
ret = -1;
this.get_full = this.get_prefix() + "ws_readValue," + port + "," + block + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt;
obj.value = data.value
});
return ret
},
ws_incValue: function (port, block, value) {
ret = -1;
this.get_full = this.get_prefix() + "ws_incValue," + port + "," + block + "," + value + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_decValue: function (port, block, value) {
ret = -1;
this.get_full = this.get_prefix() + "ws_decValue," + port + "," + block + "," + value + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_iso14443b_get_uid_2: function (port, obj) {
ret = -1;
this.get_full = this.get_prefix() + "ws_iso14443b_get_uid_2," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt;
obj.uid = data.uid;
obj.len = data.len
});
return ret
},
ws_iso15693_setFlag: function (port, flag_select, flag_address, flag_tagType) {
ret = -1;
this.get_full = this.get_prefix() + "ws_iso15693_setFlag," + port + "," + flag_select + "," + flag_address + "," + flag_tagType + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_iso15693_getFlag: function (port, obj) {
ret = -1;
this.get_full = this.get_prefix() + "ws_iso15693_getFlag," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt;
obj.flag_select = data.flag_select;
obj.flag_address = data.flag_address;
obj.flag_tagType = data.flag_tagType
});
return ret
},
ws_iso15693_setUID: function (port, uid) {
ret = -1;
this.get_full = this.get_prefix() + "ws_iso15693_setUID," + port + "," + uid + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_iso15693_getTags: function (port, obj) {
ret = -1;
this.get_full = this.get_prefix() + "ws_iso15693_getTags," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
obj.uids = data.uids;
ret = data.rt
});
return ret
},
ws_iso15693_getTagInfo: function (port, obj) {
ret = -1;
this.get_full = this.get_prefix() + "ws_iso15693_getTagInfo," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
obj.uid = data.uid;
obj.flag_memory = data.flag_memeory;
obj.block_count = data.block_count;
obj.block_size = data.block_size;
ret = data.rt
});
return ret
},
ws_iso15693_getTagInfoE: function (port, obj) {
ret = -1;
this.get_full = this.get_prefix() + "ws_iso15693_getTagInfoE," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
obj.flag_dsfid = data.flag_dsfid;
obj.flag_afi = data.flag_afi;
obj.flag_memory = data.flag_memory;
obj.flag_producer = data.flag_producer;
obj.uid = data.uid;
obj.dsfid = data.dsfid;
obj.afi = data.afi;
obj.block_count = data.block_count;
obj.block_size = data.block_size;
ret = data.rt
});
return ret
},
ws_iso15693_select: function (port, uid) {
ret = -1;
this.get_full = this.get_prefix() + "ws_iso15693_select," + port + "," + uid + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_iso15693_reset: function (port) {
ret = -1;
this.get_full = this.get_prefix() + "ws_iso15693_reset," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_iso15693_quiet: function (port) {
ret = -1;
this.get_full = this.get_prefix() + "ws_iso15693_quiet," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_iso15693_readBlock: function (port, block, block_count, obj) {
ret = -1;
this.get_full = this.get_prefix() + "ws_iso15693_readBlock," + port + "," + block + "," + block_count + "," + this.client_datatype + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt;
obj.data = data.data
});
obj.data = this.fromBase64(obj.data);
return ret
},
ws_iso15693_readBlockE: function (port, block, block_count, obj) {
ret = -1;
this.get_full = this.get_prefix() + "ws_iso15693_readBlockE," + port + "," + block + "," + block_count + "," + this.client_datatype + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt;
obj.data = data.data;
obj.status = data.status
});
obj.data = this.fromBase64(obj.data);
obj.status = this.fromBase64(obj.status);
return ret
},
ws_iso15693_writeBlock: function (port, block, block_count, data) {
ret = -1;
var tmpdata = this.toBase64(data);
this.get_full = this.get_prefix() + "ws_iso15693_writeBlock," + port + "," + block + "," + block_count + "," + this.client_datatype + tmpdata + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_iso15693_lockBlock: function (port, block) {
ret = -1;
this.get_full = this.get_prefix() + "ws_iso15693_lockBlock," + port + "," + block + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_iso15693_writeAFI: function (port, afi) {
ret = -1;
this.get_full = this.get_prefix() + "ws_iso15693_writeAFI," + port + "," + afi + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_iso15693_lockAFI: function (port) {
ret = -1;
this.get_full = this.get_prefix() + "ws_iso15693_lockAFI," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_iso15693_writeDSFID: function (port, dsfid) {
ret = -1;
this.get_full = this.get_prefix() + "ws_iso15693_writeDSFID," + port + "," + dsfid + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_iso15693_lockDSFID: function (port) {
ret = -1;
this.get_full = this.get_prefix() + "ws_iso15693_lockDSFID," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_get_dev_usbcount: function () {
ret = -1;
this.get_full = this.get_prefix() + "ws_get_dev_usbcount," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_set_dev_usbindex: function (index) {
ret = -1;
this.get_full = this.get_prefix() + "ws_set_dev_usbindex," + index + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_get_dev_usbindex: function () {
ret = -1;
this.get_full = this.get_prefix() + "ws_get_dev_usbindex," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_monitor_begin: function (port) {
ret = -1;
this.get_full = this.get_prefix() + "ws_monitor_begin," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_monitor_end: function () {
ret = -1;
this.get_full = this.get_prefix() + "ws_monitor_end," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_monitor_getstatus: function () {
ret = -1;
this.get_full = this.get_prefix() + "ws_monitor_getstatus," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_monitor_setmessage: function (message) {
ret = -1;
this.get_full = this.get_prefix() + "ws_monitor_setmessage," + message + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_openScanner: function (port, baud, message) {
ret = -1;
this.get_full = this.get_prefix() + "ws_openScanner," + port + "," + baud + "," + message + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_closeScanner: function (port) {
ret = -1;
this.get_full = this.get_prefix() + "ws_closeScanner," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt
});
return ret
},
ws_getBarcode: function (port, obj) {
ret = -1;
this.get_full = this.get_prefix() + "ws_getBarcode," + port + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
obj.barcode = data.barcode;
if (data.rt < 0) {
ret = data.rt
}
ret = data.rt
});
return ret
},
ws_sr_data: function (port, obj) {
var ret = -1;
var tmpobj = {
mode: 0
};
this.ws_get_mode(this.MODE_TIMEOUT, tmpobj);
this.ws_set_mode(this.MODE_TIMEOUT, 1000);
var tmpdata = this.toBase64(obj.data);
this.get_full = this.get_prefix() + "ws_sr_data," + port + "," + obj.len + "," + tmpdata + "," + (new Date()).getTime();
$.getJSON(this.get_full, function (data) {
ret = data.rt;
obj.len = data.len;
obj.data = data.data
});
this.ws_set_mode(this.MODE_TIMEOUT, tmpobj.mode);
return ret
},
getBytes: function (str) {
var byteSize = 0,
code = 0;
for (var i = 0; i < str.length; i++) {
code = str.charCodeAt(i);
if (code <= 0xff) byteSize += 1;
else byteSize += 2
}
return byteSize
},
getBytesStr: function (str, maxbytes) {
var byteSize = 0,
totalBytes = 0;
var tmpstr = "";
for (var i = 0; i < str.length; i++) {
var code = str.charCodeAt(i);
if (0x00 <= code && code <= 0xff) byteSize = 1;
else byteSize = 2;
if ((byteSize + totalBytes) > maxbytes) break;
tmpstr += str[i];
totalBytes += byteSize
}
return tmpstr
},
toBase64: function (str) {
var tmpstr = $.base64.encode(str, false);
return tmpstr
},
fromBase64: function (str) {
var tmpstr = $.base64.decode(str, true);
return tmpstr
}
};
(function ($) {
var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
a256 = '',
r64 = [256],
r256 = [256],
i = 0;
var UTF8 = {
encode: function (strUni) {
var strUtf = strUni.replace(/[\u0080-\u07ff]/g, function (c) {
var cc = c.charCodeAt(0);
return String.fromCharCode(0xc0 | cc >> 6, 0x80 | cc & 0x3f)
}).replace(/[\u0800-\uffff]/g, function (c) {
var cc = c.charCodeAt(0);
return String.fromCharCode(0xe0 | cc >> 12, 0x80 | cc >> 6 & 0x3F, 0x80 | cc & 0x3f)
});
return strUtf
},
decode: function (strUtf) {
var strUni = strUtf.replace(/[\u00e0-\u00ef][\u0080-\u00bf][\u0080-\u00bf]/g, function (c) {
var cc = ((c.charCodeAt(0) & 0x0f) << 12) | ((c.charCodeAt(1) & 0x3f) << 6) | (c.charCodeAt(2) & 0x3f);
return String.fromCharCode(cc)
}).replace(/[\u00c0-\u00df][\u0080-\u00bf]/g, function (c) {
var cc = (c.charCodeAt(0) & 0x1f) << 6 | c.charCodeAt(1) & 0x3f;
return String.fromCharCode(cc)
});
return strUni
}
};
while (i < 256) {
var c = String.fromCharCode(i);
a256 += c;
r256[i] = i;
r64[i] = b64.indexOf(c);
++i
}
function code(s, discard, alpha, beta, w1, w2) {
s = String(s);
var buffer = 0,
i = 0,
length = s.length,
result = '',
bitsInBuffer = 0;
while (i < length) {
var c = s.charCodeAt(i);
c = c < 256 ? alpha[c] : -1;
buffer = (buffer << w1) + c;
bitsInBuffer += w1;
while (bitsInBuffer >= w2) {
bitsInBuffer -= w2;
var tmp = buffer >> bitsInBuffer;
result += beta.charAt(tmp);
buffer ^= tmp << bitsInBuffer
}++i
}
if (!discard && bitsInBuffer > 0) result += beta.charAt(buffer << (w2 - bitsInBuffer));
return result
}
var Plugin = $.base64 = function (dir, input, encode) {
return input ? Plugin[dir](input, encode) : dir ? null : this
};
Plugin.btoa = Plugin.encode = function (plain, utf8encode) {
plain = Plugin.raw === false || Plugin.utf8encode || utf8encode ? UTF8.encode(plain) : plain;
plain = code(plain, false, r256, b64, 8, 6);
return plain + '===='.slice((plain.length % 4) || 4)
};
Plugin.atob = Plugin.decode = function (coded, utf8decode) {
coded = coded.replace(/[^A-Za-z0-9\+\/\=]/g, "");
coded = String(coded).split('=');
var i = coded.length;
do {
--i;
coded[i] = code(coded[i], true, r64, a256, 6, 8)
} while (i > 0);
coded = coded.join('');
return Plugin.raw === false || Plugin.utf8decode || utf8decode ? UTF8.decode(coded) : coded
}
}(jQuery));
需要用到的文件wsrProxyTest_iso15693.js
var wsrTest_iso15693 = {
wsr: null,
p: { port: 0, rt: 0 },
e: { // 错误代码
ERROR_OPENPORT: -1,
ERROR_GETCARDNO: -2,
ERROR_SELECT: -3,
ERROR_WRITEBLOCK: -4,
ERROR_READBLOCK: -5,
ERROR_DATA: -6,
ERROR_GETTAGINFO: -7,
ERROR_NOCARD: -8,
ERROR_VERIFYBLOCK: -9,
},
c: { // 测试计数
count_error_openport: 0,
count_error_getcardno: 0,
count_error_select: 0,
count_error_writeblock: 0,
count_error_readblock: 0,
count_error_data: 0,
count_error_gettaginfo: 0,
count_error_nocard: 0,
count_error_verifyblock: 0,
count_succeed: 0,
},
obj_uids:{uids:""}, // 检索出的标签
uid_selected:"", // 选定的标签
obj_uid: { // 选定标签的信息
flag_dsfid:0,
flag_afi:0,
flag_memory:0,
flag_producer:0,
uid:"",
dsfid:0,
afi:0,
block_count:8,
block_size:4
},
b: [], // 标签可写块号数组
uids:[], // 检索到的标签数组
mark_stop: false, // 停止自检标志 true - 停止; false - 不停止
testOption: {
rwb_count: 0,
testcount: 0,
},
init: function () {
this.wsr = wsrProxy;
this.initTestOption();
this.initBlock();
// this.initBlock1();
},
initTestOption: function () {
this.testOption.rwb_count = 28;
},
// 简单标记不可写的块
initBlock: function () {
this.b.length = 0;
this.testOption.rwb_count = this.obj_uid.block_count;
for (var i = 0; i < this.obj_uid.block_count; i++)
{
this.b.push({ no: i, data: "", status:"", isRW: true });
}
},
// 深度标记不可写的块(密码无法验证通过的扇区,或寿命已到最大写次数的块)
initBlock1: function () {
// 保存原数据类型
this.p.client_datatype = this.wsr.client_datatype;
// 打开端口
this.p.rt = this.wsr.ws_openPort(this.p.port);
if (this.p.rt < 0) return e.ERROR_OPENPORT;
try {
// 设置数据类型
this.wsr.client_datatype = 1;
// 标签检索
this.uids.length=0;
this.uid_selected="";
this.p.rt = this.wsr.ws_iso15693_getTags(this.p.port, this.obj_uids);
if (this.p.rt = 0) return this.e.ERROR_NOCARD;
if (this.p.rt < 0) return this.e.ERROR_GETCARDNO;
for (var i=0;i<this.p.rt;i++)
this.uids.push(obj_uids.uids.substr(i*16,16));
// 随机选定标签
var index = parseInt(Math.round(Math.random() * this.p.rt), 10);
if (index>=3) index=0;
this.uid_selected=this.uids[index];
this.p.rt = this.wsr.ws_iso15693_select(this.p.port, this.uid_selected);
if (this.p.rt < 0 ) return this.e.ERROR_SELECT;
// 获取标签信息
this.obj_uid.uid = this.uid_selected;
this.p.rt = this.wsr.ws_iso15693_getTagInfoE(this.p.port,this.obj_uid);
if (this.p.rt < 0 ) return this.e.ERROR_GETTAGINFO;
// 读取块数据和块状态,被锁定的块标记为不可读写
var obj={data:"",status:"",};
var tmpi = "";
this.p.rt = this.wsr.ws_iso15693_readBlockE(this.p.port,0,this.obj_uid.block_count,obj);
if (this.p.rt < 0) return this.e.ERROR_READBLOCK;
for(var i = 0; i < this.obj_uid.block_count; i++)
{
this.b[i].data = obj.data.substr(i*obj_uid.block_size*2,obj_uid.block_size*2);
this.b[i].status = obj.status.substr(i*2,2);
if (this.b[i].status=="01")
{
this.b[i].isRW = false;
this.testOption.rwb_count--;
}
}
return 1;
}
finally {
this.wsr.client_datatype = this.p.client_datatype;
this.p.rt = this.wsr.ws_closePort(this.p.port);
}
},
// 随机生成可写块号
generate_block: function () {
// 生成可读块随机索引号
var i = parseInt(Math.round(Math.random() * this.testOption.rwb_count), 10);
if (i < 0) i = this.testOption.rwb_count - 1;
if (i > (this.testOption.rwb_count - 1)) i = 0;
// 在所有可读块中定位与随机索引号匹配的可读块
var index = -1;
for (var j = 0; j < this.obj_uid.block_count; j++) {
if (!this.b[j].isRW) continue; // 忽略不可读块
index++;
if (index == i) return j; // 锁定可读块并与随机索引序列一致
}
},
// 随机生成16进制字符串
generate_strHex: function () {
var strHex = "0123456789ABCDEF";
var tmpstr = "";
for (var i = 0; i < this.obj_uid.block_size*2; i++) {
index = parseInt(Math.round(Math.random() * 16));
if (index < 0) index = 15;
if (index > 15) index = 0;
tmpstr += strHex[index];
}
return tmpstr;
},
// 检查是否空白未用过的卡
isBlankCard: function () {
// 保存原数据类型
this.p.client_datatype = this.wsr.client_datatype;
p.rt = this.wsr.ws_openPort(p.port);
if (p.rt < 0)
return e.ERROR_OPENPORT;
try {
wsr.client_datatype = 1;
p.cardno = "";
p.rt = this.wsr.ws_getCardNo_String(p.port, p);
if (p.rt < 0) return e.ERROR_OPENPORT;
// 读块数据,检查数据是否为全0
for (var i = 0; i < b.length; i++) {
p.data = "";
p.rt = this.wsr.ws_readBlock(p.port, b[i], p);
if (p.rt < 0) return e.ERROR_READBLOCK;
for (var j = 0; j < 32; j++) {
if (this.p.data[j] != "0")
return this.e.ERROR_DATA;
}
}
return 1;
}
finally {
this.wsr.client_datatype = p.client_datatype;
this.p.rt = wsrProxy.ws_closePort(p.port);
}
},
test_before: function () {
// testReader.emit("test","测试开始");
this.c.count_error_openport = 0;
this.c.count_error_getcardno = 0;
this.c.count_error_select = 0;
this.c.count_error_writeblock = 0;
this.c.count_error_readblock = 0;
this.c.count_error_data = 0;
this.c.count_error_verifyblock = 0;
this.c.count_error_nocard = 0;
this.c.count_error_gettaginfo = 0;
this.c.count_succeed = 0;
this.p.rt = this.wsr.ws_openPort(this.p.port);
if (this.p.rt < 0) {
//postMessage(e.ERROR_OPENPORT);
this.c.count_error_openport++;
return this.p.rt;
}
// 保存原数据类型
this.p.client_datatype = wsr.client_datatype;
this.wsr.client_datatype = 1;
this.testOption.testcount = 0;
this.mark_stop = false;
},
test_after: function () {
this.wsr.client_datatype = this.p.client_datatype;
//this.p.rt = wsr.ws_closePort(this.p.port);
},
test_slice: function () {
try
{
this.testOption.testcount++;
// 标签检索
this.uids.length=0;
this.uid_selected="";
this.p.rt = this.wsr.ws_iso15693_getTags(this.p.port, this.obj_uids);
if (this.p.rt = 0)
{
this.c.count_error_nocard++;
return this.e.ERROR_NOCARD;
}
if (this.p.rt < 0)
{
this.c.count_error_getcardno++;
return this.e.ERROR_GETCARDNO;
}
for (var i=0;i<this.p.rt;i++)
this.uids.push(obj_uids.uids.substr(i*16,16));
// 随机选定标签
var index = parseInt(Math.round(Math.random() * this.p.rt), 10);
if (index>=3) index=0;
this.uid_selected=this.uids[index];
this.p.rt = this.wsr.ws_iso15693_select(this.p.port, this.uid_selected);
if (this.p.rt < 0 ) return this.e.ERROR_SELECT;
// 获取标签信息
this.obj_uid.uid = this.uid_selected;
this.p.rt = this.wsr.ws_iso15693_getTagInfoE(this.p.port,this.obj_uid);
if (this.p.rt < 0 ) return this.e.ERROR_GETTAGINFO;
// 生成随机可以写的块
this.p.block = this.generate_block();
// 生成随机16进制数据
this.p.data_write = this.generate_strHex();
// 写块数据
this.p.rt = this.wsr.ws_iso15693_writeBlock(this.p.port,this.p.block,1,this.p.data_write);
if (this.p.rt < 0)
{
this.c.count_error_writeblock++;
return this.e.ERROR_WRITEBLOCK;
}
// 读块数据
var obj_read={data:"",status:"",};
this.p.rt = this.wsr.ws_iso15693_readBlockE(this.p.port,this.p.block,1,obj_read);
if (this.p.rt < 0)
{
this.c.count_error_readblock++;
return this.e.ERROR_READBLOCK;
}
// 比对写入和读出的数据是否一致
if (this.obj_read.data != this.p.data_write) {
this.c.count_error_verifyblock++;
return this.e.ERROR_VERIFYBLOCK;
}
this.c.count_succeed++;
return 1;
}
finally
{
var tbTestCount = document.getElementById('tbTestCount');
var tbTestCount1 = document.getElementById('tbTestCount1');
tbTestCount.value="设备自检次数:" + this.testOption.testcount +
" 测试通过次数:" + this.c.count_succeed +
" 读卡号无卡次数:" + this.c.count_error_nocard +
" 读卡号出错次数:" + this.c.count_error_getcardno;
tbTestCount1.value=
" 写数据出错次数:" + this.c.count_error_writeblock +
" 读数据出错次数:" + this.c.count_error_readblock +
" 读写数据验证出错:" + this.c.count_error_verifyblock;
}
}
};