本文整理汇总了Java中javax.usb.UsbEndpoint类的典型用法代码示例。如果您正苦于以下问题:Java UsbEndpoint类的具体用法?Java UsbEndpoint怎么用?Java UsbEndpoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UsbEndpoint类属于javax.usb包,在下文中一共展示了UsbEndpoint类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: initialize
import javax.usb.UsbEndpoint; //导入依赖的package包/类
protected void initialize() throws SecurityException, UsbException {
UsbServices services = UsbHostManager.getUsbServices();
UsbHub usbHub = services.getRootUsbHub();
UsbDevice theDevice = findDevice(usbHub, targetVendor, targetProduct);
if (theDevice == null) {
logger.warn("Could not find the device. The driver is not operable.");
return;
}
for (Object i : theDevice.getActiveUsbConfiguration().getUsbInterfaces()) {
UsbInterface intf = (UsbInterface) i;
for (Object e : intf.getUsbEndpoints()) {
UsbEndpoint endp = (UsbEndpoint) e;
if (endp.getDirection() == UsbConst.ENDPOINT_DIRECTION_IN) {
this.pipe = endp.getUsbPipe();
}
}
}
}
开发者ID:yadarts,项目名称:yadarts,代码行数:22,代码来源:SimplifiedEmprexUSBDriver.java
示例2: sendMessage
import javax.usb.UsbEndpoint; //导入依赖的package包/类
/**
* Sends an ADB Message.
*
* @param message
* The message to send.
* @throws UsbException
* When USB communication failed.
*/
public void sendMessage(Message message) throws UsbException
{
UsbEndpoint outEndpoint =
this.iface.getUsbEndpoint(this.outEndpoint);
UsbPipe outPipe = outEndpoint.getUsbPipe();
MessageHeader header = message.getHeader();
outPipe.open();
try
{
int sent = outPipe.syncSubmit(header.getBytes());
if (sent != MessageHeader.SIZE)
throw new InvalidMessageException(
"Invalid ADB message header size sent: " + sent);
sent = outPipe.syncSubmit(message.getData());
if (sent != header.getDataLength())
throw new InvalidMessageException(
"Data size mismatch in sent ADB message. Should be "
+ header.getDataLength() + " but is " + sent);
}
finally
{
outPipe.close();
}
}
开发者ID:usb4java,项目名称:usb4java-javax-examples,代码行数:33,代码来源:AdbDevice.java
示例3: getDeviceDetails
import javax.usb.UsbEndpoint; //导入依赖的package包/类
public static String getDeviceDetails( UsbDevice device )
throws UsbException, UnsupportedEncodingException, UsbDisconnectedException
{
StringBuilder sb = new StringBuilder();
sb.append( device.getUsbDeviceDescriptor().toString() + "\n\n" );
for( Object configObject: device.getUsbConfigurations() )
{
UsbConfiguration config = (UsbConfiguration)configObject;
sb.append( config.getUsbConfigurationDescriptor().toString() + "\n\n" );
for( Object interfaceObject: config.getUsbInterfaces() )
{
UsbInterface iface = (UsbInterface)interfaceObject;
sb.append( iface.getUsbInterfaceDescriptor().toString() + "\n\n" );
for( Object endpointObject: iface.getUsbEndpoints() )
{
UsbEndpoint endpoint = (UsbEndpoint)endpointObject;
sb.append( endpoint.getUsbEndpointDescriptor().toString() + "\n\n" );
}
}
}
return sb.toString();
}
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:31,代码来源:USBUtils.java
示例4: sendBulkTransfer
import javax.usb.UsbEndpoint; //导入依赖的package包/类
private int sendBulkTransfer(UsbEndpoint usbEndpoint, byte[] data) throws UsbException{
int returnCode = -1;
if(UsbConst.ENDPOINT_DIRECTION_OUT == usbEndpoint.getDirection()){
mLogger.debug("sendBulkTransfer - direction: OUT, byteString: {}", getByteString(data));
}
UsbPipe usbPipe = usbEndpoint.getUsbPipe();
if (usbPipe != null) {
if(!usbPipe.isOpen()){
usbPipe.open();
}
if (usbPipe.isOpen()) {
UsbIrp usbIrp = usbPipe.createUsbIrp();
usbIrp.setData(data);
//TODO: data length does not need to be set explicitly
// int dataLength = (data == null) ? 0 : data.length;
// usbIrp.setLength(dataLength);
usbPipe.syncSubmit(usbIrp);
if (!usbIrp.isUsbException()) {
returnCode = usbIrp.getActualLength();
} else {
// throw usbControlIrp.getUsbException();
usbIrp.getUsbException().printStackTrace();
}
} else {
mLogger.error("usbPipe open ERROR");
}
} else {
mLogger.error("usbPipe is NULL");
}
if(UsbConst.ENDPOINT_DIRECTION_IN == usbEndpoint.getDirection()){
//TODO: show type of packet in debug log
mLogger.debug("sendBulkTransfer - direction: IN, byteString: {}", getByteString(data));
}
return returnCode;
}
开发者ID:fredg02,项目名称:se.bitcraze.crazyflie.lib,代码行数:40,代码来源:UsbLinkJava.java
示例5: open
import javax.usb.UsbEndpoint; //导入依赖的package包/类
private void open() throws UsbException {
UsbConfiguration configuration = device.getActiveUsbConfiguration();
iface = configuration.getUsbInterface((byte) 0);
// this allows us to steal the lock from the kernel
iface.claim(usbInterface -> true);
final List<UsbEndpoint> endpoints = iface.getUsbEndpoints();
pipe = endpoints.get(0).getUsbPipe(); // there is only 1 endpoint
pipe.addUsbPipeListener(this);
pipe.open();
}
开发者ID:RaspberryPiWithJava,项目名称:JavaScale,代码行数:11,代码来源:UsbScaleTest.java
示例6: processIrp
import javax.usb.UsbEndpoint; //导入依赖的package包/类
@Override
protected void processIrp(final UsbIrp irp) throws UsbException
{
final UsbEndpoint endpoint = this.pipe.getUsbEndpoint();
final byte direction = endpoint.getDirection();
final byte type = endpoint.getType();
if (type == UsbConst.ENDPOINT_TYPE_CONTROL)
{
processControlIrp((UsbControlIrp) irp);
return;
}
switch (direction)
{
case UsbConst.ENDPOINT_DIRECTION_OUT:
irp.setActualLength(write(irp.getData(), irp.getOffset(),
irp.getLength()));
if (irp.getActualLength() < irp.getLength()
&& !irp.getAcceptShortPacket())
{
throw new UsbShortPacketException();
}
break;
case UsbConst.ENDPOINT_DIRECTION_IN:
irp.setActualLength(read(irp.getData(), irp.getOffset(),
irp.getLength()));
if (irp.getActualLength() < irp.getLength()
&& !irp.getAcceptShortPacket())
{
throw new UsbShortPacketException();
}
break;
default:
throw new UsbException("Invalid direction: "
+ direction);
}
}
开发者ID:usb4java,项目名称:usb4java-javax,代码行数:40,代码来源:IrpQueue.java
示例7: testGetUsbEndpoints
import javax.usb.UsbEndpoint; //导入依赖的package包/类
/**
* Tests the {@link RootHubInterface#getUsbEndpoints()} method.
*/
@Test
public void testGetUsbEndpoints()
{
final List<UsbEndpoint> endpoints = this.iface.getUsbEndpoints();
assertEquals(0, endpoints.size());
}
开发者ID:usb4java,项目名称:usb4java-javax,代码行数:10,代码来源:RootHubInterfaceTest.java
示例8: receiveMessage
import javax.usb.UsbEndpoint; //导入依赖的package包/类
/**
* Receives an ADB message.
*
* @return The received ADB message.
* @throws UsbException
* When USB communication failed.
*/
public Message receiveMessage() throws UsbException
{
UsbEndpoint inEndpoint =
this.iface.getUsbEndpoint(this.inEndpoint);
UsbPipe inPipe = inEndpoint.getUsbPipe();
inPipe.open();
try
{
byte[] headerBytes = new byte[MessageHeader.SIZE];
int received = inPipe.syncSubmit(headerBytes);
if (received != MessageHeader.SIZE)
throw new InvalidMessageException(
"Invalid ADB message header size: " + received);
MessageHeader header = new MessageHeader(headerBytes);
if (!header.isValid())
throw new InvalidMessageException(
"ADB message header checksum failure");
byte[] data = new byte[header.getDataLength()];
received = inPipe.syncSubmit(data);
if (received != header.getDataLength())
throw new InvalidMessageException(
"ADB message data size mismatch. Should be "
+ header.getDataLength() + " but is " + received);
Message message = Message.create(header, data);
if (!message.isValid())
throw new InvalidMessageException(
"ADB message data checksum failure");
return message;
}
finally
{
inPipe.close();
}
}
开发者ID:usb4java,项目名称:usb4java-javax-examples,代码行数:42,代码来源:AdbDevice.java
示例9: findInterruptInEndpoint
import javax.usb.UsbEndpoint; //导入依赖的package包/类
protected UsbEndpoint findInterruptInEndpoint(List<?> usbEndpoints) {
for (int i = 0; i < usbEndpoints.size(); i++) {
UsbEndpoint usbEndpoint = (UsbEndpoint) usbEndpoints.get(i);
if (UsbConst.ENDPOINT_TYPE_INTERRUPT == usbEndpoint.getType()
&& UsbConst.ENDPOINT_DIRECTION_IN == usbEndpoint
.getDirection()) {
return usbEndpoint;
}
}
return null;
}
开发者ID:yadarts,项目名称:yadarts,代码行数:14,代码来源:SimplifiedEmprexUSBDriver.java
示例10: getUsbEndpoints
import javax.usb.UsbEndpoint; //导入依赖的package包/类
@Override
public List<UsbEndpoint> getUsbEndpoints()
{
return this.endpoints;
}
开发者ID:usb4java,项目名称:usb4java-javax,代码行数:6,代码来源:RootHubInterface.java
示例11: getUsbEndpoint
import javax.usb.UsbEndpoint; //导入依赖的package包/类
@Override
public UsbEndpoint getUsbEndpoint(final byte address)
{
return null;
}
开发者ID:usb4java,项目名称:usb4java-javax,代码行数:6,代码来源:RootHubInterface.java
示例12: checkDevice
import javax.usb.UsbEndpoint; //导入依赖的package包/类
/**
* Checks if the specified USB device is a ADB device and adds it to the
* list if it is.
*
* @param usbDevice
* The USB device to check.
* @param adbDevices
* The list of ADB devices to add the USB device to when it is an
* ADB device.
*/
private static void checkDevice(UsbDevice usbDevice,
List<AdbDevice> adbDevices)
{
UsbDeviceDescriptor deviceDesc = usbDevice.getUsbDeviceDescriptor();
// Ignore devices from Non-ADB vendors
if (!isAdbVendor(deviceDesc.idVendor())) return;
// Check interfaces of device
UsbConfiguration config = usbDevice.getActiveUsbConfiguration();
for (UsbInterface iface: (List<UsbInterface>) config.getUsbInterfaces())
{
List<UsbEndpoint> endpoints = iface.getUsbEndpoints();
// Ignore interface if it does not have two endpoints
if (endpoints.size() != 2) continue;
// Ignore interface if it does not match the ADB specs
if (!isAdbInterface(iface)) continue;
UsbEndpointDescriptor ed1 =
endpoints.get(0).getUsbEndpointDescriptor();
UsbEndpointDescriptor ed2 =
endpoints.get(1).getUsbEndpointDescriptor();
// Ignore interface if endpoints are not bulk endpoints
if (((ed1.bmAttributes() & UsbConst.ENDPOINT_TYPE_BULK) == 0) ||
((ed2.bmAttributes() & UsbConst.ENDPOINT_TYPE_BULK) == 0))
continue;
// Determine which endpoint is in and which is out. If both
// endpoints are in or out then ignore the interface
byte a1 = ed1.bEndpointAddress();
byte a2 = ed2.bEndpointAddress();
byte in, out;
if (((a1 & UsbConst.ENDPOINT_DIRECTION_IN) != 0) &&
((a2 & UsbConst.ENDPOINT_DIRECTION_IN) == 0))
{
in = a1;
out = a2;
}
else if (((a2 & UsbConst.ENDPOINT_DIRECTION_IN) != 0) &&
((a1 & UsbConst.ENDPOINT_DIRECTION_IN) == 0))
{
out = a1;
in = a2;
}
else continue;
// Create ADB device and add it to the list
AdbDevice adbDevice = new AdbDevice(iface, in, out);
adbDevices.add(adbDevice);
}
}
开发者ID:usb4java,项目名称:usb4java-javax-examples,代码行数:65,代码来源:Adb.java
示例13: dumpDevice
import javax.usb.UsbEndpoint; //导入依赖的package包/类
/**
* Dumps the specified USB device to stdout.
*
* @param device
* The USB device to dump.
*/
private static void dumpDevice(final UsbDevice device)
{
// Dump information about the device itself
System.out.println(device);
final UsbPort port = device.getParentUsbPort();
if (port != null)
{
System.out.println("Connected to port: " + port.getPortNumber());
System.out.println("Parent: " + port.getUsbHub());
}
// Dump device descriptor
System.out.println(device.getUsbDeviceDescriptor());
// Process all configurations
for (UsbConfiguration configuration: (List<UsbConfiguration>) device
.getUsbConfigurations())
{
// Dump configuration descriptor
System.out.println(configuration.getUsbConfigurationDescriptor());
// Process all interfaces
for (UsbInterface iface: (List<UsbInterface>) configuration
.getUsbInterfaces())
{
// Dump the interface descriptor
System.out.println(iface.getUsbInterfaceDescriptor());
// Process all endpoints
for (UsbEndpoint endpoint: (List<UsbEndpoint>) iface
.getUsbEndpoints())
{
// Dump the endpoint descriptor
System.out.println(endpoint.getUsbEndpointDescriptor());
}
}
}
System.out.println();
// Dump child devices if device is a hub
if (device.isUsbHub())
{
final UsbHub hub = (UsbHub) device;
for (UsbDevice child: (List<UsbDevice>) hub.getAttachedUsbDevices())
{
dumpDevice(child);
}
}
}
开发者ID:usb4java,项目名称:usb4java-javax-examples,代码行数:57,代码来源:DumpDevices.java
注:本文中的javax.usb.UsbEndpoint类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论