dk.opi.io.opc.opcclient
Class OpcGroup

java.lang.Object
  extended bydk.opi.io.DefaultIOGroup
      extended bydk.opi.io.opc.opcclient.OpcGroup
All Implemented Interfaces:
IOGroup

public class OpcGroup
extends DefaultIOGroup

This class implements functionality related to groups. Groups are containers for OpcItems. This class has no public constructor - use the OpcClientApi.addGroup() method to create instances of this class.

See Also:
OpcClientApi.addGroup(java.lang.String, boolean, int, float)

Field Summary
 
Fields inherited from class dk.opi.io.DefaultIOGroup
active, description, ioListeners, items, name, updateRate
 
Method Summary
 OpcItem addItem(String itemId, String accessPath, boolean active, int dataType, String actionCmd)
          Add an item to this group.
 OpcItem addItem(String itemId, String accessPath, boolean active, int dataType, String actionCmd, String descr)
          Add an item to this group.
 void fireAllItems(IOListener iol, boolean performRead, int dataSource)
          Use this method to manually fire a IOListener.onValueChanged(dk.opi.io.IOItem) notification to the specified IOListener.
 void readAllItems(int dataSource)
          Read the item value for all items in this group.
 void removeItem(IOItem ioi)
          Remove an item from this group
 void setActive(boolean b)
          Turn off/on automatical updating from the IOItems in this group depending on the value of b.
 
Methods inherited from class dk.opi.io.DefaultIOGroup
addIOListener, addItem, finalize, fireAllItems, fireAllItems, fireIOListenerOnValueChanged, getDescription, getItem, getItems, getName, getUpdateRate, isActive, removeIOListener, setDescription
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addItem

public OpcItem addItem(String itemId,
                       String accessPath,
                       boolean active,
                       int dataType,
                       String actionCmd)
                throws RbxIOException
Add an item to this group. An item represents an input/output variable (tag) in the device(s) monitored by the OPC server. The description of the item is set to the same value as the itemId

Parameters:
itemId - name or id of the item. Does not have to be be unique within group
accessPath - The AccessPath is intended as a way for the client to provide to the server a suggested data path (e.g. a particular modem or network interface). It indicates HOW to get the data.
The ITEM ID provides all of the information needed to locate and process a data item. The Access Path is an optional piece of information that can be provided by the client.
Its use is highly server specific but it is intended to allow the client to provide a 'recommendation' to the server regarding how to get to the data. As an analogy, if the item id represented a phone number, the access path might represent a request to route the call via satellite (or transatlantic cable or microwave link). The call will go through regardless of whether you specify an access path and also whether or not the server is able to use that suggested path.
For example, suppose you wanted to access a value in an RTU and had a high speed modem on COM1 and a low speed modem on COM2. You might specify COM1 as the preferred access path. Either one will work, but you would prefer to use COM1 if it is available for better performance.
In any case, the use of access path by both the server and the client is optional. Servers need not provide the function and clients need not use it even if it is provided.
Servers which do not support access paths will completely ignore any passed access path (and will not treat this as an error by the client). Also, when queried, such servers will always return a null access path for all items. the access path the server should associate with this item. By convention a value of null specifies that the server should select the access path.
active - if items in this group are going to be monitored
actionCmd - a String allowing users to assign logical names to Items
Returns:
OpcItem object which should be used when reading or writing from/to the item
Throws:
RbxIOException

addItem

public OpcItem addItem(String itemId,
                       String accessPath,
                       boolean active,
                       int dataType,
                       String actionCmd,
                       String descr)
                throws RbxIOException
Add an item to this group. An item represents an input/output variable (tag) in the device(s) monitored by the OPC server

Parameters:
itemId - name or id of the item. Does not have to be be unique within group
accessPath - The AccessPath is intended as a way for the client to provide to the server a suggested data path (e.g. a particular modem or network interface). It indicates HOW to get the data.
The ITEM ID provides all of the information needed to locate and process a data item. The Access Path is an optional piece of information that can be provided by the client.
Its use is highly server specific but it is intended to allow the client to provide a 'recommendation' to the server regarding how to get to the data. As an analogy, if the item id represented a phone number, the access path might represent a request to route the call via satellite (or transatlantic cable or microwave link). The call will go through regardless of whether you specify an access path and also whether or not the server is able to use that suggested path.
For example, suppose you wanted to access a value in an RTU and had a high speed modem on COM1 and a low speed modem on COM2. You might specify COM1 as the preferred access path. Either one will work, but you would prefer to use COM1 if it is available for better performance.
In any case, the use of access path by both the server and the client is optional. Servers need not provide the function and clients need not use it even if it is provided.
Servers which do not support access paths will completely ignore any passed access path (and will not treat this as an error by the client). Also, when queried, such servers will always return a null access path for all items. the access path the server should associate with this item. By convention a value of null specifies that the server should select the access path.
active - if items in this group are going to be monitored
actionCmd - a String allowing users to assign logical names to Items
descr - description of the item. Can be queried by a call to
Returns:
OpcItem object which should be used when reading or writing from/to the item IOItem.getDescription()
Throws:
RbxIOException

removeItem

public void removeItem(IOItem ioi)
                throws RbxIOException
Remove an item from this group

Specified by:
removeItem in interface IOGroup
Overrides:
removeItem in class DefaultIOGroup
Parameters:
ioi - The item to remove
Throws:
RbxIOException - thrown if it was not possible to remove the specified item, for instance if the specified item is not a member of this group.

setActive

public void setActive(boolean b)
Turn off/on automatical updating from the IOItems in this group depending on the value of b. Overwrites ditto method in class DefaultIOGroup

Specified by:
setActive in interface IOGroup
Overrides:
setActive in class DefaultIOGroup
Parameters:
b - if true IOItems in this group will fire the valueChanged() event everytime a value is changed

fireAllItems

public void fireAllItems(IOListener iol,
                         boolean performRead,
                         int dataSource)
                  throws RbxIOException
Use this method to manually fire a IOListener.onValueChanged(dk.opi.io.IOItem) notification to the specified IOListener. This method is usefull right after items have been added to the group. A call to this method will initialize your application with the current values.

Specified by:
fireAllItems in interface IOGroup
Overrides:
fireAllItems in class DefaultIOGroup
Parameters:
iol - the listener to notify
performRead - if true a read will be performed for all items in the group prior to firing of the event. In combination with a dataSource value of DEVICE_READ this will ensure that the onValueChanged() is fired with the most recent and up to date value.
dataSource - The source to read from, ie. CACHE_READ or DEVICE_READ. Also see IOItem.readValue(int). Ignored unless performRead is set to true
Throws:
RbxIOException - Will only be thrown if performRead is true and the read operation for some reason fails

readAllItems

public void readAllItems(int dataSource)
                  throws RbxIOException
Read the item value for all items in this group. Item values may subsequently be obtained by a call to getOldValue() on each item. The intended use of this method is to update register values for items, in case the group is intentially set to inactive. In that case the dataSource parameter should always be set to IOItem.DEVICE_READ, in order to read directly from the device
IOListener.onValueChanged(dk.opi.io.IOItem) on registered listeners for the group will be called for changed values. The quality of the item is updated as part of making this call, so make sure that you as part of the IOListener.onValueChanged(dk.opi.io.IOItem) notification is making a check for the quality.
All items are obtained from the OPC server in one read instruction, this is very efficient as well as it ensures that all items are read at the same time.

Specified by:
readAllItems in interface IOGroup
Overrides:
readAllItems in class DefaultIOGroup
Parameters:
dataSource - The source to read from, ie. IOItem.CACHE_READ or IOItem.DEVICE_READ. A CACHE read will obtain the current value for the item from the device server cache (eg. OPC server). This is fast but the value is only updated with the specified update rate, ie. 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 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 one or more read operations failed.