jAER project on SourceForge

net.sf.jaer.hardwareinterface.usb.silabs
Class SiLabsC8051F320_USBIO_AeSequencer

java.lang.Object
  extended by net.sf.jaer.hardwareinterface.usb.silabs.SiLabsC8051F320_USBIO_AeSequencer
All Implemented Interfaces:
de.thesycon.usbio.PnPNotifyInterface, de.thesycon.usbio.UsbIoErrorCodes, AESequencerInterface, HardwareInterface, USBInterface

public class SiLabsC8051F320_USBIO_AeSequencer
extends java.lang.Object
implements de.thesycon.usbio.UsbIoErrorCodes, de.thesycon.usbio.PnPNotifyInterface, AESequencerInterface

The USB simplemonitor board is used to sequence out events using this class and appropriate firmware on the board.

Servo motor controller using USBIO driver access to SiLabsC8051F320 device. To prevent blocking on the thread controlling the servo, this class starts a consumer thread that communicates with the USB interface. The producer (the user) communicates with the consumer thread using an ArrayBlockingQueue. Therefore servo commands never produce hardware exceptions; these are caught in the consumer thread by closing the device, which should be reopened on the next command.

This class goes with the USB simplemonitor board.

Author:
tobi

Field Summary
protected  de.thesycon.usbio.structs.USB_DEVICE_DESCRIPTOR deviceDescriptor
          the USBIO device descriptor
static int ENDPOINT_OUT_LENGTH
          length of endpoint, ideally this value should be obtained from the pipe bound to the endpoint but we know what it is for this device.
protected  int gDevList
          the devlist handle for USBIO
static java.lang.String GUID
          driver guid (Globally unique ID, for this USB driver instance
protected  de.thesycon.usbio.UsbIo gUsbIo
          the UsbIo interface to the device.
static int HOST_BUFFER_LENGTH
           
protected  int interfaceNumber
          the device number, out of all potential compatible devices that could be opened
protected  int numberOfStringDescriptors
           
static int PACKET_QUEUE_LENGTH
          number of packets that can be queued up.
static short PID
           
protected  de.thesycon.usbio.structs.USB_STRING_DESCRIPTOR stringDescriptor1
          the first USB string descriptor (Vendor name) (if available)
protected  de.thesycon.usbio.structs.USB_STRING_DESCRIPTOR stringDescriptor2
          the second USB string descriptor (Product name) (if available)
protected  de.thesycon.usbio.structs.USB_STRING_DESCRIPTOR stringDescriptor3
          the third USB string descriptor (Serial number) (if available)
static short VID
          The vendor ID
 
Fields inherited from interface de.thesycon.usbio.UsbIoErrorCodes
USBIO_ERR_ADDITIONAL_EVENT_SIGNALLED, USBIO_ERR_ALREADY_BOUND, USBIO_ERR_ALREADY_CONFIGURED, USBIO_ERR_BABBLE_DETECTED, USBIO_ERR_BAD_START_FRAME, USBIO_ERR_BTSTUFF, USBIO_ERR_BUFFER_OVERRUN, USBIO_ERR_BUFFER_UNDERRUN, USBIO_ERR_BULK_RESTRICTION, USBIO_ERR_CANCELED, USBIO_ERR_CONTROL_NOT_SUPPORTED, USBIO_ERR_CONTROL_RESTRICTION, USBIO_ERR_CRC, USBIO_ERR_DATA_BUFFER_ERROR, USBIO_ERR_DATA_OVERRUN, USBIO_ERR_DATA_TOGGLE_MISMATCH, USBIO_ERR_DATA_UNDERRUN, USBIO_ERR_DEMO_EXPIRED, USBIO_ERR_DEV_NOT_RESPONDING, USBIO_ERR_DEVICE_GONE, USBIO_ERR_DEVICE_NOT_FOUND, USBIO_ERR_DEVICE_NOT_OPEN, USBIO_ERR_DEVICE_NOT_PRESENT, USBIO_ERR_ENDPOINT_HALTED, USBIO_ERR_EP0_RESTRICTION, USBIO_ERR_ERROR_BUSY, USBIO_ERR_ERROR_SHORT_TRANSFER, USBIO_ERR_FAILED, USBIO_ERR_FIFO, USBIO_ERR_FRAME_CONTROL_NOT_OWNED, USBIO_ERR_FRAME_CONTROL_OWNED, USBIO_ERR_INSUFFICIENT_RESOURCES, USBIO_ERR_INTERFACE_NOT_FOUND, USBIO_ERR_INTERNAL_HC_ERROR, USBIO_ERR_INTERRUPT_RESTRICTION, USBIO_ERR_INVALID_CONFIGURATION_DESCRIPTOR, USBIO_ERR_INVALID_DEVICE_STATE, USBIO_ERR_INVALID_DIRECTION, USBIO_ERR_INVALID_FUNCTION_PARAM, USBIO_ERR_INVALID_INBUFFER, USBIO_ERR_INVALID_IOCTL, USBIO_ERR_INVALID_ISO_PACKET, USBIO_ERR_INVALID_OUTBUFFER, USBIO_ERR_INVALID_PARAM, USBIO_ERR_INVALID_PARAMETER, USBIO_ERR_INVALID_PIPE_FLAGS, USBIO_ERR_INVALID_PIPE_HANDLE, USBIO_ERR_INVALID_POWER_STATE, USBIO_ERR_INVALID_RECIPIENT, USBIO_ERR_INVALID_TYPE, USBIO_ERR_INVALID_URB_FUNCTION, USBIO_ERR_ISO_NA_LATE_USBPORT, USBIO_ERR_ISO_NOT_ACCESSED_BY_HW, USBIO_ERR_ISO_NOT_ACCESSED_LATE, USBIO_ERR_ISO_RESTRICTION, USBIO_ERR_ISO_TD_ERROR, USBIO_ERR_ISOCH_REQUEST_FAILED, USBIO_ERR_LOAD_SETUP_API_FAILED, USBIO_ERR_NO_BANDWIDTH, USBIO_ERR_NO_MEMORY, USBIO_ERR_NO_SUCH_DEVICE_INSTANCE, USBIO_ERR_NOT_ACCESSED, USBIO_ERR_NOT_BOUND, USBIO_ERR_NOT_CONFIGURED, USBIO_ERR_NOT_SUPPORTED, USBIO_ERR_OPEN_PIPES, USBIO_ERR_OUT_OF_ADDRESS_SPACE, USBIO_ERR_OUT_OF_MEMORY, USBIO_ERR_PENDING_REQUESTS, USBIO_ERR_PID_CHECK_FAILURE, USBIO_ERR_PIPE_NOT_FOUND, USBIO_ERR_PIPE_RESTRICTION, USBIO_ERR_PIPE_SIZE_RESTRICTION, USBIO_ERR_POOL_EMPTY, USBIO_ERR_POWER_DOWN, USBIO_ERR_REQUEST_FAILED, USBIO_ERR_RESERVED1, USBIO_ERR_RESERVED2, USBIO_ERR_SET_CONFIG_FAILED, USBIO_ERR_SET_CONFIGURATION_FAILED, USBIO_ERR_STALL_PID, USBIO_ERR_STATUS_NOT_MAPPED, USBIO_ERR_SUCCESS, USBIO_ERR_TIMEOUT, USBIO_ERR_TOO_MUCH_ISO_PACKETS, USBIO_ERR_UNEXPECTED_PID, USBIO_ERR_USBD_BUFFER_TOO_SMALL, USBIO_ERR_USBD_INTERFACE_NOT_FOUND, USBIO_ERR_USBD_TIMEOUT, USBIO_ERR_VERSION_MISMATCH, USBIO_ERR_VID_RESTRICTION, USBIO_ERR_XACT_ERROR
 
Fields inherited from interface net.sf.jaer.hardwareinterface.usb.USBInterface
PID_THESYCON_END, PID_THESYCON_START, VID_THESYCON
 
Constructor Summary
SiLabsC8051F320_USBIO_AeSequencer()
          Creates a new instance of SiLabsC8051F320_USBIO_ServoController using device 0 - the first device in the list.
SiLabsC8051F320_USBIO_AeSequencer(int devNumber)
          Creates a new instance of USBAEMonitor.
 
Method Summary
protected  void checkWtiterThread()
           
 void close()
          Closes the device.
 short getDID()
           
 int getEstimatedOutEventRate()
          Returns estimate of present out event rate on this interface
 int getMaxCapacity()
          Returns max capacity of this interface in events/sec
 int getNumberOfStringDescriptors()
          returns number of string descriptors
 int getNumEventsSent()
           
 int getNumEventsToSend()
           
 short getPID()
           
 java.lang.String[] getStringDescriptors()
          return the string USB descriptors for the device
 int getTimestampTickUs()
           
 java.lang.String getTypeName()
          get text name of interface, e.g.
 short getVID()
           
 int[] getVIDPID()
          return the USB VID/PID of the interface
protected  boolean hasStringIdentifier()
          checks if device has a string identifier that is a non-empty string
 boolean isEventSequencingEnabled()
           
 boolean isLoopedSequencingEnabled()
           
 boolean isOpen()
          reports if interface is open().
 void offerPacketToSequencer(AEPacketRaw packet)
          Offers a packet to be sequenced to the sequencer.
 void onAdd()
           
 void onRemove()
           
 void open()
          This method does the hard work of opening the device, downloading the firmware, making sure everything is OK.
 void resetTimestamps()
          resets the timestamps to start at zero
 void setLoopedSequencingEnabled(boolean set)
          enables continuous sequencing, if enabled the AEWriter rewinds if it reaches the end of the packet and restarts sending from the beginning.
 void startSequencing(AEPacketRaw eventsToSend)
          starts sequencing of events, starts AEWriter.
 void stopSequencing()
          stops sequencing of events from the driver
protected  void submitPacket(AEPacketRaw packet)
          Submits the packet to the writer thread queue that sends them to the device
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GUID

public static final java.lang.String GUID
driver guid (Globally unique ID, for this USB driver instance

See Also:
Constant Field Values

VID

public static final short VID
The vendor ID

See Also:
Constant Field Values

PID

public static final short PID
See Also:
Constant Field Values

ENDPOINT_OUT_LENGTH

public static final int ENDPOINT_OUT_LENGTH
length of endpoint, ideally this value should be obtained from the pipe bound to the endpoint but we know what it is for this device. It is set to 16 bytes to minimize transmission time. At 12 Mbps, 16 bytes+header (13 bytes)=140 bits requires about 30 us to transmit.

See Also:
Constant Field Values

HOST_BUFFER_LENGTH

public static final int HOST_BUFFER_LENGTH
See Also:
Constant Field Values

PACKET_QUEUE_LENGTH

public static final int PACKET_QUEUE_LENGTH
number of packets that can be queued up. It is set to a small number so that comands do not pile up. If the queue is full when a command is given, then the old commands are discarded so that the latest command is next to be processed. Note that this policy can have drawbacks - if commands are sent to different servos successively, then new commands can wipe out commands to older commands to set other servos to some position.

See Also:
Constant Field Values

interfaceNumber

protected int interfaceNumber
the device number, out of all potential compatible devices that could be opened


stringDescriptor1

protected de.thesycon.usbio.structs.USB_STRING_DESCRIPTOR stringDescriptor1
the first USB string descriptor (Vendor name) (if available)


stringDescriptor2

protected de.thesycon.usbio.structs.USB_STRING_DESCRIPTOR stringDescriptor2
the second USB string descriptor (Product name) (if available)


stringDescriptor3

protected de.thesycon.usbio.structs.USB_STRING_DESCRIPTOR stringDescriptor3
the third USB string descriptor (Serial number) (if available)


numberOfStringDescriptors

protected int numberOfStringDescriptors

deviceDescriptor

protected de.thesycon.usbio.structs.USB_DEVICE_DESCRIPTOR deviceDescriptor
the USBIO device descriptor


gUsbIo

protected de.thesycon.usbio.UsbIo gUsbIo
the UsbIo interface to the device. This is assigned on construction by the factory which uses it to open the device. here is used for all USBIO access to the device


gDevList

protected int gDevList
the devlist handle for USBIO

Constructor Detail

SiLabsC8051F320_USBIO_AeSequencer

public SiLabsC8051F320_USBIO_AeSequencer()
Creates a new instance of SiLabsC8051F320_USBIO_ServoController using device 0 - the first device in the list.


SiLabsC8051F320_USBIO_AeSequencer

public SiLabsC8051F320_USBIO_AeSequencer(int devNumber)
Creates a new instance of USBAEMonitor. Note that it is possible to construct several instances and use each of them to open and read from the same device.

Parameters:
devNumber - the desired device number, in range returned by CypressFX2Factory.getNumInterfacesAvailable
Method Detail

onAdd

public void onAdd()
Specified by:
onAdd in interface de.thesycon.usbio.PnPNotifyInterface

onRemove

public void onRemove()
Specified by:
onRemove in interface de.thesycon.usbio.PnPNotifyInterface

close

public void close()
Closes the device. Never throws an exception.

Specified by:
close in interface HardwareInterface

getNumberOfStringDescriptors

public int getNumberOfStringDescriptors()
returns number of string descriptors

Returns:
number of string descriptors: 2 for TmpDiff128, 3 for MonitorSequencer

hasStringIdentifier

protected boolean hasStringIdentifier()
checks if device has a string identifier that is a non-empty string

Returns:
false if not, true if there is one

open

public void open()
          throws HardwareInterfaceException
This method does the hard work of opening the device, downloading the firmware, making sure everything is OK. This method is synchronized to prevent multiple threads from trying to open at the same time, e.g. a GUI thread and the main thread. Opening the device after it has already been opened has no effect.

Specified by:
open in interface HardwareInterface
Throws:
HardwareInterfaceException - if there is a problem. Diagnostics are printed to stderr.
See Also:
close()

getStringDescriptors

public java.lang.String[] getStringDescriptors()
return the string USB descriptors for the device

Specified by:
getStringDescriptors in interface USBInterface
Returns:
String[] of length 2 of USB descriptor strings.

getVIDPID

public int[] getVIDPID()
return the USB VID/PID of the interface

Specified by:
getVIDPID in interface USBInterface
Returns:
int[] of length 2 containing the Vendor ID (VID) and Product ID (PID) of the device. First element is VID, second element is PID.

getVID

public short getVID()
Specified by:
getVID in interface USBInterface
Returns:
PID (vendor ID)

getPID

public short getPID()
Specified by:
getPID in interface USBInterface
Returns:
PID (product ID)

getDID

public short getDID()
Specified by:
getDID in interface USBInterface
Returns:
bcdDevice (the binary coded decimel device version

isOpen

public boolean isOpen()
reports if interface is open().

Specified by:
isOpen in interface HardwareInterface
Returns:
true if already open

getTypeName

public java.lang.String getTypeName()
Description copied from interface: HardwareInterface
get text name of interface, e.g. "CypressFX2" or "SiLabsC8051F320"

Specified by:
getTypeName in interface HardwareInterface

submitPacket

protected void submitPacket(AEPacketRaw packet)
Submits the packet to the writer thread queue that sends them to the device

Parameters:
packet - the packet, which consists of EventRaw's to be sent to the device with absolute timestamps

checkWtiterThread

protected void checkWtiterThread()

getNumEventsSent

public int getNumEventsSent()
Specified by:
getNumEventsSent in interface AESequencerInterface

getNumEventsToSend

public int getNumEventsToSend()
Specified by:
getNumEventsToSend in interface AESequencerInterface

resetTimestamps

public void resetTimestamps()
Description copied from interface: AESequencerInterface
resets the timestamps to start at zero

Specified by:
resetTimestamps in interface AESequencerInterface

isEventSequencingEnabled

public boolean isEventSequencingEnabled()
Specified by:
isEventSequencingEnabled in interface AESequencerInterface
Returns:
true if event sequencing is enabled

getMaxCapacity

public int getMaxCapacity()
Description copied from interface: AESequencerInterface
Returns max capacity of this interface in events/sec

Specified by:
getMaxCapacity in interface AESequencerInterface
Returns:
max capacity in events/sec

getEstimatedOutEventRate

public int getEstimatedOutEventRate()
Description copied from interface: AESequencerInterface
Returns estimate of present out event rate on this interface

Specified by:
getEstimatedOutEventRate in interface AESequencerInterface
Returns:
estimated event rate in events/sec

getTimestampTickUs

public int getTimestampTickUs()
Specified by:
getTimestampTickUs in interface AESequencerInterface
Returns:
timestamp tick in us for this interface

offerPacketToSequencer

public void offerPacketToSequencer(AEPacketRaw packet)
Description copied from interface: AESequencerInterface
Offers a packet to be sequenced to the sequencer. Calling this automatically should disable looping the sequenced data.

Specified by:
offerPacketToSequencer in interface AESequencerInterface
Parameters:
packet - the packet to add to the tail of the queue.

setLoopedSequencingEnabled

public void setLoopedSequencingEnabled(boolean set)
Description copied from interface: AESequencerInterface
enables continuous sequencing, if enabled the AEWriter rewinds if it reaches the end of the packet and restarts sending from the beginning. otherwise it just stops sequencing.

Specified by:
setLoopedSequencingEnabled in interface AESequencerInterface
Parameters:
set - true to loop packet, false to sequence a single packet

isLoopedSequencingEnabled

public boolean isLoopedSequencingEnabled()
Specified by:
isLoopedSequencingEnabled in interface AESequencerInterface
Returns:
true if sequencing will loop back to start at end of data

startSequencing

public void startSequencing(AEPacketRaw eventsToSend)
                     throws HardwareInterfaceException
Description copied from interface: AESequencerInterface
starts sequencing of events, starts AEWriter.

Specified by:
startSequencing in interface AESequencerInterface
Parameters:
eventsToSend - the events that should be sequenced, timestamps are realtive to last event, inter spike interval must not be bigger than 2^16-1
Throws:
HardwareInterfaceException

stopSequencing

public void stopSequencing()
                    throws HardwareInterfaceException
Description copied from interface: AESequencerInterface
stops sequencing of events from the driver

Specified by:
stopSequencing in interface AESequencerInterface
Throws:
HardwareInterfaceException

jAER project on SourceForge