本文整理汇总了Java中android.hardware.usb.UsbEndpoint类的典型用法代码示例。如果您正苦于以下问题:Java UsbEndpoint类的具体用法?Java UsbEndpoint怎么用?Java UsbEndpoint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UsbEndpoint类属于android.hardware.usb包,在下文中一共展示了UsbEndpoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: AdbDevice
import android.hardware.usb.UsbEndpoint; //导入依赖的package包/类
public AdbDevice(AdbTestActivity activity, UsbDeviceConnection connection,
UsbInterface intf) {
mActivity = activity;
mDeviceConnection = connection;
mSerial = connection.getSerial();
UsbEndpoint epOut = null;
UsbEndpoint epIn = null;
// look for our bulk endpoints
for (int i = 0; i < intf.getEndpointCount(); i++) {
UsbEndpoint ep = intf.getEndpoint(i);
if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
if (ep.getDirection() == UsbConstants.USB_DIR_OUT) {
epOut = ep;
} else {
epIn = ep;
}
}
}
if (epOut == null || epIn == null) {
throw new IllegalArgumentException("not all endpoints found");
}
mEndpointOut = epOut;
mEndpointIn = epIn;
}
示例2: UsbHidDevice
import android.hardware.usb.UsbEndpoint; //导入依赖的package包/类
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;
}
}
}
示例3: MidiInputDevice
import android.hardware.usb.UsbEndpoint; //导入依赖的package包/类
/**
* constructor
*
* @param usbDevice
* @param usbDeviceConnection
* @param usbInterface
* @param midiEventListener
* @throws IllegalArgumentException endpoint not found.
*/
public MidiInputDevice(UsbDevice usbDevice, UsbDeviceConnection usbDeviceConnection, UsbInterface usbInterface, UsbEndpoint usbEndpoint, OnMidiInputEventListener midiEventListener) throws IllegalArgumentException {
//this.usbDevice = usbDevice;
this.usbDeviceConnection = usbDeviceConnection;
this.usbInterface = usbInterface;
this.midiEventListener = midiEventListener;
waiterThread = new WaiterThread();
inputEndpoint = usbEndpoint;
usbDeviceConnection.claimInterface(usbInterface, true);
waiterThread.setPriority(8);
waiterThread.setName("MidiInputDevice[" + usbDevice.getDeviceName() + "].WaiterThread");
waiterThread.start();
FragMentManager.getInstance().updateUSBConnection(true);
}
示例4: startConnecting
import android.hardware.usb.UsbEndpoint; //导入依赖的package包/类
private void startConnecting() {
handleConnecting();
try {
UsbManager usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
deviceConnection = usbManager.openDevice(device);
driver = UsbSerialDriverFactory.createDriver(device, deviceConnection);
UsbEndpoint[] endpoints = driver.open();
readEndpoint = endpoints[0];
writeEndpoint = endpoints[1];
driver.setParameters(115200, 8, UsbSerialDriver.STOPBITS_1, UsbSerialDriver.PARITY_NONE);
} catch (Exception e) {
Log.e(LOG_TAG, "Failed to connect to USB device(" + device.getDeviceName() + "). cause=" + e.getMessage());
cleanUp();
handleFailedToConnect(e);
return;
}
// Start a thread for reading
readThread = new UsbReadThread();
readThread.start();
Log.i(LOG_TAG, "USB device is connected! connection=" + getDescription());
handleConnected();
}
示例5: open
import android.hardware.usb.UsbEndpoint; //导入依赖的package包/类
@Override
public boolean open() {
iface = device.getInterface(0);
Log.d(TAG, "Endpoint Count: " + iface.getEndpointCount());
UsbEndpoint ep0 = iface.getEndpoint(0);
UsbEndpoint ep1 = iface.getEndpoint(1);
if (ep0.getDirection() == UsbConstants.USB_DIR_IN) {
in = ep0;
out = ep1;
} else {
in = ep1;
out = ep0;
}
con = manager.openDevice(device);
return con != null;
}
示例6: testStartReadThread
import android.hardware.usb.UsbEndpoint; //导入依赖的package包/类
/**
* Test method for {@link com.digi.xbee.api.connection.android.AndroidUSBInputStream#startReadThread()}
*/
@Test
public void testStartReadThread() throws Exception {
// Prepare the resources for the test.
Whitebox.setInternalState(is, VARIABLE_READ_BUFFER, circularBuffer);
// Call the method under test.
is.startReadThread();
Thread.sleep(10);
boolean working = (Boolean) Whitebox.getInternalState(is, VARIABLE_WORKING);
// Perform the verifications.
assertThat(working, is(equalTo(true)));
Mockito.verify(usbConnection, Mockito.atLeast(1)).bulkTransfer(Mockito.any(UsbEndpoint.class),
Mockito.any(byte[].class), Mockito.anyInt(), Mockito.anyInt());
is.stopReadThread();
}
示例7: createUsbCommunication
import android.hardware.usb.UsbEndpoint; //导入依赖的package包/类
public static UsbCommunication createUsbCommunication(UsbDeviceConnection deviceConnection,
UsbEndpoint outEndpoint, UsbEndpoint inEndpoint) {
UsbCommunication communication;
if (underlyingUsbCommunication == UnderlyingUsbCommunication.DEVICE_CONNECTION_SYNC) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
communication = new JellyBeanMr2Communication(deviceConnection, outEndpoint, inEndpoint);
} else {
Log.i(TAG, "using workaround usb communication");
communication = new HoneyCombMr1Communication(deviceConnection, outEndpoint, inEndpoint);
}
} else {
communication = new UsbRequestCommunication(deviceConnection, outEndpoint, inEndpoint);
}
return communication;
}
示例8: write
import android.hardware.usb.UsbEndpoint; //导入依赖的package包/类
public int write(final byte[] data, final int timeout) throws IOException {
//TODO: score the real interface and endpoint
final UsbEndpoint endpoint = mDevice.getInterface(0).getEndpoint(1);
int offset = 0;
while (offset < data.length) {
final int write_length;
final int result;
synchronized (mWriteBufferLock) {
final byte[] writeBuffer;
write_length = Math.min(data.length-offset, mWriteBuffer.length);
if (offset == 0) {
writeBuffer = data;
} else {
System.arraycopy(data, offset, mWriteBuffer, 0, write_length);
writeBuffer = mWriteBuffer;
}
result = mConnection.bulkTransfer(endpoint, writeBuffer, write_length, timeout);
}
if (result <=0) {
throw new IOException("Error writing " + write_length + " bytes at offset " + offset + " length="+data.length);
}
Log.d(TAG, "Wrote " + result + " bytes. Attempted=" + write_length);
offset += result;
}
return offset;
}
示例9: ConnectedUsbDevice
import android.hardware.usb.UsbEndpoint; //导入依赖的package包/类
public ConnectedUsbDevice(UsbDeviceConnection connection, UsbInterface usbInterface) {
this.connection = connection;
this.usbInterface = usbInterface;
initConnection(connection);
int endPoints = usbInterface.getEndpointCount();
int interfaceProtocol = usbInterface.getInterfaceProtocol();
System.out.println("EndPoints: " + endPoints + " | interfaces: " + interfaceProtocol);
out = usbInterface.getEndpoint(1);
in = usbInterface.getEndpoint(2);
for (int x = 0; x < endPoints; x++) {
UsbEndpoint endpoint = usbInterface.getEndpoint(x);
boolean bulk = endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK;
boolean crtl = endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_CONTROL;
boolean inDir = endpoint.getDirection() == UsbConstants.USB_DIR_IN;
boolean outDir = endpoint.getDirection() == UsbConstants.USB_DIR_OUT;
System.out.println("ID: " + x + " Bulk: " + bulk + " Ctrl: " + crtl + " Out: " + outDir + " In: " + inDir);
}
}
示例10: getCdcEndpoint
import android.hardware.usb.UsbEndpoint; //导入依赖的package包/类
private boolean getCdcEndpoint() {
UsbEndpoint ep;
if (mInterface[0] == null) {
return false;
}
for (int i = 0; i < 2; ++i) {
ep = mInterface[0].getEndpoint(i);
if (ep.getDirection() == UsbConstants.USB_DIR_IN) {
mFTDIEndpointIN[0] = ep;
} else {
mFTDIEndpointOUT[0] = ep;
}
}
if (mFTDIEndpointIN == null || mFTDIEndpointOUT == null) {
return false;
}
return true;
}
示例11: setFTDIEndpoints
import android.hardware.usb.UsbEndpoint; //导入依赖的package包/类
private boolean setFTDIEndpoints(UsbInterface[] intf, int portNum) {
UsbEndpoint epIn;
UsbEndpoint epOut;
if (intf[0] == null) {
return false;
}
for (int i = 0; i < portNum; ++i) {
epIn = intf[i].getEndpoint(0);
epOut = intf[i].getEndpoint(1);
if (epIn != null && epOut != null) {
mFTDIEndpointIN[i] = epIn;
mFTDIEndpointOUT[i] = epOut;
} else {
return false;
}
}
return true;
}
示例12: UsbMidiDeviceAndroid
import android.hardware.usb.UsbEndpoint; //导入依赖的package包/类
/**
* 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 HashMap<Integer, UsbEndpoint>();
mRequestMap = new HashMap<UsbEndpoint, UsbRequest>();
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);
}
}
}
}
示例13: write
import android.hardware.usb.UsbEndpoint; //导入依赖的package包/类
@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: UsbHiSpeedBulk
import android.hardware.usb.UsbEndpoint; //导入依赖的package包/类
public UsbHiSpeedBulk(UsbDeviceConnection usbDeviceConnection, UsbEndpoint usbEndpoint, int nrequests, int packetsPerRequests) {
this.usbDeviceConnection = usbDeviceConnection;
this.fileDescriptor = usbDeviceConnection.getFileDescriptor();
this.nrequests = nrequests;
this.requests = new ArrayList<>(nrequests);
this.packetSize = usbEndpoint.getMaxPacketSize();
this.usbEndpoint = usbEndpoint;
this.packetsPerRequests = packetsPerRequests;
this.buffer = new Buffer(packetsPerRequests * packetSize);
}
示例15: UsbBulkSource
import android.hardware.usb.UsbEndpoint; //导入依赖的package包/类
public UsbBulkSource(UsbDeviceConnection usbDeviceConnection, UsbEndpoint usbEndpoint, AlternateUsbInterface usbInterface, int numRequests, int numPacketsPerReq) {
this.usbDeviceConnection = usbDeviceConnection;
this.usbEndpoint = usbEndpoint;
this.usbInterface = usbInterface;
this.numRequests = numRequests;
this.numPacketsPerReq = numPacketsPerReq;
}