javafish.clients.opc
Class JOpc

java.lang.Object
  extended by javafish.clients.opc.JCustomOpc
      extended by javafish.clients.opc.JOpc
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
JEasyOpc

public class JOpc
extends JCustomOpc
implements java.lang.Runnable

Java OPC class

implements OPCDA standard (2.0, 3.0)

OPC is open connectivity in industrial automation and the enterprise systems that support the industry. Interoperability is assured through the creation and maintenance of non-proprietary open standards specifications.

The first OPC standard specification resulted from the collaboration of a number of leading worldwide automation suppliers working in cooperation with Microsoft. Originally based on Microsoft's OLE COM and DCOM technologies, the specification defined a standard set of objects, interfaces and methods for use in process control and manufacturing automation applications to facilitate interoperability.

The COM/DCOM technologies provided the framework for software products to be developed. There are now hundreds of OPC Data Access servers and clients.

Author:
arnal2@seznam.cz

Constructor Summary
JOpc(java.lang.String host, java.lang.String serverProgID, java.lang.String serverClientHandle)
          Create new instance of OPC Client.
 
Method Summary
 void addGroup(OpcGroup group)
          Add opc group to the client.
 void asynch10Read(OpcGroup group)
          Asynchronous 1.0 reading (AdviseSink) - start
 void asynch10Unadvise(OpcGroup group)
          Asynchronous 1.0 unadvise reading (AdviseSink) - terminate
 void asynch20Read(OpcGroup group)
          Asynchronous 2.0 reading (Callback) - start
 void asynch20Unadvise(OpcGroup group)
          Asynchronous 2.0 unadvise reading (Callback) - terminate
 OpcGroup getDownloadGroup()
          Get downloaded group (clone) from opc-server NOTE: Asynchronous mode, OPC-Queue of downloaded groups, OPCGroup can be NULL.
 OpcGroup getGroupByClientHandle(int clientHandle)
          Get group by its clientHandle identification.
 OpcGroup[] getGroupsAsArray()
          Get opc-groups as array.
 int getNewGroupClientHandle()
          Generate new clientHandle for group (Generation of unique group ID)
 void registerGroup(OpcGroup group)
          Register group to opc-server.
 void registerGroups()
          Register all groups (with items) to opc-server.
 void registerItem(OpcGroup group, OpcItem item)
          Register item (in group) to opc-server.
 void removeGroup(OpcGroup group)
          Remove opc group from the client.
 void run()
           
 void setGroupActivity(OpcGroup group, boolean active)
          Set new activity of group (change active state)
 void setGroupUpdateTime(OpcGroup group, int updateTime)
          Set new updateTime of group (refresh rate)
 void setItemActivity(OpcGroup group, OpcItem item, boolean active)
          Set new activity of item (change active state)
 void start()
          Run OPC-Client thread
 OpcGroup synchReadGroup(OpcGroup group)
          Synchronous reading of group
 OpcItem synchReadItem(OpcGroup group, OpcItem item)
          Synchronous reading of one item in specific group.
 void synchWriteItem(OpcGroup group, OpcItem item)
          Synchronous writing of one item in specific group.
 void unregisterGroup(OpcGroup group)
          Unregister group from opc-server.
 void unregisterGroups()
          Unregister all groups from opc-server (with items).
 void unregisterItem(OpcGroup group, OpcItem item)
          Unregister item (in group) from opc-server.
 void updateGroups()
          Update native groups representation.
 
Methods inherited from class javafish.clients.opc.JCustomOpc
coInitialize, connect, coUninitialize, getFullOpcServerName, getHost, getServerClientHandle, getServerProgID, ping
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JOpc

public JOpc(java.lang.String host,
            java.lang.String serverProgID,
            java.lang.String serverClientHandle)
Create new instance of OPC Client.

Parameters:
host - - host computer
serverProgID - - OPC Server name
serverClientHandle - - user name for OPC Client
Method Detail

getNewGroupClientHandle

public int getNewGroupClientHandle()
Generate new clientHandle for group

(Generation of unique group ID)

Returns:
int clientHandle

addGroup

public void addGroup(OpcGroup group)
Add opc group to the client.

NOTE: GroupExistsException - runtime exception

Parameters:
group - OpcGroup

removeGroup

public void removeGroup(OpcGroup group)
Remove opc group from the client.

NOTE: GroupExistsException - runtime exception

Parameters:
group - OpcGroup

getGroupByClientHandle

public OpcGroup getGroupByClientHandle(int clientHandle)
Get group by its clientHandle identification.

Parameters:
clientHandle - int
Returns:
group OpcGroup

getGroupsAsArray

public OpcGroup[] getGroupsAsArray()
Get opc-groups as array.

Returns:
groups OpcGroup[]

updateGroups

public void updateGroups()
Update native groups representation.


registerGroup

public void registerGroup(OpcGroup group)
                   throws ComponentNotFoundException,
                          UnableAddGroupException
Register group to opc-server.

Parameters:
group - OpcGroup
Throws:
ComponentNotFoundException
UnableAddGroupException

registerItem

public void registerItem(OpcGroup group,
                         OpcItem item)
                  throws ComponentNotFoundException,
                         UnableAddItemException
Register item (in group) to opc-server.

Parameters:
group - OpcGroup
item - OpcItem
Throws:
ComponentNotFoundException
UnableAddItemException

registerGroups

public void registerGroups()
                    throws UnableAddGroupException,
                           UnableAddItemException
Register all groups (with items) to opc-server.

NOTE: It's faster than separate methods registerGroup and registerItem, but you don't know, which item or group causes the registration exception.

Throws:
UnableAddGroupException
UnableAddItemException

unregisterGroup

public void unregisterGroup(OpcGroup group)
                     throws ComponentNotFoundException,
                            UnableRemoveGroupException
Unregister group from opc-server.

Parameters:
group - OpcGroup
Throws:
ComponentNotFoundException
UnableRemoveGroupException

unregisterItem

public void unregisterItem(OpcGroup group,
                           OpcItem item)
                    throws ComponentNotFoundException,
                           UnableRemoveItemException
Unregister item (in group) from opc-server.

Parameters:
group - OpcGroup
item - OpcItem
Throws:
ComponentNotFoundException
UnableRemoveItemException

unregisterGroups

public void unregisterGroups()
                      throws UnableRemoveGroupException
Unregister all groups from opc-server (with items).

NOTE: It's faster than separate methods unregisterGroup and unregisterItem, but you don't know, which group causes the unregistration exception.

Throws:
UnableRemoveGroupException

synchReadItem

public OpcItem synchReadItem(OpcGroup group,
                             OpcItem item)
                      throws ComponentNotFoundException,
                             SynchReadException
Synchronous reading of one item in specific group.

Parameters:
group - OpcGroup
item - OpcItem
Returns:
item OpcItem
Throws:
ComponentNotFoundException
SynchReadException

synchWriteItem

public void synchWriteItem(OpcGroup group,
                           OpcItem item)
                    throws ComponentNotFoundException,
                           SynchWriteException
Synchronous writing of one item in specific group.

Parameters:
group - OpcGroup
item - OpcItem
Throws:
ComponentNotFoundException
SynchWriteException

synchReadGroup

public OpcGroup synchReadGroup(OpcGroup group)
                        throws ComponentNotFoundException,
                               SynchReadException
Synchronous reading of group

Parameters:
group - OpcGroup
Returns:
group with response (clone) OPCGroup
Throws:
ComponentNotFoundException
SynchReadException

asynch10Read

public void asynch10Read(OpcGroup group)
                  throws ComponentNotFoundException,
                         Asynch10ReadException
Asynchronous 1.0 reading (AdviseSink) - start

Parameters:
group - OpcGroup
Throws:
ComponentNotFoundException
Asynch10ReadException

asynch20Read

public void asynch20Read(OpcGroup group)
                  throws ComponentNotFoundException,
                         Asynch20ReadException
Asynchronous 2.0 reading (Callback) - start

Parameters:
group - OpcGroup
Throws:
ComponentNotFoundException
Asynch20ReadException

asynch10Unadvise

public void asynch10Unadvise(OpcGroup group)
                      throws ComponentNotFoundException,
                             Asynch10UnadviseException
Asynchronous 1.0 unadvise reading (AdviseSink) - terminate

Parameters:
group - OpcGroup
Throws:
ComponentNotFoundException
Asynch10UnadviseException

asynch20Unadvise

public void asynch20Unadvise(OpcGroup group)
                      throws ComponentNotFoundException,
                             Asynch20UnadviseException
Asynchronous 2.0 unadvise reading (Callback) - terminate

Parameters:
group - OpcGroup
Throws:
ComponentNotFoundException
Asynch20UnadviseException

getDownloadGroup

public OpcGroup getDownloadGroup()
Get downloaded group (clone) from opc-server

NOTE: Asynchronous mode, OPC-Queue of downloaded groups, OPCGroup can be NULL.

Returns:
group OpcGroup

setGroupUpdateTime

public void setGroupUpdateTime(OpcGroup group,
                               int updateTime)
                        throws ComponentNotFoundException,
                               GroupUpdateTimeException
Set new updateTime of group (refresh rate)

Parameters:
group - OpcGroup
updateTime - int
Throws:
ComponentNotFoundException
GroupUpdateTimeException

setGroupActivity

public void setGroupActivity(OpcGroup group,
                             boolean active)
                      throws ComponentNotFoundException,
                             GroupActivityException
Set new activity of group (change active state)

Parameters:
group - OpcGroup
active - boolean
Throws:
ComponentNotFoundException
GroupActivityException

setItemActivity

public void setItemActivity(OpcGroup group,
                            OpcItem item,
                            boolean active)
                     throws ComponentNotFoundException,
                            ItemActivityException
Set new activity of item (change active state)

Parameters:
group - OpcGroup
item - OpcItem
active - boolean
Throws:
ComponentNotFoundException
ItemActivityException

start

public void start()
Run OPC-Client thread


run

public void run()
Specified by:
run in interface java.lang.Runnable