dk.opi.io
Class DefaultIOItem

java.lang.Object
  extended bydk.opi.io.DefaultIOItem
All Implemented Interfaces:
IOItem
Direct Known Subclasses:
OpcItem

public abstract class DefaultIOItem
extends Object
implements IOItem

This class implements the IOGroup interface and implements a simple polling interface for IOItem values. Ie. if you set the group active this class will poll IOItems belonging to this group and report any changes in item values


Field Summary
protected  String actionCommand
           
protected  boolean active
           
protected  int dataType
           
protected  String description
           
static IOQuality GOOD_QUALITY_VALUE
          Implementation of IOQuality always returning "good"
protected  IOGroup ioGroup
           
protected  String name
           
protected  Object oldValue
           
protected  Object userObject
           
 
Fields inherited from interface dk.opi.io.IOItem
CACHE_READ, DATATYPE_BOOL, DATATYPE_BOOLARRAY, DATATYPE_DATE, DATATYPE_DOUBLE, DATATYPE_DOUBLEARRAY, DATATYPE_FLOAT, DATATYPE_FLOATARRAY, DATATYPE_INT, DATATYPE_INTARRAY, DATATYPE_STRING, DATATYPE_USE_NATIVE, DEVICE_READ
 
Constructor Summary
DefaultIOItem(IOGroup iog, String name, int dataType, boolean active, String actionCommand)
          Construct a new DefaultIOItem object.
DefaultIOItem(IOGroup iog, String name, int dataType, boolean active, String actionCommand, String descr)
          Construct a new DefaultIOItem object
 
Method Summary
 String getActionCommand()
          Returns the command name associated with this item.
 int getDataType()
          Describes the data type of the value associated with this event.
 String getDescription()
          Get descriptive text for this item
 IOGroup getGroup()
          Get the group this item belongs to
 IOQuality getOldQuality()
          Returns the quality of the last read value, ie. quality corresponding to the value returned from calling getOldValue() This default implementation will always return good.
 Object getOldValue()
          Last value read from the device - can be used to efficiently read an an item value when fired in an IOListener onDataChanged() event.
 Object getUserObject()
          Returns a user object that may optionally having been assigned to this IOItem.
 boolean isActive()
          Is the item active - ie. is it automatically being polled
 boolean isOldQualityGood()
          Returns quality of last read value.
abstract  Object readValue()
          Abstract method which will read the item value from the device.
 Object readValue(int dataSource)
          Read the item value from the device.
 void setActionCommand(String aCmd)
          Set the command name associated with this item.
 void setDescription(String text)
          Set descriptive text for this item
 void setOldValue(Object oldValue)
          The DefaultIOGroup class will call this method when a value has been read with the readValue() method.
 void setUserObject(Object o)
          Set optional user object associated with this IOItem.
 String toString()
           
abstract  void writeIntValue(int value)
          Deprecated. Replaced by writeValue(int).
abstract  void writeValue(boolean value)
          Write the specified value to the device.
abstract  void writeValue(Boolean value)
          Write the specified value to the device.
 void writeValue(boolean[] values)
          Write the specified array of booleans to the device.
abstract  void writeValue(double value)
          Write the specified value to the device.
 void writeValue(Double value)
          Write the specified value to the device.
 void writeValue(double[] values)
          Write the specified array of doubles to the device.
abstract  void writeValue(float value)
          Write the specified value to the device.
 void writeValue(Float value)
          Write the specified value to the device.
 void writeValue(float[] values)
          Write the specified array of floats to the device.
 void writeValue(int[] values)
          Write the specified array of integers to the device.
 void writeValue(Integer value)
          Write the specified value to the device.
abstract  void writeValue(String value)
          Write the specified value to the device.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface dk.opi.io.IOItem
writeValue
 

Field Detail

ioGroup

protected IOGroup ioGroup

name

protected String name

dataType

protected int dataType

active

protected boolean active

actionCommand

protected String actionCommand

oldValue

protected Object oldValue

description

protected String description

userObject

protected Object userObject

GOOD_QUALITY_VALUE

public static final IOQuality GOOD_QUALITY_VALUE
Implementation of IOQuality always returning "good"

Constructor Detail

DefaultIOItem

public DefaultIOItem(IOGroup iog,
                     String name,
                     int dataType,
                     boolean active,
                     String actionCommand)
Construct a new DefaultIOItem object. The description String of the item is set to the value of actionCommand

Parameters:
iog - what group this item belongs to
name - name of the group. Must be unique within this server
dataType - any of the types IOItem.DATATYPE_INT etc.
active - if items in this group are going to be monitored
actionCommand - optional string users can use to quickly identify an IOItem when for instance an item is sent to an IOListener

DefaultIOItem

public DefaultIOItem(IOGroup iog,
                     String name,
                     int dataType,
                     boolean active,
                     String actionCommand,
                     String descr)
Construct a new DefaultIOItem object

Parameters:
iog - what group this item belongs to
name - name of the group. Must be unique within this server
dataType - any of the types IOItem.DATATYPE_INT etc.
active - if items in this group are going to be monitored
actionCommand - optional string users can use to quickly identify an IOItem when for instance an item is sent to an IOListener
descr - description of the item. Can be queried by a call to getDescription()
Method Detail

getGroup

public IOGroup getGroup()
Get the group this item belongs to

Specified by:
getGroup in interface IOItem
Returns:
The group this item belongs to

readValue

public abstract Object readValue()
                          throws RbxIOException
Abstract method which will read the item value from the device. The value is converted into an object corresponding to the dataType of this item. This method must be implemented by subclasses of this class

Specified by:
readValue in interface IOItem
Returns:
the value read from the item. The object returned are either of type Integer, Boolean etc. depending on the datatype of the item
Throws:
RbxIOException - thrown if the read operation failed

readValue

public Object readValue(int dataSource)
                 throws RbxIOException
Read the item value from the device. The value is converted into an object corresponding to the dataType of this item. This default implementation will simply delegate to readValue() ignoring the dataSource parameter.

Specified by:
readValue in interface IOItem
Parameters:
dataSource - The source to read from, ie. CACHE_READ or DEVICE_READ. A cache read will obtain the current value for the item from the device server cache (ie. OPC server). This is fast but the value is only updated with the specified update rate. A CACHE read is accurate to within the 'UpdateRate' of the group. The data can be read from the DEVICE in which case an actual read of the physical device is to be performed. The intended use of a DEVICE read is to update the register value of an inactive item. The exact implementation of CACHE and DEVICE reads may vary between devices and communication servers. For CACHE reads the data is only valid if both the group and the item are active. DEVICE reads are not affected by the ACTIVE state of the group or item.
Throws:
RbxIOException - thrown if the read operation failed

writeIntValue

public abstract void writeIntValue(int value)
                            throws RbxIOException
Deprecated. Replaced by writeValue(int).

Abstract method which will write the specified value to the device. The value written is supplied as an integer This method must be implemented by subclasses of this class.

Specified by:
writeIntValue in interface IOItem
Parameters:
value - The value to send to the device
Throws:
RbxIOException - thrown if the write operation failed

writeValue

public abstract void writeValue(float value)
                         throws RbxIOException
Write the specified value to the device.

Specified by:
writeValue in interface IOItem
Parameters:
value - The value to send to the device
Throws:
RbxIOException - thrown if the write operation failed

writeValue

public abstract void writeValue(double value)
                         throws RbxIOException
Write the specified value to the device.

Specified by:
writeValue in interface IOItem
Parameters:
value - The value to send to the device
Throws:
RbxIOException - thrown if the write operation failed

writeValue

public abstract void writeValue(boolean value)
                         throws RbxIOException
Write the specified value to the device.

Specified by:
writeValue in interface IOItem
Parameters:
value - The value to send to the device
Throws:
RbxIOException - thrown if the write operation failed

writeValue

public void writeValue(Integer value)
                throws RbxIOException
Write the specified value to the device.

Specified by:
writeValue in interface IOItem
Parameters:
value - The value to send to the device
Throws:
RbxIOException - thrown if the write operation failed

writeValue

public void writeValue(Float value)
                throws RbxIOException
Write the specified value to the device.

Specified by:
writeValue in interface IOItem
Parameters:
value - The value to send to the device
Throws:
RbxIOException - thrown if the write operation failed

writeValue

public void writeValue(Double value)
                throws RbxIOException
Write the specified value to the device.

Specified by:
writeValue in interface IOItem
Parameters:
value - The value to send to the device
Throws:
RbxIOException - thrown if the write operation failed

writeValue

public abstract void writeValue(String value)
                         throws RbxIOException
Write the specified value to the device.

Specified by:
writeValue in interface IOItem
Parameters:
value - The value to send to the device
Throws:
RbxIOException - thrown if the write operation failed

writeValue

public abstract void writeValue(Boolean value)
                         throws RbxIOException
Write the specified value to the device.

Specified by:
writeValue in interface IOItem
Parameters:
value - The value to send to the device
Throws:
RbxIOException - thrown if the write operation failed

writeValue

public void writeValue(int[] values)
                throws RbxIOException
Write the specified array of integers to the device. This default implentation will do nothing, must be implemented in class extending from this one.

Specified by:
writeValue in interface IOItem
Parameters:
values - The array of integer values to send to the device
Throws:
RbxIOException - thrown if the write operation failed

writeValue

public void writeValue(float[] values)
                throws RbxIOException
Write the specified array of floats to the device. This default implentation will do nothing, must be implemented in class extending from this one.

Specified by:
writeValue in interface IOItem
Parameters:
values - The array of float values to send to the device
Throws:
RbxIOException - thrown if the write operation failed

writeValue

public void writeValue(double[] values)
                throws RbxIOException
Write the specified array of doubles to the device. This default implentation will do nothing, must be implemented in class extending from this one.

Specified by:
writeValue in interface IOItem
Parameters:
values - The array of double values to send to the device
Throws:
RbxIOException - thrown if the write operation failed

writeValue

public void writeValue(boolean[] values)
                throws RbxIOException
Write the specified array of booleans to the device. This default implentation will do nothing, must be implemented in class extending from this one.

Specified by:
writeValue in interface IOItem
Parameters:
values - The array of boolean values to send to the device
Throws:
RbxIOException - thrown if the write operation failed

getActionCommand

public String getActionCommand()
Returns the command name associated with this item. This allows users to assign logical names to Items

Specified by:
getActionCommand in interface IOItem
Returns:
any String including the null object

setActionCommand

public void setActionCommand(String aCmd)
Set the command name associated with this item. This allows users to assign logical names to Items

Specified by:
setActionCommand in interface IOItem
Parameters:
aCmd - any users defined string including null

getDataType

public int getDataType()
Describes the data type of the value associated with this event. The value returned is any of the values DATATYPE_INT etc. also defined in this interface

Specified by:
getDataType in interface IOItem
Returns:
any of the values DATATYPE_INT etc. also defined in this interface

setOldValue

public void setOldValue(Object oldValue)
The DefaultIOGroup class will call this method when a value has been read with the readValue() method. This method must be called in order to allow the IOGroup object to notify IOListeners about changes in a monitored item value

Parameters:
oldValue - last read value for this item. The Object type must correspond to the dataType of this item.
See Also:
IOItem.DATATYPE_INT

getOldValue

public Object getOldValue()
Last value read from the device - can be used to efficiently read an an item value when fired in an IOListener onDataChanged() event. The value returned is returned from an internal cache rather than reading from the device which in some instance may be rather time consuming

Specified by:
getOldValue in interface IOItem
Returns:
last read value for this item. The Object type corresponds to the dataType of this item.
See Also:
IOItem.DATATYPE_INT

getOldQuality

public IOQuality getOldQuality()
Returns the quality of the last read value, ie. quality corresponding to the value returned from calling getOldValue() This default implementation will always return good. Subclasses may overwrite for specific implementations

Specified by:
getOldQuality in interface IOItem
Returns:
an implementation of interface IOQuality. Guaranteed never to return null.

isOldQualityGood

public boolean isOldQualityGood()
Returns quality of last read value. Calling this method is more efficient than first calling getOldQuality() and then investigate the returned IOQuality instance, since the implementation need not create an IOQuality instance to determine if the quality is good or not. This default implementation will always return true. Subclasses may overwrite for specific implementations

Specified by:
isOldQualityGood in interface IOItem
Returns:
true if the quality of last read value is "good". For further detail on quality status see IOQuality

toString

public String toString()

isActive

public boolean isActive()
Is the item active - ie. is it automatically being polled

Specified by:
isActive in interface IOItem
Returns:
true if item is active

setDescription

public void setDescription(String text)
Set descriptive text for this item

Specified by:
setDescription in interface IOItem
Parameters:
text - the description. If null then the action command string is returned on calls to getDescription()
See Also:
getDescription()

getDescription

public String getDescription()
Get descriptive text for this item

Specified by:
getDescription in interface IOItem
Returns:
the description. If descriptive text has not been specified the current value of the action command is returned
See Also:
setDescription(java.lang.String)

getUserObject

public Object getUserObject()
Returns a user object that may optionally having been assigned to this IOItem. The user object may be used for eg. storing ImageIcons or additional descriptive text.

Specified by:
getUserObject in interface IOItem
Returns:
optional user object
See Also:
setUserObject(java.lang.Object)

setUserObject

public void setUserObject(Object o)
Set optional user object associated with this IOItem. The user object may be used for eg. storing ImageIcons or additional descriptive text.

Specified by:
setUserObject in interface IOItem
Parameters:
o - the Object to associate with this item