ztex
Class ZtexUsbReader

java.lang.Object
  extended by ztex.ZtexUsbReader

public class ZtexUsbReader
extends java.lang.Object

A helper class to implement asynchronous bulk and interrupt read transfers. This class also has a speed test mode.


Constructor Summary
ZtexUsbReader(org.usb4java.DeviceHandle p_handle, int p_ep, boolean p_isInt, int p_bufNum, int p_bufSize)
          Creates the reader for a given USB device and endpoint number.
ZtexUsbReader(Ztex1 ztex, int p_ep, boolean p_isInt, int p_bufNum, int p_bufSize)
          Creates the reader from a given ZTEX device and endpoint number.
ZtexUsbReader(Ztex1v1 ztex, int p_bufNum, int p_bufSize)
          Creates the reader for the input endpoint of the default interface of a ZTEX device.
 
Method Summary
 int bufSize()
          Return the buffer size.
 long byteCount()
          Return the number of bytes read since last start(long).
 void cancel()
          Cancels all pending transfers, also see cancelWait(int),
 boolean cancelWait(int timeout)
          Cancels all pending transfers and waits until transfers are canceled.
 int getBuffer(byte[] buf, int timeout)
          Get the next buffer.
 void start(long maxCount)
          Start the reader.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZtexUsbReader

public ZtexUsbReader(org.usb4java.DeviceHandle p_handle,
                     int p_ep,
                     boolean p_isInt,
                     int p_bufNum,
                     int p_bufSize)
Creates the reader for a given USB device and endpoint number.

Parameters:
p_handle - The device handle used for communication (must be opened).
p_ep - The input endpoint.
p_isInt - True if it is an interrupt transfer.
p_bufSize - size of each buffer. Typical values are 64KByte to 512KByte
p_bufNum - number of buffer. Recommended queue size is 2MByte to 8MByte.

ZtexUsbReader

public ZtexUsbReader(Ztex1 ztex,
                     int p_ep,
                     boolean p_isInt,
                     int p_bufNum,
                     int p_bufSize)
Creates the reader from a given ZTEX device and endpoint number.

Parameters:
ztex - The ZTEX device.
p_ep - The number of the input endpoint
p_isInt - True if it is an interrupt transfer.
p_bufSize - size of each buffer. Typical values are 64KByte to 512KByte
p_bufNum - number of buffer. Recommended queue size is 2MByte to 8MByte.

ZtexUsbReader

public ZtexUsbReader(Ztex1v1 ztex,
                     int p_bufNum,
                     int p_bufSize)
              throws InvalidFirmwareException,
                     UsbException,
                     CapabilityException
Creates the reader for the input endpoint of the default interface of a ZTEX device.

Parameters:
ztex - The ZTEX device.
p_bufSize - size of each buffer. Typical values are 64KByte to 512KByte
p_bufNum - number of buffer. Recommended queue size is 2MByte to 8MByte.
Throws:
InvalidFirmwareException
UsbException
CapabilityException
Method Detail

getBuffer

public int getBuffer(byte[] buf,
                     int timeout)
              throws UsbException
Get the next buffer. This does not work in speed test mode, see see start(long).

Parameters:
buf - The byte array where to store the data.
timeout - Timeout in ms. If timeout occurs the function returns -1.
Returns:
The number of bytes read or -1 if timeout occurs.
Throws:
UsbExecption - if an error occurred.
UsbException

byteCount

public long byteCount()
Return the number of bytes read since last start(long).

Returns:
The number of bytes read since last start(long).

bufSize

public int bufSize()
Return the buffer size.

Returns:
The buffer size.

cancel

public void cancel()
            throws UsbException
Cancels all pending transfers, also see cancelWait(int),

Throws:
UsbExecption - if an error occurred.
UsbException

cancelWait

public boolean cancelWait(int timeout)
                   throws UsbException
Cancels all pending transfers and waits until transfers are canceled.

Throws:
UsbExecption - if an error occurred.
UsbException

start

public void start(long maxCount)
           throws UsbException
Start the reader. The amount of buffers to be read is defined using the parameter maxCount. A value of 0 starts infinite reads, a value of -1 starts the reader in speed test mode. In this mode the buffer content is ignored and new read transfer are initiated immediately.

Parameters:
maxCount - Maximum amount of bytes to read or 0 for infinite transfers or <0 for speed test mode.
Throws:
UsbExecption - if an error occurred.
UsbException