本文整理汇总了Java中android.hardware.usb.UsbConstants.USB_DIR_IN属性的典型用法代码示例。如果您正苦于以下问题:Java UsbConstants.USB_DIR_IN属性的具体用法?Java UsbConstants.USB_DIR_IN怎么用?Java UsbConstants.USB_DIR_IN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.hardware.usb.UsbConstants
的用法示例。
在下文中一共展示了UsbConstants.USB_DIR_IN属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getStringDescriptor
/**
* Returns the string descriptor bytes for the given index
* @param index index of the descriptor
* @return the string descriptor bytes for the given index.
*/
@CalledByNative
byte[] getStringDescriptor(int index) {
if (mConnection == null) {
return new byte[0];
}
byte[] buffer = new byte[255];
int type = UsbConstants.USB_DIR_IN | UsbConstants.USB_TYPE_STANDARD;
int request = REQUEST_GET_DESCRIPTOR;
int value = (STRING_DESCRIPTOR_TYPE << 8) | index;
int read = mConnection.controlTransfer(type, request, value, 0, buffer, buffer.length, 0);
if (read < 0) {
return new byte[0];
}
return Arrays.copyOf(buffer, read);
}
示例2: bulkTransfer
private void bulkTransfer(CordovaArgs args, JSONObject params,
final CallbackContext callbackContext) throws JSONException, UsbError {
ConnectedDevice dev = getDevice(params);
int endpointAddress = params.getInt("endpoint");
int interfaceNumber = endpointAddress >> ENDPOINT_IF_SHIFT;
int endpointNumber = endpointAddress & ((1 << ENDPOINT_IF_SHIFT) - 1);
if (interfaceNumber >= dev.getInterfaceCount() ||
endpointNumber >= dev.getEndpointCount(interfaceNumber)) {
throw new UsbError("Enpoint not found: " + endpointAddress);
}
int direction = directionFromName(params.getString("direction"));
byte[] buffer = getByteBufferForTransfer(args, params, direction);
int ret = dev.bulkTransfer(interfaceNumber, endpointNumber, direction, buffer,
params.getInt("timeout"));
if (ret < 0) {
throw new UsbError("Bulk transfer returned " + ret);
}
if (direction == UsbConstants.USB_DIR_IN) {
callbackContext.success(Arrays.copyOf(buffer, ret));
} else {
callbackContext.success();
}
}
示例3: open
@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;
}
示例4: ConnectedUsbDevice
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);
}
}
示例5: getCdcEndpoint
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;
}
示例6: openCH34X
private boolean openCH34X()
{
if(connection.claimInterface(mInterface, true))
{
Log.i(CLASS_ID, "Interface succesfully claimed");
}else
{
Log.i(CLASS_ID, "Interface could not be claimed");
return false;
}
// Assign endpoints
int numberEndpoints = mInterface.getEndpointCount();
for(int i=0;i<=numberEndpoints-1;i++)
{
UsbEndpoint endpoint = mInterface.getEndpoint(i);
if(endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK
&& endpoint.getDirection() == UsbConstants.USB_DIR_IN)
{
inEndpoint = endpoint;
}else if(endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK
&& endpoint.getDirection() == UsbConstants.USB_DIR_OUT)
{
outEndpoint = endpoint;
}
}
return init() == 0;
}
示例7: run
@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())
{
((FTDISerialDevice) usbSerialDevice).ftdiUtilities.checkModemStatus(data); //Check the Modem status
serialBuffer.clearReadBuffer();
if(data.length > 2)
{
data = ((FTDISerialDevice) usbSerialDevice).ftdiUtilities.adaptArray(data);
onReceivedData(data);
}
}else
{
// Clear buffer, execute the callback
serialBuffer.clearReadBuffer();
onReceivedData(data);
}
// Queue a new request
requestIN.queue(serialBuffer.getReadBuffer(), serialBuffer.getReadBufferSize());
}
}
}
示例8: openCP2102
private boolean openCP2102()
{
if(connection.claimInterface(mInterface, true))
{
Log.i(CLASS_ID, "Interface succesfully claimed");
}else
{
Log.i(CLASS_ID, "Interface could not be claimed");
return false;
}
// Assign endpoints
int numberEndpoints = mInterface.getEndpointCount();
for(int i=0;i<=numberEndpoints-1;i++)
{
UsbEndpoint endpoint = mInterface.getEndpoint(i);
if(endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK
&& endpoint.getDirection() == UsbConstants.USB_DIR_IN)
{
inEndpoint = endpoint;
}else
{
outEndpoint = endpoint;
}
}
// Default Setup
if(setControlCommand(CP210x_IFC_ENABLE, CP210x_UART_ENABLE, null) < 0)
return false;
setBaudRate(DEFAULT_BAUDRATE);
if(setControlCommand(CP210x_SET_LINE_CTL, CP210x_LINE_CTL_DEFAULT,null) < 0)
return false;
setFlowControl(UsbSerialInterface.FLOW_CONTROL_OFF);
if(setControlCommand(CP210x_SET_MHS, CP210x_MHS_DEFAULT, null) < 0)
return false;
return true;
}
示例9: openCDC
private boolean openCDC()
{
if(connection.claimInterface(mInterface, true))
{
Log.i(CLASS_ID, "Interface succesfully claimed");
}else
{
Log.i(CLASS_ID, "Interface could not be claimed");
return false;
}
// Assign endpoints
int numberEndpoints = mInterface.getEndpointCount();
for(int i=0;i<=numberEndpoints-1;i++)
{
UsbEndpoint endpoint = mInterface.getEndpoint(i);
if(endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK
&& endpoint.getDirection() == UsbConstants.USB_DIR_IN)
{
inEndpoint = endpoint;
}else if(endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK
&& endpoint.getDirection() == UsbConstants.USB_DIR_OUT)
{
outEndpoint = endpoint;
}
}
if(outEndpoint == null || inEndpoint == null)
{
Log.i(CLASS_ID, "Interface does not have an IN or OUT interface");
return false;
}
// Default Setup
setControlCommand(CDC_SET_LINE_CODING, 0, getInitialLineCoding());
setControlCommand(CDC_SET_CONTROL_LINE_STATE, CDC_CONTROL_LINE_ON, null);
return true;
}
示例10: SmartCardChannel
/** Constructor. Inicia los EndPoints del Interfaz del dispositivo
* @param usbDevCon
* @param usbInterface */
protected SmartCardChannel(final UsbDeviceConnection usbDevCon, final UsbInterface usbInterface) {
this.usbDeviceConnection = usbDevCon;
for (int i = 0; i < usbInterface.getEndpointCount(); i++) {
final UsbEndpoint usbEndPoint = usbInterface.getEndpoint(i);
if (usbEndPoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
if (usbEndPoint.getDirection() == UsbConstants.USB_DIR_IN) {
this.endPointIn = usbEndPoint;
}
else if (usbEndPoint.getDirection() == UsbConstants.USB_DIR_OUT) {
this.endPointOut = usbEndPoint;
}
}
}
}
示例11: run
@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())
{
((FTDISerialDevice) usbSerialDevice).ftdiUtilities.checkModemStatus(data); //Check the Modem status
serialBuffer.clearReadBuffer();
if(data.length > 2)
{
data = ((FTDISerialDevice) usbSerialDevice).ftdiUtilities.adaptArray(data);
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);
}
}
}
示例12: open
@Override
public void open() throws IOException {
boolean opened = false;
try {
for (int i = 0; i < mDevice.getInterfaceCount(); i++) {
UsbInterface usbIface = mDevice.getInterface(i);
if (mConnection.claimInterface(usbIface, true)) {
Log.d(TAG, "claimInterface " + i + " SUCCESS");
} else {
Log.d(TAG, "claimInterface " + i + " FAIL");
}
}
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;
}
}
}
setConfigSingle(SILABSER_IFC_ENABLE_REQUEST_CODE, UART_ENABLE);
setConfigSingle(SILABSER_SET_MHS_REQUEST_CODE, MCR_ALL | CONTROL_WRITE_DTR | CONTROL_WRITE_RTS);
setConfigSingle(SILABSER_SET_BAUDDIV_REQUEST_CODE, BAUD_RATE_GEN_FREQ / DEFAULT_BAUD_RATE);
// setParameters(DEFAULT_BAUD_RATE, DEFAULT_DATA_BITS, DEFAULT_STOP_BITS, DEFAULT_PARITY);
opened = true;
} finally {
if (!opened) {
close();
}
}
}
示例13: openCDC
private boolean openCDC()
{
if(connection.claimInterface(mInterface, true))
{
Log.i(CLASS_ID, "Interface succesfully claimed");
}else
{
Log.i(CLASS_ID, "Interface could not be claimed");
return false;
}
// Assign endpoints
int numberEndpoints = mInterface.getEndpointCount();
for(int i=0;i<=numberEndpoints-1;i++)
{
UsbEndpoint endpoint = mInterface.getEndpoint(i);
if(endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK
&& endpoint.getDirection() == UsbConstants.USB_DIR_IN)
{
inEndpoint = endpoint;
}else if(endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK
&& endpoint.getDirection() == UsbConstants.USB_DIR_OUT)
{
outEndpoint = endpoint;
}
}
if(outEndpoint == null || inEndpoint == null)
{
Log.i(CLASS_ID, "Interface does not have an IN or OUT interface");
return false;
}
// Default Setup
setControlCommand(CDC_SET_LINE_CODING, 0, CDC_DEFAULT_LINE_CODING);
setControlCommand(CDC_SET_CONTROL_LINE_STATE, CDC_CONTROL_LINE_ON, null);
return true;
}
示例14: openCP2130
private boolean openCP2130()
{
if(connection.claimInterface(mInterface, true))
{
Log.i(CLASS_ID, "Interface succesfully claimed");
}else
{
Log.i(CLASS_ID, "Interface could not be claimed");
return false;
}
// Assign endpoints
int numberEndpoints = mInterface.getEndpointCount();
for(int i=0;i<=numberEndpoints-1;i++)
{
UsbEndpoint endpoint = mInterface.getEndpoint(i);
if(endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK
&& endpoint.getDirection() == UsbConstants.USB_DIR_IN)
{
inEndpoint = endpoint;
}else
{
outEndpoint = endpoint;
}
}
return true;
}
示例15: open
/**
* 打开PL2303HXA设备
*
* @throws PL2303Exception
* 打开失败异常,如果未授权或不支持的设置参数
*/
public void open() throws PL2303Exception {
usbDeviceConnection = usbManager.openDevice(usbDevice);
if (usbDeviceConnection != null) {
Log.i(TAG, "openDevice()=>ok!");
Log.i(TAG, "getInterfaceCount()=>" + usbDevice.getInterfaceCount());
usbInterface = usbDevice.getInterface(0);
for (int i = 0; i < usbInterface.getEndpointCount(); ++i) {
UsbEndpoint ue = usbInterface.getEndpoint(i);
if (ue.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK && ue.getDirection() == UsbConstants.USB_DIR_IN) {
uein = ue;
} else if (ue.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK && ue.getDirection() == UsbConstants.USB_DIR_OUT) {
ueout = ue;
}
}
if (uein != null && ueout != null) {
Log.i(TAG, "get Endpoint ok!");
usbDeviceConnection.claimInterface(usbInterface, true);
byte[] buffer = new byte[1];
controlTransfer(192, 1, 33924, 0, buffer, 1, transferTimeOut);
controlTransfer(64, 1, 1028, 0, null, 0, transferTimeOut);
controlTransfer(192, 1, 33924, 0, buffer, 1, transferTimeOut);
controlTransfer(192, 1, 33667, 0, buffer, 1, transferTimeOut);
controlTransfer(192, 1, 33924, 0, buffer, 1, transferTimeOut);
controlTransfer(64, 1, 1028, 1, null, 0, transferTimeOut);
controlTransfer(192, 1, 33924, 0, buffer, 1, transferTimeOut);
controlTransfer(192, 1, 33667, 0, buffer, 1, transferTimeOut);
controlTransfer(64, 1, 0, 1, null, 0, transferTimeOut);
controlTransfer(64, 1, 1, 0, null, 0, transferTimeOut);
controlTransfer(64, 1, 2, 68, null, 0, transferTimeOut);
reset();
opened = true;
}
} else {
Log.e(TAG, "openDevice()=>fail!");
throw new PL2303Exception("usbManager.openDevice failed!");
}
}