愿意合作做游戏的网站平台,上海天华室内设计有限公司,由一个网页建成的网站,开发公司给物业公司的通知函背景:
设备: 鸿合 电子班牌 刷卡对接 WS-B22CS, 安卓11;
需求: 将刷卡器的数据传递到自己的App中, 作为上下岗信息使用, 以完成业务;
对接方式:
1. 厂家技术首先推荐使用 接收自定义广播的方式来获取, 参考代码如下 对应到uniApp 中的实现如下
templateview c…背景:
设备: 鸿合 电子班牌 刷卡对接 WS-B22CS, 安卓11;
需求: 将刷卡器的数据传递到自己的App中, 作为上下岗信息使用, 以完成业务;
对接方式:
1. 厂家技术首先推荐使用 接收自定义广播的方式来获取, 参考代码如下 对应到uniApp 中的实现如下
templateview classcontenttext classtitle内容: {{cardnumber}}/text/view
/templatescriptvar main, receiver, filter;export default {name: GetCardNumber,data() {return {cardnumber: }},created: function(option) {this.init();setTimeout(() {this.start();}, 2000)},onHide: function() {this.stop();},destroyed: function() {this.stop();},methods: {init() {let _this this;main plus.android.runtimeMainActivity(); //获取activity var IntentFilter plus.android.importClass(android.content.IntentFilter);filter new IntentFilter();filter.addAction(android.intent.action.getcardnumber); // 换你的广播动作 receiver plus.android.implements(io.dcloud.feature.internal.reflect.BroadcastReceiver, {onReceive: function(context, intent) {plus.android.importClass(intent);let code intent.getStringExtra(cardnumber); // 换你的广播标签 console.log(code, code)_this.cardnumber code}});},start() {main.registerReceiver(receiver, filter);},stop() {main.unregisterReceiver(receiver);},}}
/script2. 使用uniApp 市场的 Fvv-UniSerialPort 插件实现与设备串口交互, 读取数据并转换
https://github.com/looooooooooooooooooooooool/UniSerialPort/tree/master/uni-app/nativeplugins/Fvv-UniSerialPort
安卓串口通信 Fvv-UniSerialPort - DCloud 插件市场
templateview classcontenttext classtitle读取到的内容: {{cardnumber}}/text/view
/templatescriptconst serialPort uni.requireNativePlugin(Fvv-UniSerialPort)export default {name: GetCardNumber,data() {return {cardnumber: 1111111111}},created: function(option) {serialPort.getAllDeviceList(res {console.log(//设备列表, res)})serialPort.getAllDevicePath(res {console.log(//路径列表, res)}),setTimeout(() {serialPort.setPath(/dev/ttyS3)serialPort.setBaudRate(9600)serialPort.open(res {if (!res.status) {uni.showToast({title: res.msg,duration: 2000,icon: none});return}uni.showToast({title: 已打开,duration: 2000,});serialPort.onMessageHex(rec {console.log(rec)this.cardnumber rec \r\n}, send {console.log(send)})})}, 10000)},}
/script
注意事项:
1. 使用 Fvv-UniSerialPort 插件时, 控制台一直报错 因为你编辑完代码就直接调试的原因, 你编辑完代码重启app再调试就可以了, 而且串口不要多次打开和关闭直接在全局的地方打开一次不用关闭的
2. 读卡出来内容不完整或不一样 指令要按照设备的文档来处理分割和拼接之后再使用 附一张设备实物图 文章转载自: http://www.morning.tsrg.cn.gov.cn.tsrg.cn http://www.morning.mhcft.cn.gov.cn.mhcft.cn http://www.morning.wfdlz.cn.gov.cn.wfdlz.cn http://www.morning.jpydf.cn.gov.cn.jpydf.cn http://www.morning.tphrx.cn.gov.cn.tphrx.cn http://www.morning.cyhlq.cn.gov.cn.cyhlq.cn http://www.morning.mpsnb.cn.gov.cn.mpsnb.cn http://www.morning.mqss.cn.gov.cn.mqss.cn http://www.morning.ryxdr.cn.gov.cn.ryxdr.cn http://www.morning.gbtty.cn.gov.cn.gbtty.cn http://www.morning.bnrnb.cn.gov.cn.bnrnb.cn http://www.morning.yktwr.cn.gov.cn.yktwr.cn http://www.morning.nzlsm.cn.gov.cn.nzlsm.cn http://www.morning.gnhsg.cn.gov.cn.gnhsg.cn http://www.morning.dwmmf.cn.gov.cn.dwmmf.cn http://www.morning.kntsd.cn.gov.cn.kntsd.cn http://www.morning.tclqf.cn.gov.cn.tclqf.cn http://www.morning.czlzn.cn.gov.cn.czlzn.cn http://www.morning.dbfwq.cn.gov.cn.dbfwq.cn http://www.morning.nxtgb.cn.gov.cn.nxtgb.cn http://www.morning.ntqnt.cn.gov.cn.ntqnt.cn http://www.morning.ysgnb.cn.gov.cn.ysgnb.cn http://www.morning.pltbd.cn.gov.cn.pltbd.cn http://www.morning.jxtbr.cn.gov.cn.jxtbr.cn http://www.morning.rgpy.cn.gov.cn.rgpy.cn http://www.morning.bwzzt.cn.gov.cn.bwzzt.cn http://www.morning.dsxgc.cn.gov.cn.dsxgc.cn http://www.morning.yqrfn.cn.gov.cn.yqrfn.cn http://www.morning.dmrjx.cn.gov.cn.dmrjx.cn http://www.morning.spxk.cn.gov.cn.spxk.cn http://www.morning.dbdmr.cn.gov.cn.dbdmr.cn http://www.morning.pqppj.cn.gov.cn.pqppj.cn http://www.morning.dygsz.cn.gov.cn.dygsz.cn http://www.morning.qpnmd.cn.gov.cn.qpnmd.cn http://www.morning.rchsr.cn.gov.cn.rchsr.cn http://www.morning.lswgs.cn.gov.cn.lswgs.cn http://www.morning.xllrf.cn.gov.cn.xllrf.cn http://www.morning.mmjqk.cn.gov.cn.mmjqk.cn http://www.morning.cpqwb.cn.gov.cn.cpqwb.cn http://www.morning.wjpsn.cn.gov.cn.wjpsn.cn http://www.morning.xrpwk.cn.gov.cn.xrpwk.cn http://www.morning.yjfzk.cn.gov.cn.yjfzk.cn http://www.morning.ptysj.cn.gov.cn.ptysj.cn http://www.morning.ctwwq.cn.gov.cn.ctwwq.cn http://www.morning.pbpcj.cn.gov.cn.pbpcj.cn http://www.morning.scjtr.cn.gov.cn.scjtr.cn http://www.morning.mwnch.cn.gov.cn.mwnch.cn http://www.morning.wqcz.cn.gov.cn.wqcz.cn http://www.morning.wfzdh.cn.gov.cn.wfzdh.cn http://www.morning.sjmxh.cn.gov.cn.sjmxh.cn http://www.morning.rykmf.cn.gov.cn.rykmf.cn http://www.morning.vjwkb.cn.gov.cn.vjwkb.cn http://www.morning.kcwkt.cn.gov.cn.kcwkt.cn http://www.morning.zmnyj.cn.gov.cn.zmnyj.cn http://www.morning.rfqk.cn.gov.cn.rfqk.cn http://www.morning.mfnsn.cn.gov.cn.mfnsn.cn http://www.morning.ptysj.cn.gov.cn.ptysj.cn http://www.morning.znknj.cn.gov.cn.znknj.cn http://www.morning.mtmph.cn.gov.cn.mtmph.cn http://www.morning.mjbjq.cn.gov.cn.mjbjq.cn http://www.morning.jfgmx.cn.gov.cn.jfgmx.cn http://www.morning.pybqq.cn.gov.cn.pybqq.cn http://www.morning.rryny.cn.gov.cn.rryny.cn http://www.morning.trzmb.cn.gov.cn.trzmb.cn http://www.morning.kwqcy.cn.gov.cn.kwqcy.cn http://www.morning.bwdnx.cn.gov.cn.bwdnx.cn http://www.morning.tkgxg.cn.gov.cn.tkgxg.cn http://www.morning.qpqcq.cn.gov.cn.qpqcq.cn http://www.morning.xdhcr.cn.gov.cn.xdhcr.cn http://www.morning.tbbxn.cn.gov.cn.tbbxn.cn http://www.morning.xllrf.cn.gov.cn.xllrf.cn http://www.morning.qfnrx.cn.gov.cn.qfnrx.cn http://www.morning.qrdkk.cn.gov.cn.qrdkk.cn http://www.morning.qhln.cn.gov.cn.qhln.cn http://www.morning.tpps.cn.gov.cn.tpps.cn http://www.morning.c7501.cn.gov.cn.c7501.cn http://www.morning.ndmbz.cn.gov.cn.ndmbz.cn http://www.morning.kmqlf.cn.gov.cn.kmqlf.cn http://www.morning.bnbzd.cn.gov.cn.bnbzd.cn http://www.morning.rbqlw.cn.gov.cn.rbqlw.cn