public interface GenericDevice extends Device<GenericDevice>
GenericDevice interface defines methods for setting and getting
device-specific configuration and access (I/O) controls as well as registering event listeners.
A generic device may be identified by the numerical ID and by the name (if any defined) that
correspond to its registered configuration. An GenericDevice instance can be opened by a
call to one of the DeviceManager.open(id,...) methods using its ID or by a call to one of the
DeviceManager.open(name,...) methods using its name.
An application can set and get configuration and access (I/O) controls. A control is identified
by a GenericDeviceControl instance and can be set or gotten using the
setControl and
getControl methods. Controls can
be used to configured a device a well as performing basic input/output operations. The
list of controls supported by a device is device-specific.
An application can also register an GenericEventListener instance to monitor native
events of the designated type fired by the device. To register a
GenericEventListener instance, the application must call the
setEventListener method. The registered listener can later on
be removed by calling the same method with a null listener parameter. Asynchronous
notification may not be supported by all devices. An attempt to set a listener on a device which
does not supports it will result in an UnsupportedOperationException being thrown.
A platform implementer may allow through this interface access and control of devices
which do not require read and write operations and for which there exist no other more specific
API such as GPIOPin or
GPIOPort.BIG_ENDIAN, LITTLE_ENDIAN, MIXED_ENDIAN| Modifier and Type | Method and Description |
|---|---|
<T> T |
getControl(GenericDeviceControl<T> control)
Gets the value of the specified control.
|
<T> void |
setControl(GenericDeviceControl<T> control,
T value)
Sets the value of the specified control.
|
void |
setEventListener(int eventId,
GenericEventListener listener)
Registers a
GenericEventListener instance to monitor native events of the designated
type fired by the device associated to this GenericDevice object. |
<T> T getControl(GenericDeviceControl<T> control) throws java.io.IOException, UnavailableDeviceException, ClosedDeviceException
T - the type of the control's value.control - the control to get.java.lang.IllegalArgumentException - if control is not recognized or invalid.java.io.IOException - if some other I/O error occurs.UnavailableDeviceException - if this device is not currently available - such as it is locked by another
application.ClosedDeviceException - if the device has been closed.<T> void setControl(GenericDeviceControl<T> control, T value) throws java.io.IOException, UnavailableDeviceException, ClosedDeviceException
T - the type of the control's value.control - the control to set.value - the value to set.java.lang.IllegalArgumentException - if control is not recognized or invalid.java.io.IOException - if some other I/O error occurs.UnavailableDeviceException - if this device is not currently available - such as it is locked by another
application.ClosedDeviceException - if the device has been closed.void setEventListener(int eventId,
GenericEventListener listener)
throws java.io.IOException,
UnavailableDeviceException,
ClosedDeviceException
GenericEventListener instance to monitor native events of the designated
type fired by the device associated to this GenericDevice object. While
the listener can be triggered by hardware interrupts, there are no real-time guarantees of
when the listener will be called.
A list of event type IDs is defined in GenericEvent. This list can be extended with
device-specific IDs.
If this GenericDevice is open in
DeviceManager.SHARED access mode the listeners registered
by all the applications sharing the underlying device will get notified of the events they
registered for.
If listener is null then listener previously registered for the specified
event type will be removed.
Only one listener can be registered at a particular time for a particular event type.eventId - ID of the native event to listen to.listener - the GenericEventListener instance to be notified upon occurrence of the
designated event.java.io.IOException - if some other I/O error occurs.java.lang.IllegalArgumentException - if eventId does not correspond to any supported event.java.lang.UnsupportedOperationException - if this GenericDevice object does not support asynchronous event
notification.java.lang.IllegalStateException - if listener is not null and a listener is already registered for
the specified event type.ClosedDeviceException - if the device has been closed.UnavailableDeviceExceptionCopyright © 2012, 2014, Oracle and/or its affiliates. All rights reserved.
Legal Notices