• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java UsbConst类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中javax.usb.UsbConst的典型用法代码示例。如果您正苦于以下问题:Java UsbConst类的具体用法?Java UsbConst怎么用?Java UsbConst使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: initialize

import javax.usb.UsbConst; //导入依赖的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: transfer

import javax.usb.UsbConst; //导入依赖的package包/类
/**
 * Transfers data from or to the device.
 * 
 * @param handle
 *            The device handle.
 * @param descriptor
 *            The endpoint descriptor.
 * @param type
 *            The endpoint type.
 * @param buffer
 *            The data buffer.
 * @return The number of transferred bytes.
 * @throws UsbException
 *             When data transfer fails.
 */
private int transfer(final DeviceHandle handle,
    final UsbEndpointDescriptor descriptor, final int type,
    final ByteBuffer buffer) throws UsbException
{
    final byte address = descriptor.bEndpointAddress();
    final boolean in = this.pipe.getUsbEndpoint().getDirection() ==
        UsbConst.ENDPOINT_DIRECTION_IN;
    if (type == UsbConst.ENDPOINT_TYPE_BULK)
    {
        return transferBulk(handle, address, in, buffer);
    }
    else if (type == UsbConst.ENDPOINT_TYPE_INTERRUPT)
    {
        return transferInterrupt(handle, address, in, buffer);
    }
    else
    {
        throw new UsbException("Unsupported endpoint type: " + type);
    }
}
 
开发者ID:usb4java,项目名称:usb4java-javax,代码行数:36,代码来源:IrpQueue.java


示例3: testGetUsbInterfaceDescriptor

import javax.usb.UsbConst; //导入依赖的package包/类
/**
 * Tests the {@link RootHubInterface#getUsbInterfaceDescriptor()} method.
 */
@Test
public void testGetUsbInterfaceDescriptor()
{
    final UsbInterfaceDescriptor desc =
        this.iface.getUsbInterfaceDescriptor();
    assertEquals(UsbConst.DESCRIPTOR_MIN_LENGTH_INTERFACE, desc.bLength());
    assertEquals(UsbConst.DESCRIPTOR_TYPE_INTERFACE,
        desc.bDescriptorType());
    assertEquals(0, desc.bInterfaceNumber());
    assertEquals(0, desc.bAlternateSetting());
    assertEquals(0, desc.bNumEndpoints());
    assertEquals(UsbConst.HUB_CLASSCODE, desc.bInterfaceClass());
    assertEquals(0, desc.bInterfaceSubClass());
    assertEquals(0, desc.bInterfaceProtocol());
    assertEquals(0, desc.iInterface());
}
 
开发者ID:usb4java,项目名称:usb4java-javax,代码行数:20,代码来源:RootHubInterfaceTest.java


示例4: sendMessage

import javax.usb.UsbConst; //导入依赖的package包/类
/**
 * Sends a message to the missile launcher.
 * 
 * @param device
 *            The USB device handle.
 * @param message
 *            The message to send.
 * @throws UsbException
 *             When sending the message failed.
 */
public static void sendMessage(UsbDevice device, byte[] message)
    throws UsbException
{
    UsbControlIrp irp = device.createUsbControlIrp(
        (byte) (UsbConst.REQUESTTYPE_TYPE_CLASS |
        UsbConst.REQUESTTYPE_RECIPIENT_INTERFACE), (byte) 0x09,
        (short) 2, (short) 1);
    irp.setData(message);
    device.syncSubmit(irp);
}
 
开发者ID:usb4java,项目名称:usb4java-javax-examples,代码行数:21,代码来源:MissileLauncher.java


示例5: sendBulkTransfer

import javax.usb.UsbConst; //导入依赖的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


示例6: controlRequest

import javax.usb.UsbConst; //导入依赖的package包/类
protected UsbControlIrp controlRequest() {
	final byte requestType = UsbConst.REQUESTTYPE_TYPE_VENDOR;
	final byte request = UsbConst.REQUEST_GET_DESCRIPTOR;
	final short value = 0x100;
	final short index = 0;
	return device.createUsbControlIrp(requestType, request, value, index);
}
 
开发者ID:IAmContent,项目名称:public,代码行数:8,代码来源:Owi535UsbMotorController.java


示例7: init

import javax.usb.UsbConst; //导入依赖的package包/类
private void init()
{
    this.usbDevice.addUsbDeviceListener(this);

    this.resetStates();

    // Set up the control pipe.
    this.irp = usbDevice.createUsbControlIrp(
            (byte) UsbConst.CONFIGURATION_SELF_POWERED,
            (byte) UsbConst.REQUEST_GET_DESCRIPTOR,
            (short) 0x100,
            (short) 0
    );
}
 
开发者ID:swordmaster2k,项目名称:robotarmedge,代码行数:15,代码来源:UsbRobotArm.java


示例8: getSpeed

import javax.usb.UsbConst; //导入依赖的package包/类
@Override
public final Object getSpeed()
{
    switch (this.speed)
    {
        case LibUsb.SPEED_FULL:
            return UsbConst.DEVICE_SPEED_FULL;
        case LibUsb.SPEED_LOW:
            return UsbConst.DEVICE_SPEED_LOW;
        default:
            return UsbConst.DEVICE_SPEED_UNKNOWN;
    }
}
 
开发者ID:usb4java,项目名称:usb4java-javax,代码行数:14,代码来源:AbstractDevice.java


示例9: processIrp

import javax.usb.UsbConst; //导入依赖的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


示例10: findInterruptInEndpoint

import javax.usb.UsbConst; //导入依赖的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


示例11: getSpeed

import javax.usb.UsbConst; //导入依赖的package包/类
@Override
public Object getSpeed()
{
    return UsbConst.DEVICE_SPEED_UNKNOWN;
}
 
开发者ID:usb4java,项目名称:usb4java-javax,代码行数:6,代码来源:RootHub.java


示例12: getDirection

import javax.usb.UsbConst; //导入依赖的package包/类
@Override
public byte getDirection()
{
    final byte address = this.descriptor.bEndpointAddress();
    return (byte) (address & UsbConst.ENDPOINT_DIRECTION_MASK);
}
 
开发者ID:usb4java,项目名称:usb4java-javax,代码行数:7,代码来源:Endpoint.java


示例13: getType

import javax.usb.UsbConst; //导入依赖的package包/类
@Override
public byte getType()
{
    final byte attribs = this.descriptor.bmAttributes();
    return (byte) (attribs & UsbConst.ENDPOINT_TYPE_MASK);
}
 
开发者ID:usb4java,项目名称:usb4java-javax,代码行数:7,代码来源:Endpoint.java


示例14: checkDevice

import javax.usb.UsbConst; //导入依赖的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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java StatusTextEvent类代码示例发布时间:2022-05-23
下一篇:
Java ImageDeformationByFilters类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap