import * as ASCIIUtils from "@/uni_modules/wrs-js-modbusCRCHex/js_sdk/wrs-ASCIIUtils";
// import {logs} from "@/utils/util";
import {Base} from "@/utils/usbSerial/base";
import {logs} from "@/utils/util";

export class ScanMachine extends Base {

  constructor(topClass, usbSerial) {
    super(topClass, usbSerial)

    this.id = 'scan'
    this.title = '扫码器'
    this.config = {
      baudRate: 115200,
      dataBits: 8,
      stopBits: 1,
    }
  }


  read(resp) {
    logs('read', this.id, resp)
    if (!resp.data) return;
    let data = resp.data
    if (data.startsWith('02') && data.endsWith('03')) {
      resp.value = data.substring(2, data.length - 2);
    }
    resp.value = ASCIIUtils.decodeUtf8(data)
    // logs('scan usbSerial.read', resp)
    if (this.notifyFun) this.notifyFun(resp)
  }


}
