WebUSB reading data from a serial port not responding

时间:2019-06-01 14:00:19

标签: javascript serial-port webusb

I am using WEBUSB to read data from a weighing machine. The device is returning with status: stall when data is sent on the control transfer .

The Serial port from the weighing machine has been connected to RS232 USB to Serial port converter (BAFO BF-810 which has IC PL2303) and the usb is connected to the computer. Reading data from the same IC PL2303 was working before do not know suddenly why this issue has popped up.


  vendorRead(value, index) {
    return this.device.controlTransferIn({
      requestType: 'class',
      request: 0x01,
      recipient: 'device',
      value: value,
      index: index
    }, 1).then(buffer => buffer[0]);
  }

  vendorWrite(value, index) {
    return this.device.controlTransferOut({
      requestType: 'class',
      request: 0x01,
      recipient: 'device',
      value: value,
      index: index
    });
  }

  setBaudRate() {
    return this.device.controlTransferIn({
      requestType: 'class',
      request: 0x21,
      recipient: 'interface',
      value: 0,
      index: 0
    }, 7).then((data) => {
      console.log(data)
      const parameters = data.data.buffer;
      parameters[4] = 0;
      parameters[5] = 0;
      parameters[6] = 0;
      return this.device.controlTransferOut({
        requestType: 'class',
        request: 0x20,
        recipient: 'interface', 
        value: 0,
        index: 0
      }, parameters)
    }).then(() => this.vendorWrite(0x0, 0x0)) // no flow control
    .then(() => this.vendorWrite(8, 0)) // reset upstream data pipes
    .then(() => this.vendorWrite(9, 0));
  }

  initialize(device, range) {
    this.device = device;
    this.range = range;
    this.active = true;
    this.device.open()
    .then(() => this.device.selectConfiguration(1))
    .then(() => {
      return this.device.claimInterface(0)
    })
    .then(() => this.vendorRead(0x8484, 0))
    .then(() => this.vendorWrite(0x0404, 0))
    .then(() => this.vendorRead(0x8484, 0))
    .then(() => this.vendorRead(0x8383, 0))
    .then(() => this.vendorRead(0x8484, 0))
    .then(() => this.vendorWrite(0x0404, 1))
    .then(() => this.vendorRead(0x8484, 0))
    .then(() => this.vendorRead(0x8383, 0))
    .then(() => this.vendorWrite(0, 1))
    .then(() => this.vendorWrite(1, 0))
    .then(() => this.vendorWrite(2, 0x44))
    .then(() => this.setBaudRate())
    .then(() => this.readData())
    .catch(err => {
      console.log(err);
    });
    return this.readingChanged;
  }

Got stuck here for the past 1 week. Any help will be greatly appreciated . Thanks in Advance.

0 个答案:

没有答案