当前位置: 首页>>代码示例>>Java>>正文


Java UsbDeviceConnection.requestWait方法代码示例

本文整理汇总了Java中android.hardware.usb.UsbDeviceConnection.requestWait方法的典型用法代码示例。如果您正苦于以下问题:Java UsbDeviceConnection.requestWait方法的具体用法?Java UsbDeviceConnection.requestWait怎么用?Java UsbDeviceConnection.requestWait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.hardware.usb.UsbDeviceConnection的用法示例。


在下文中一共展示了UsbDeviceConnection.requestWait方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: read

import android.hardware.usb.UsbDeviceConnection; //导入方法依赖的package包/类
public int read(byte[] dest, int timeoutMillis, UsbDeviceConnection connection) throws IOException {
    if (false) {
        final UsbRequest request = new UsbRequest();
        try {
            request.initialize(connection, null);
            final ByteBuffer buf = ByteBuffer.wrap(dest);
            if (!request.queue(buf, dest.length)) {
                throw new IOException("Error queueing request.");
            }

            final UsbRequest response = connection.requestWait();
            if (response == null) {
                throw new IOException("Null response");
            }

            final int nread = buf.position();
            if (nread > 0) {
                //Log.d(TAG, HexDump.dumpHexString(dest, 0, Math.min(32, dest.length)));
                return nread;
            } else {
                return 0;
            }
        } finally {
            request.close();
        }
    }

    final int numBytesRead;
    synchronized (mReadBufferLock) {
        int readAmt = Math.min(dest.length, mReadBuffer.length);
        numBytesRead = connection.bulkTransfer(null, mReadBuffer, readAmt,
                timeoutMillis);
        if (numBytesRead < 0) {
            // This sucks: we get -1 on timeout, not 0 as preferred.
            // We *should* use UsbRequest, except it has a bug/api oversight
            // where there is no way to determine the number of bytes read
            // in response :\ -- http://b.android.com/28023
            if (timeoutMillis == Integer.MAX_VALUE) {
                // Hack: Special case "~infinite timeout" as an error.
                return -1;
            }
            return 0;
        }
        System.arraycopy(mReadBuffer, 0, dest, 0, numBytesRead);
    }
    return numBytesRead;
}
 
开发者ID:LadyViktoria,项目名称:wearDrip,代码行数:48,代码来源:FtdiSerialDriver.java

示例2: read

import android.hardware.usb.UsbDeviceConnection; //导入方法依赖的package包/类
@Override
public int read(byte[] dest, int timeoutMillis, UsbDeviceConnection connection) throws IOException {
    if (false) {
        final UsbRequest request = new UsbRequest();
        try {
            request.initialize(connection, mReadEndpoint);
            final ByteBuffer buf = ByteBuffer.wrap(dest);
            if (!request.queue(buf, dest.length)) {
                throw new IOException("Error queueing request.");
            }

            final UsbRequest response = connection.requestWait();
            if (response == null) {
                throw new IOException("Null response");
            }

            final int nread = buf.position();
            if (nread > 0) {
                //Log.d(TAG, HexDump.dumpHexString(dest, 0, Math.min(32, dest.length)));
                return nread;
            } else {
                return 0;
            }
        } finally {
            request.close();
        }
    }

    final int numBytesRead;
    synchronized (mReadBufferLock) {
        int readAmt = Math.min(dest.length, mReadBuffer.length);
        numBytesRead = connection.bulkTransfer(mReadEndpoint, mReadBuffer, readAmt,
                timeoutMillis);
        if (numBytesRead < 0) {
            // This sucks: we get -1 on timeout, not 0 as preferred.
            // We *should* use UsbRequest, except it has a bug/api oversight
            // where there is no way to determine the number of bytes read
            // in response :\ -- http://b.android.com/28023
            if (timeoutMillis == Integer.MAX_VALUE) {
                // Hack: Special case "~infinite timeout" as an error.
                return -1;
            }
            return 0;
        }
        System.arraycopy(mReadBuffer, 0, dest, 0, numBytesRead);
    }
    return numBytesRead;
}
 
开发者ID:LadyViktoria,项目名称:wearDrip,代码行数:49,代码来源:Cp21xxSerialDriver.java

示例3: read

import android.hardware.usb.UsbDeviceConnection; //导入方法依赖的package包/类
public int read(byte[] dest, int timeoutMillis, UsbDeviceConnection connection) throws IOException {
    if (false) {
        final UsbRequest request = new UsbRequest();
        try {
            request.initialize(connection, mReadEndpoint);
            final ByteBuffer buf = ByteBuffer.wrap(dest);
            if (!request.queue(buf, dest.length)) {
                throw new IOException("Error queueing request.");
            }

            final UsbRequest response = connection.requestWait();
            if (response == null) {
                throw new IOException("Null response");
            }

            final int nread = buf.position();
            if (nread > 0) {
                //Log.d(TAG, HexDump.dumpHexString(dest, 0, Math.min(32, dest.length)));
                return nread;
            } else {
                return 0;
            }
        } finally {
            request.close();
        }
    }

    final int numBytesRead;
    synchronized (mReadBufferLock) {
        int readAmt = Math.min(dest.length, mReadBuffer.length);
        numBytesRead = connection.bulkTransfer(mReadEndpoint, mReadBuffer, readAmt,
                timeoutMillis);
        if (numBytesRead < 0) {
            // This sucks: we get -1 on timeout, not 0 as preferred.
            // We *should* use UsbRequest, except it has a bug/api oversight
            // where there is no way to determine the number of bytes read
            // in response :\ -- http://b.android.com/28023
            if (timeoutMillis == Integer.MAX_VALUE) {
                // Hack: Special case "~infinite timeout" as an error.
                return -1;
            }
            return 0;
        }
        System.arraycopy(mReadBuffer, 0, dest, 0, numBytesRead);
    }
    return numBytesRead;
}
 
开发者ID:LadyViktoria,项目名称:wearDrip,代码行数:48,代码来源:ProlificSerialDriver.java


注:本文中的android.hardware.usb.UsbDeviceConnection.requestWait方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。