类android.hardware.usb.UsbEndpoint源码实例Demo

下面列出了怎么用android.hardware.usb.UsbEndpoint的API类实例代码及写法,或者点击链接到github查看源代码。

@Override
protected void openInt(UsbDeviceConnection connection) throws IOException {
	for (int i = 0; i < mDevice.getInterfaceCount(); i++) {
		UsbInterface usbIface = mDevice.getInterface(i);
		if (!mConnection.claimInterface(usbIface, true)) {
			throw new IOException("Could not claim data interface");
		}
	}

	UsbInterface dataIface = mDevice.getInterface(mDevice.getInterfaceCount() - 1);
	for (int i = 0; i < dataIface.getEndpointCount(); i++) {
		UsbEndpoint ep = dataIface.getEndpoint(i);
		if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
			if (ep.getDirection() == UsbConstants.USB_DIR_IN) {
				mReadEndpoint = ep;
			} else {
				mWriteEndpoint = ep;
			}
		}
	}

	initialize();
	setBaudRate(DEFAULT_BAUD_RATE);
}
 
源代码2 项目: yubikit-android   文件: UsbSession.java
/**
 * Gets bulkin and bulkout endpoints of specified interface
 * @param usbInterface interface of usb device
 * @return the pair of endpoints: in and out
 */
private Pair<UsbEndpoint, UsbEndpoint> findEndpoints(UsbInterface usbInterface, int type) {
    UsbEndpoint endpointIn = null;
    UsbEndpoint endpointOut = null;

    for (int i = 0; i < usbInterface.getEndpointCount(); i++) {
        UsbEndpoint endpoint = usbInterface.getEndpoint(i);
        if (endpoint.getType() == type) {
            if (endpoint.getDirection() == UsbConstants.USB_DIR_IN) {
                endpointIn = endpoint;
            } else {
                endpointOut = endpoint;
            }
        }
    }
    return new Pair<>(endpointIn, endpointOut);
}
 
源代码3 项目: UsbHid   文件: UsbHidDevice.java
private UsbHidDevice(UsbDevice usbDevice, UsbInterface usbInterface, UsbManager usbManager) {
    mUsbDevice = usbDevice;
    mUsbInterface = usbInterface;
    mUsbManager= usbManager;

    for (int i = 0; i < mUsbInterface.getEndpointCount(); i++) {
        UsbEndpoint endpoint = mUsbInterface.getEndpoint(i);
        int dir = endpoint.getDirection();
        int type = endpoint.getType();
        if (mInUsbEndpoint == null && dir == UsbConstants.USB_DIR_IN && type == UsbConstants.USB_ENDPOINT_XFER_INT) {
            mInUsbEndpoint = endpoint;
        }
        if (mOutUsbEndpoint == null && dir == UsbConstants.USB_DIR_OUT && type == UsbConstants.USB_ENDPOINT_XFER_INT) {
            mOutUsbEndpoint = endpoint;
        }
    }
}
 
源代码4 项目: xmrwallet   文件: BTChipTransportAndroidHID.java
public static BTChipTransport open(UsbManager manager, UsbDevice device) throws IOException {
    UsbDeviceConnection connection = manager.openDevice(device);
    if (connection == null) throw new IOException("Device not connected");
    // Must only be called once permission is granted (see http://developer.android.com/reference/android/hardware/usb/UsbManager.html)
    // Important if enumerating, rather than being awaken by the intent notification
    UsbInterface dongleInterface = device.getInterface(0);
    UsbEndpoint in = null;
    UsbEndpoint out = null;
    for (int i = 0; i < dongleInterface.getEndpointCount(); i++) {
        UsbEndpoint tmpEndpoint = dongleInterface.getEndpoint(i);
        if (tmpEndpoint.getDirection() == UsbConstants.USB_DIR_IN) {
            in = tmpEndpoint;
        } else {
            out = tmpEndpoint;
        }
    }
    connection.claimInterface(dongleInterface, true);
    return new BTChipTransportAndroidHID(connection, dongleInterface, in, out);
}
 
private void openSingleInterface() throws IOException {
    // the following code is inspired by the cdc-acm driver in the linux kernel

    mControlIndex = 0;
    mControlInterface = mDevice.getInterface(0);
    mDataInterface = mDevice.getInterface(0);
    if (!mConnection.claimInterface(mControlInterface, true)) {
        throw new IOException("Could not claim shared control/data interface");
    }

    for (int i = 0; i < mControlInterface.getEndpointCount(); ++i) {
        UsbEndpoint ep = mControlInterface.getEndpoint(i);
        if ((ep.getDirection() == UsbConstants.USB_DIR_IN) && (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_INT)) {
            mControlEndpoint = ep;
        } else if ((ep.getDirection() == UsbConstants.USB_DIR_IN) && (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK)) {
            mReadEndpoint = ep;
        } else if ((ep.getDirection() == UsbConstants.USB_DIR_OUT) && (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK)) {
            mWriteEndpoint = ep;
        }
    }
    if (mControlEndpoint == null) {
        throw new IOException("No control endpoint");
    }
}
 
源代码6 项目: yubikit-android   文件: UsbSessionTest.java
public void mockOutError(){
    Mockito.when(connection.bulkTransfer(
            Mockito.any(UsbEndpoint.class),
            Mockito.any(byte[].class),
            Mockito.anyInt(),
            Mockito.anyInt()
    )).thenReturn(-1);
}
 
源代码7 项目: yubikit-android   文件: UsbSessionTest.java
public void mockInError() {
    Mockito.when(connection.bulkTransfer(
            Mockito.any(UsbEndpoint.class),
            Mockito.any(byte[].class),
            Mockito.anyInt(),
            Mockito.anyInt(),
            Mockito.anyInt()
    )).thenReturn(-1);
}
 
源代码8 项目: green_android   文件: BTChipTransportAndroidHID.java
public BTChipTransportAndroidHID(UsbDeviceConnection connection, UsbInterface dongleInterface, UsbEndpoint in, UsbEndpoint out, int timeout, boolean ledger) {
	this.connection = connection;
	this.dongleInterface = dongleInterface;
	this.in = in;
	this.out = out;
	this.ledger = ledger;
	// Compatibility with old prototypes, to be removed
	if (!this.ledger) {
		this.ledger = (in.getEndpointNumber() != out.getEndpointNumber());
	}
	this.timeout = timeout;
	transferBuffer = new byte[HID_BUFFER_SIZE];
}
 
public BTChipTransportAndroidWinUSB(UsbDeviceConnection connection, UsbInterface dongleInterface, UsbEndpoint in, UsbEndpoint out, int timeout) {
	this.connection = connection;
	this.dongleInterface = dongleInterface;
	this.in = in;
	this.out = out;
	this.timeout = timeout;
	transferBuffer = new byte[260];
}
 
源代码10 项目: green_android   文件: BTChipTransportAndroid.java
public static BTChipTransport open(UsbManager manager, UsbDevice device) {
	// Must only be called once permission is granted (see http://developer.android.com/reference/android/hardware/usb/UsbManager.html)
	// Important if enumerating, rather than being awaken by the intent notification
	UsbInterface dongleInterface = device.getInterface(0);
       UsbEndpoint in = null;
       UsbEndpoint out = null;
       boolean ledger; 
       for (int i=0; i<dongleInterface.getEndpointCount(); i++) {
           UsbEndpoint tmpEndpoint = dongleInterface.getEndpoint(i);
           if (tmpEndpoint.getDirection() == UsbConstants.USB_DIR_IN) {
               in = tmpEndpoint;
           }
           else {
               out = tmpEndpoint;
           }
       }
       UsbDeviceConnection connection = manager.openDevice(device);
       if (connection == null) {
           return null;
       }
       connection.claimInterface(dongleInterface, true);
       ledger = ((device.getProductId() == PID_HID_LEDGER) || (device.getProductId() == PID_HID_LEDGER_PROTON)
	|| (device.getProductId() == PID_NANOS) || (device.getProductId() == PID_BLUE) || (device.getProductId() == PID_NANOX));
       if (device.getProductId() == PID_WINUSB) {
       	return new BTChipTransportAndroidWinUSB(connection, dongleInterface, in, out, TIMEOUT);
       }
       else {
       	return new BTChipTransportAndroidHID(connection, dongleInterface, in, out, TIMEOUT, ledger);
       }
}
 
源代码11 项目: green_android   文件: Trezor.java
private Trezor(final UsbDevice device, final UsbDeviceConnection conn,
               final UsbEndpoint readEndpoint, final UsbEndpoint writeEndpoint) {
    mVendorId = device.getVendorId();
    mProductId = device.getProductId();
    mConn = conn;
    mReadEndpoint = readEndpoint;
    mWriteEndpoint = writeEndpoint;
    mSerial = mConn.getSerial();
}
 
源代码12 项目: remoteyourcam-usb   文件: PtpUsbConnection.java
public PtpUsbConnection(UsbDeviceConnection connection, UsbEndpoint bulkIn, UsbEndpoint bulkOut, int vendorId,
        int productId) {
    this.connection = connection;
    this.bulkIn = bulkIn;
    this.bulkOut = bulkOut;
    this.vendorId = vendorId;
    this.productId = productId;
}
 
源代码13 项目: Chorus-RF-Laptimer   文件: FtdiSerialDriver.java
@Override
public int write(byte[] src, int timeoutMillis) throws IOException {
    final UsbEndpoint endpoint = mDevice.getInterface(0).getEndpoint(1);
    int offset = 0;

    while (offset < src.length) {
        final int writeLength;
        final int amtWritten;

        synchronized (mWriteBufferLock) {
            final byte[] writeBuffer;

            writeLength = Math.min(src.length - offset, mWriteBuffer.length);
            if (offset == 0) {
                writeBuffer = src;
            } else {
                // bulkTransfer does not support offsets, make a copy.
                System.arraycopy(src, offset, mWriteBuffer, 0, writeLength);
                writeBuffer = mWriteBuffer;
            }

            amtWritten = mConnection.bulkTransfer(endpoint, writeBuffer, writeLength,
                    timeoutMillis);
        }

        if (amtWritten <= 0) {
            throw new IOException("Error writing " + writeLength
                    + " bytes at offset " + offset + " length=" + src.length);
        }

        Log.d(TAG, "Wrote amtWritten=" + amtWritten + " attempted=" + writeLength);
        offset += amtWritten;
    }
    return offset;
}
 
源代码14 项目: xmrwallet   文件: BTChipTransportAndroidHID.java
public BTChipTransportAndroidHID(UsbDeviceConnection connection, UsbInterface dongleInterface, UsbEndpoint in, UsbEndpoint out) {
    this.connection = connection;
    this.dongleInterface = dongleInterface;
    this.in = in;
    this.out = out;
    transferBuffer = new byte[HID_BUFFER_SIZE];
}
 
源代码15 项目: OkUSB   文件: FtdiSerialDriver.java
@Override
public int write(byte[] src, int timeoutMillis) throws IOException {
    final UsbEndpoint endpoint = mDevice.getInterface(0).getEndpoint(1);
    int offset = 0;

    while (offset < src.length) {
        final int writeLength;
        final int amtWritten;

        synchronized (mWriteBufferLock) {
            final byte[] writeBuffer;

            writeLength = Math.min(src.length - offset, mWriteBuffer.length);
            if (offset == 0) {
                writeBuffer = src;
            } else {
                // bulkTransfer does not support offsets, make a copy.
                System.arraycopy(src, offset, mWriteBuffer, 0, writeLength);
                writeBuffer = mWriteBuffer;
            }

            amtWritten = mConnection.bulkTransfer(endpoint, writeBuffer, writeLength,
                    timeoutMillis);
        }

        if (amtWritten <= 0) {
            throw new IOException("Error writing " + writeLength
                    + " bytes at offset " + offset + " length=" + src.length);
        }

        Log.d(TAG, "Wrote amtWritten=" + amtWritten + " attempted=" + writeLength);
        offset += amtWritten;
    }
    return offset;
}
 
源代码16 项目: usb-with-serial-port   文件: FtdiSerialDriver.java
@Override
public int write(byte[] src, int timeoutMillis) throws IOException {
    final UsbEndpoint endpoint = mDevice.getInterface(0).getEndpoint(1);
    int offset = 0;

    while (offset < src.length) {
        final int writeLength;
        final int amtWritten;

        synchronized (mWriteBufferLock) {
            final byte[] writeBuffer;

            writeLength = Math.min(src.length - offset, mWriteBuffer.length);
            if (offset == 0) {
                writeBuffer = src;
            } else {
                // bulkTransfer does not support offsets, make a copy.
                System.arraycopy(src, offset, mWriteBuffer, 0, writeLength);
                writeBuffer = mWriteBuffer;
            }
            if (endpoint != null && mConnection != null) {
                amtWritten = mConnection.bulkTransfer(endpoint, writeBuffer, writeLength, timeoutMillis);
            } else {
                throw new IOException();
            }
        }

        if (amtWritten <= 0) {
            throw new IOException("Error writing " + writeLength + " bytes at offset " + offset + " length=" + src.length);
        }

        L.INSTANCE.d("Wrote amtWritten=" + amtWritten + " attempted=" + writeLength);
        offset += amtWritten;
    }
    return offset;
}
 
源代码17 项目: xDrip   文件: FtdiSerialDriver.java
@Override
public int write(byte[] src, int timeoutMillis) throws IOException {
    final UsbEndpoint endpoint = mDevice.getInterface(0).getEndpoint(1);
    int offset = 0;

    while (offset < src.length) {
        final int writeLength;
        final int amtWritten;

        synchronized (mWriteBufferLock) {
            final byte[] writeBuffer;

            writeLength = Math.min(src.length - offset, mWriteBuffer.length);
            if (offset == 0) {
                writeBuffer = src;
            } else {
                // bulkTransfer does not support offsets, make a copy.
                System.arraycopy(src, offset, mWriteBuffer, 0, writeLength);
                writeBuffer = mWriteBuffer;
            }

            amtWritten = mConnection.bulkTransfer(endpoint, writeBuffer, writeLength,
                    timeoutMillis);
        }

        if (amtWritten <= 0) {
            throw new IOException("Error writing " + writeLength
                    + " bytes at offset " + offset + " length=" + src.length);
        }

        Log.d(TAG, "Wrote amtWritten=" + amtWritten + " attempted=" + writeLength);
        offset += amtWritten;
    }
    return offset;
}
 
源代码18 项目: xDrip-plus   文件: FtdiSerialDriver.java
@Override
public int write(byte[] src, int timeoutMillis) throws IOException {
    final UsbEndpoint endpoint = mDevice.getInterface(0).getEndpoint(1);
    int offset = 0;

    while (offset < src.length) {
        final int writeLength;
        final int amtWritten;

        synchronized (mWriteBufferLock) {
            final byte[] writeBuffer;

            writeLength = Math.min(src.length - offset, mWriteBuffer.length);
            if (offset == 0) {
                writeBuffer = src;
            } else {
                // bulkTransfer does not support offsets, make a copy.
                System.arraycopy(src, offset, mWriteBuffer, 0, writeLength);
                writeBuffer = mWriteBuffer;
            }

            amtWritten = mConnection.bulkTransfer(endpoint, writeBuffer, writeLength,
                    timeoutMillis);
        }

        if (amtWritten <= 0) {
            throw new IOException("Error writing " + writeLength
                    + " bytes at offset " + offset + " length=" + src.length);
        }

        Log.d(TAG, "Wrote amtWritten=" + amtWritten + " attempted=" + writeLength);
        offset += amtWritten;
    }
    return offset;
}
 
public U2FTransportAndroidHID(UsbDeviceConnection connection, UsbInterface dongleInterface, UsbEndpoint in, UsbEndpoint out, int timeout) {
   this.connection = connection;
   this.dongleInterface = dongleInterface;
   this.in = in;
   this.out = out;
   this.timeout = timeout;
   transferBuffer = new byte[HID_BUFFER_SIZE];
   helper = new U2FHelper();
   random = new Random();
}
 
源代码20 项目: GreenBits   文件: BTChipTransportAndroidHID.java
public BTChipTransportAndroidHID(UsbDeviceConnection connection, UsbInterface dongleInterface, UsbEndpoint in, UsbEndpoint out, int timeout, boolean ledger) {
	this.connection = connection;
	this.dongleInterface = dongleInterface;
	this.in = in;
	this.out = out;
	this.ledger = ledger;
	// Compatibility with old prototypes, to be removed
	if (!this.ledger) {
		this.ledger = (in.getEndpointNumber() != out.getEndpointNumber());
	}
	this.timeout = timeout;
	transferBuffer = new byte[HID_BUFFER_SIZE];
}
 
源代码21 项目: GreenBits   文件: BTChipTransportAndroidWinUSB.java
public BTChipTransportAndroidWinUSB(UsbDeviceConnection connection, UsbInterface dongleInterface, UsbEndpoint in, UsbEndpoint out, int timeout) {
	this.connection = connection;
	this.dongleInterface = dongleInterface;
	this.in = in;
	this.out = out;
	this.timeout = timeout;
	transferBuffer = new byte[260];
}
 
源代码22 项目: GreenBits   文件: BTChipTransportAndroid.java
public static BTChipTransport open(UsbManager manager, UsbDevice device) {
	// Must only be called once permission is granted (see http://developer.android.com/reference/android/hardware/usb/UsbManager.html)
	// Important if enumerating, rather than being awaken by the intent notification
	UsbInterface dongleInterface = device.getInterface(0);
       UsbEndpoint in = null;
       UsbEndpoint out = null;
       boolean ledger; 
       for (int i=0; i<dongleInterface.getEndpointCount(); i++) {
           UsbEndpoint tmpEndpoint = dongleInterface.getEndpoint(i);
           if (tmpEndpoint.getDirection() == UsbConstants.USB_DIR_IN) {
               in = tmpEndpoint;
           }
           else {
               out = tmpEndpoint;
           }
       }
       UsbDeviceConnection connection = manager.openDevice(device);
       if (connection == null) {
           return null;
       }
       connection.claimInterface(dongleInterface, true);
       ledger = ((device.getProductId() == PID_HID_LEDGER) || (device.getProductId() == PID_HID_LEDGER_PROTON)
	|| (device.getProductId() == PID_NANOS) || (device.getProductId() == PID_BLUE));
       if (device.getProductId() == PID_WINUSB) {
       	return new BTChipTransportAndroidWinUSB(connection, dongleInterface, in, out, TIMEOUT);
       }
       else {
       	return new BTChipTransportAndroidHID(connection, dongleInterface, in, out, TIMEOUT, ledger);
       }
}
 
源代码23 项目: xDrip-Experimental   文件: FtdiSerialDriver.java
@Override
public int write(byte[] src, int timeoutMillis) throws IOException {
    final UsbEndpoint endpoint = mDevice.getInterface(0).getEndpoint(1);
    int offset = 0;

    while (offset < src.length) {
        final int writeLength;
        final int amtWritten;

        synchronized (mWriteBufferLock) {
            final byte[] writeBuffer;

            writeLength = Math.min(src.length - offset, mWriteBuffer.length);
            if (offset == 0) {
                writeBuffer = src;
            } else {
                // bulkTransfer does not support offsets, make a copy.
                System.arraycopy(src, offset, mWriteBuffer, 0, writeLength);
                writeBuffer = mWriteBuffer;
            }

            amtWritten = mConnection.bulkTransfer(endpoint, writeBuffer, writeLength,
                    timeoutMillis);
        }

        if (amtWritten <= 0) {
            throw new IOException("Error writing " + writeLength
                    + " bytes at offset " + offset + " length=" + src.length);
        }

        Log.d(TAG, "Wrote amtWritten=" + amtWritten + " attempted=" + writeLength);
        offset += amtWritten;
    }
    return offset;
}
 
源代码24 项目: 365browser   文件: ChromeUsbInterface.java
@CalledByNative
private UsbEndpoint[] getEndpoints() {
    int count = mInterface.getEndpointCount();
    UsbEndpoint[] endpoints = new UsbEndpoint[count];
    for (int i = 0; i < count; ++i) {
        endpoints[i] = mInterface.getEndpoint(i);
    }
    return endpoints;
}
 
源代码25 项目: 365browser   文件: UsbMidiDeviceAndroid.java
/**
 * Constructs a UsbMidiDeviceAndroid.
 * @param manager
 * @param device The USB device which this object is assocated with.
 */
UsbMidiDeviceAndroid(UsbManager manager, UsbDevice device) {
    mConnection = manager.openDevice(device);
    mEndpointMap = new SparseArray<UsbEndpoint>();
    mRequestMap = new HashMap<UsbEndpoint, UsbRequest>();
    mHandler = new Handler();
    mUsbDevice = device;
    mIsClosed = false;
    mHasInputThread = false;
    mNativePointer = 0;

    for (int i = 0; i < device.getInterfaceCount(); ++i) {
        UsbInterface iface = device.getInterface(i);
        if (iface.getInterfaceClass() != UsbConstants.USB_CLASS_AUDIO
                || iface.getInterfaceSubclass() != MIDI_SUBCLASS) {
            continue;
        }
        mConnection.claimInterface(iface, true);
        for (int j = 0; j < iface.getEndpointCount(); ++j) {
            UsbEndpoint endpoint = iface.getEndpoint(j);
            if (endpoint.getDirection() == UsbConstants.USB_DIR_OUT) {
                mEndpointMap.put(endpoint.getEndpointNumber(), endpoint);
            }
        }
    }
    // Start listening for input endpoints.
    // This function will create and run a thread if there is USB-MIDI endpoints in the
    // device. Note that because UsbMidiDevice is shared among all tabs and the thread
    // will be terminated when the device is disconnected, at most one thread can be created
    // for each connected USB-MIDI device.
    startListen(device);
}
 
源代码26 项目: PodEmu   文件: FtdiSerialDriver.java
@Override
public int write(byte[] src, int timeoutMillis) throws IOException {
    final UsbEndpoint endpoint = mDevice.getInterface(0).getEndpoint(1);
    int offset = 0;

    while (offset < src.length) {
        final int writeLength;
        final int amtWritten;

        synchronized (mWriteBufferLock) {
            final byte[] writeBuffer;

            writeLength = Math.min(src.length - offset, mWriteBuffer.length);
            if (offset == 0) {
                writeBuffer = src;
            } else {
                // bulkTransfer does not support offsets, make a copy.
                System.arraycopy(src, offset, mWriteBuffer, 0, writeLength);
                writeBuffer = mWriteBuffer;
            }

            amtWritten = mConnection.bulkTransfer(endpoint, writeBuffer, writeLength,
                    timeoutMillis);
        }

        if (amtWritten <= 0) {
            throw new IOException("Error writing " + writeLength
                    + " bytes at offset " + offset + " duration=" + src.length);
        }

        Log.d(TAG, "Wrote amtWritten=" + amtWritten + " attempted=" + writeLength);
        offset += amtWritten;
    }
    return offset;
}
 
源代码27 项目: android-stm32-dfu-programmer   文件: Usb.java
public String getDeviceInfo(UsbDevice device) {
    if (device == null)
        return "No device found.";

    StringBuilder sb = new StringBuilder();
    sb.append("Model: " + device.getDeviceName() + "\n");
    sb.append("ID: " + device.getDeviceId() + " (0x" + Integer.toHexString(device.getDeviceId()) + ")" + "\n");
    sb.append("Class: " + device.getDeviceClass() + "\n");
    sb.append("Subclass: " + device.getDeviceSubclass() + "\n");
    sb.append("Protocol: " + device.getDeviceProtocol() + "\n");
    sb.append("Vendor ID " + device.getVendorId() + " (0x" + Integer.toHexString(device.getVendorId()) + ")" + "\n");
    sb.append("Product ID: " + device.getProductId() + " (0x" + Integer.toHexString(device.getProductId()) + ")" + "\n");
    sb.append("Device Ver: 0x" + Integer.toHexString(mDeviceVersion) + "\n");
    sb.append("Interface count: " + device.getInterfaceCount() + "\n");

    for (int i = 0; i < device.getInterfaceCount(); i++) {

        UsbInterface usbInterface = device.getInterface(i);

        sb.append("Interface: " + usbInterface.toString() + "\n");
        sb.append("Endpoint Count: " + usbInterface.getEndpointCount() + "\n");

        for (int j = 0; j < usbInterface.getEndpointCount(); j++) {

            UsbEndpoint ep = usbInterface.getEndpoint(j);

            sb.append("Endpoint: " + ep.toString() + "\n");
        }
    }

    return sb.toString();
}
 
@Override
public int write(byte[] src, int timeoutMillis) throws IOException {
    final UsbEndpoint endpoint = mDevice.getInterface(0).getEndpoint(1);
    int offset = 0;

    while (offset < src.length) {
        final int writeLength;
        final int amtWritten;

        synchronized (mWriteBufferLock) {
            final byte[] writeBuffer;

            writeLength = Math.min(src.length - offset, mWriteBuffer.length);
            if (offset == 0) {
                writeBuffer = src;
            } else {
                // bulkTransfer does not support offsets, make a copy.
                System.arraycopy(src, offset, mWriteBuffer, 0, writeLength);
                writeBuffer = mWriteBuffer;
            }

            amtWritten = mConnection.bulkTransfer(endpoint, writeBuffer, writeLength,
                    timeoutMillis);
        }

        if (amtWritten <= 0) {
            throw new IOException("Error writing " + writeLength
                    + " bytes at offset " + offset + " length=" + src.length);
        }

        Log.d(TAG, "Wrote amtWritten=" + amtWritten + " attempted=" + writeLength);
        offset += amtWritten;
    }
    return offset;
}
 
源代码29 项目: WalletCordova   文件: BTChipTransportAndroidHID.java
public BTChipTransportAndroidHID(UsbDeviceConnection connection, UsbInterface dongleInterface, UsbEndpoint in, UsbEndpoint out, int timeout, boolean ledger) {
	this.connection = connection;
	this.dongleInterface = dongleInterface;
	this.in = in;
	this.out = out;
	this.ledger = ledger;
	// Compatibility with old prototypes, to be removed
	if (!this.ledger) {
		this.ledger = (in.getEndpointNumber() != out.getEndpointNumber());
	}
	this.timeout = timeout;
	transferBuffer = new byte[HID_BUFFER_SIZE];
}
 
public BTChipTransportAndroidWinUSB(UsbDeviceConnection connection, UsbInterface dongleInterface, UsbEndpoint in, UsbEndpoint out, int timeout) {
	this.connection = connection;
	this.dongleInterface = dongleInterface;
	this.in = in;
	this.out = out;
	this.timeout = timeout;
	transferBuffer = new byte[260];
}
 
 类所在包
 同包方法