コード例 #1
0
    @Override
    public void run() {
      byte[] dataReceived = null;

      while (working.get()) {
        int numberBytes =
            connection.bulkTransfer(
                inEndpoint,
                serialBuffer.getBufferCompatible(),
                SerialBuffer.DEFAULT_READ_BUFFER_SIZE,
                0);

        if (numberBytes > 0) {
          dataReceived = serialBuffer.getDataReceivedCompatible(numberBytes);

          // FTDI devices reserves two first bytes of an IN endpoint with info about
          // modem and Line.
          if (isFTDIDevice()) {
            if (dataReceived.length > 2) {
              dataReceived = FTDISerialDevice.FTDIUtilities.adaptArray(dataReceived);
              callback.onReceivedData(dataReceived);
            }
          } else {
            callback.onReceivedData(dataReceived);
          }
        }
      }
    }
コード例 #2
0
    @Override
    public void run() {
      while (working.get()) {
        UsbRequest request = connection.requestWait();
        if (request != null
            && request.getEndpoint().getType() == UsbConstants.USB_ENDPOINT_XFER_BULK
            && request.getEndpoint().getDirection() == UsbConstants.USB_DIR_IN) {
          byte[] data = serialBuffer.getDataReceived();

          // FTDI devices reserves two first bytes of an IN endpoint with info about
          // modem and Line.
          if (isFTDIDevice()) {
            if (data.length > 2) {
              data = FTDISerialDevice.FTDIUtilities.adaptArray(data);
              // Clear buffer, execute the callback
              serialBuffer.clearReadBuffer();
              onReceivedData(data);
            }
          } else {
            // Clear buffer, execute the callback
            serialBuffer.clearReadBuffer();
            onReceivedData(data);
          }
          // Queue a new request
          requestIN.queue(serialBuffer.getReadBuffer(), SerialBuffer.DEFAULT_READ_BUFFER_SIZE);
        }
      }
    }