scanMachine.js 816 B

12345678910111213141516171819202122232425262728293031323334
  1. import * as ASCIIUtils from "@/uni_modules/wrs-js-modbusCRCHex/js_sdk/wrs-ASCIIUtils";
  2. // import {logs} from "@/utils/util";
  3. import {Base} from "@/utils/usbSerial/base";
  4. import {logs} from "@/utils/util";
  5. export class ScanMachine extends Base {
  6. constructor(topClass, usbSerial) {
  7. super(topClass, usbSerial)
  8. this.id = 'scan'
  9. this.title = '扫码器'
  10. this.config = {
  11. baudRate: 115200,
  12. dataBits: 8,
  13. stopBits: 1,
  14. }
  15. }
  16. read(resp) {
  17. logs('read', this.id, resp)
  18. if (!resp.data) return;
  19. let data = resp.data
  20. if (data.startsWith('02') && data.endsWith('03')) {
  21. resp.value = data.substring(2, data.length - 2);
  22. }
  23. resp.value = ASCIIUtils.decodeUtf8(data)
  24. // logs('scan usbSerial.read', resp)
  25. if (this.notifyFun) this.notifyFun(resp)
  26. }
  27. }