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


Java LibUsb.allocTransfer方法代码示例

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


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

示例1: prepareTransfers

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * Prepares (allocates) a set of transfer buffers for use in transferring data from the USB device via the bulk
 * interface.  Since we're using direct allocation (native), buffers are retained and reused across multiple
 * start/stop cycles.
 */
private void prepareTransfers() throws LibUsbException
{
    while(mAvailableTransfers.size() < TRANSFER_BUFFER_POOL_SIZE)
    {
        Transfer transfer = LibUsb.allocTransfer();

        if(transfer == null)
        {
            throw new LibUsbException("Couldn't allocate USB transfer buffer", LibUsb.ERROR_NO_MEM);
        }

        final ByteBuffer buffer = ByteBuffer.allocateDirect(mBufferSize);

        LibUsb.fillBulkTransfer(transfer, mDeviceHandle, USB_BULK_TRANSFER_ENDPOINT, buffer, this,
            "Buffer", USB_TIMEOUT_MS);

        mAvailableTransfers.add(transfer);
    }
}
 
开发者ID:DSheirer,项目名称:sdrtrunk,代码行数:25,代码来源:USBTransferProcessor.java

示例2: write

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * Asynchronously writes some data to the device.
 * 
 * @param handle
 *            The device handle.
 * @param data
 *            The data to send to the device.
 * @param callback
 *            The callback to execute when data has been transfered.
 */
public static void write(DeviceHandle handle, byte[] data,
    TransferCallback callback)
{
    ByteBuffer buffer = BufferUtils.allocateByteBuffer(data.length);
    buffer.put(data);
    Transfer transfer = LibUsb.allocTransfer();
    LibUsb.fillBulkTransfer(transfer, handle, OUT_ENDPOINT, buffer,
        callback, null, TIMEOUT);
    System.out.println("Sending " + data.length + " bytes to device");
    int result = LibUsb.submitTransfer(transfer);
    if (result != LibUsb.SUCCESS)
    {
        throw new LibUsbException("Unable to submit transfer", result);
    }
}
 
开发者ID:usb4java,项目名称:usb4java-examples,代码行数:26,代码来源:AsyncBulkTransfer.java

示例3: read

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * Asynchronously reads some data from the device.
 * 
 * @param handle
 *            The device handle.
 * @param size
 *            The number of bytes to read from the device.
 * @param callback
 *            The callback to execute when data has been received.
 */
public static void read(DeviceHandle handle, int size,
    TransferCallback callback)
{
    ByteBuffer buffer = BufferUtils.allocateByteBuffer(size).order(
        ByteOrder.LITTLE_ENDIAN);
    Transfer transfer = LibUsb.allocTransfer();
    LibUsb.fillBulkTransfer(transfer, handle, IN_ENDPOINT, buffer,
        callback, null, TIMEOUT);
    System.out.println("Reading " + size + " bytes from device");
    int result = LibUsb.submitTransfer(transfer);
    if (result != LibUsb.SUCCESS)
    {
        throw new LibUsbException("Unable to submit transfer", result);
    }
}
 
开发者ID:usb4java,项目名称:usb4java-examples,代码行数:26,代码来源:AsyncBulkTransfer.java

示例4: start_transfers

import org.usb4java.LibUsb; //导入方法依赖的package包/类
protected boolean start_transfers(DeviceHandle handle, int curr_frame_size) {
  // Initialize the frame queue
  frame_size = curr_frame_size;
  
  frame_queue.resize(frame_size);

  // Initialize the current frame pointer to the start of the buffer; it will
  // be updated as frames are completed and pushed onto the frame queue
  cur_frame_start = frame_queue.GetFrameBufferStart();
  cur_frame_data_len = 0;

  // Find the bulk transfer endpoint
  byte bulk_endpoint = find_ep(LibUsb.getDevice(handle));
  LibUsb.clearHalt(handle, bulk_endpoint);

  int res = 0;
  for (int index = 0; index < NUM_TRANSFERS; ++index) {
    // Create & submit the transfer
    TranferUserData user_data = new TranferUserData(this, index);
    xfr[index] = LibUsb.allocTransfer(0);
    
    // Java GC takes care of memory freeing
    ByteBuffer transfer_buffer = ByteBuffer.allocateDirect(TRANSFER_SIZE);
    
    LibUsb.fillBulkTransfer(xfr[index], handle, bulk_endpoint, transfer_buffer, transfer_completed_callback, user_data, 0);
    res |= LibUsb.submitTransfer(xfr[index]);
    
    num_active_transfers++;
  }

  last_pts = 0;
  last_fid = 0;

  PS3Eye.usb.cameraStarted();

  return res == 0;
}
 
开发者ID:diwi,项目名称:PS3Eye,代码行数:38,代码来源:URBDesc.java

示例5: prepareTransfers

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * Prepares (allocates) a set of transfer buffers for use in 
 * transferring data from the tuner via the bulk interface
 */
private void prepareTransfers() throws LibUsbException
{
	if( mAvailableTransfers == null )
	{
		mAvailableTransfers = new LinkedTransferQueue<>();
		
 	for( int x = 0; x < TRANSFER_BUFFER_POOL_SIZE; x++ )
 	{
 		Transfer transfer = LibUsb.allocTransfer();

 		if( transfer == null )
 		{
 			throw new LibUsbException( "couldn't allocate transfer", 
 						LibUsb.ERROR_NO_MEM );
 		}
 		
 		final ByteBuffer buffer = 
 				ByteBuffer.allocateDirect( mBufferSize );
 		
 		LibUsb.fillBulkTransfer( transfer, mDeviceHandle, USB_BULK_ENDPOINT, 
 				buffer, BufferProcessor.this, "Buffer", TIMEOUT_US );

 		mAvailableTransfers.add( transfer );
 	}
	}
}
 
开发者ID:ac2cz,项目名称:FoxTelem,代码行数:31,代码来源:RTL2832TunerController.java

示例6: prepareTransfers

import org.usb4java.LibUsb; //导入方法依赖的package包/类
/**
 * Prepares (allocates) a set of transfer buffers for use in 
 * transferring data from the tuner via the bulk interface
 */
private void prepareTransfers() throws LibUsbException
{
	if( mAvailableTransfers == null )
	{
		mAvailableTransfers = new LinkedTransferQueue<Transfer>();
		
 	for( int x = 0; x < TRANSFER_BUFFER_POOL_SIZE; x++ )
 	{
 		Transfer transfer = LibUsb.allocTransfer();

 		if( transfer == null )
 		{
 			throw new LibUsbException( "couldn't allocate transfer", 
 						LibUsb.ERROR_NO_MEM );
 		}
 		
 		final ByteBuffer buffer = 
 				ByteBuffer.allocateDirect( mBufferSize );
 		
 		LibUsb.fillBulkTransfer( transfer, mDeviceHandle, USB_ENDPOINT, 
				buffer, BufferProcessor.this, "Buffer", USB_TIMEOUT_MS );

 		mAvailableTransfers.add( transfer );
 	}
	}
}
 
开发者ID:ac2cz,项目名称:FoxTelem,代码行数:31,代码来源:AirspyDevice.java


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