Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Help please.....!!!!!!!!! Java 1.4 and OPC Server issue...?

843810Sep 12 2008 — edited Sep 12 2008
hello everyone,

i m creating a Desktop Application using the Javafish API which connects to the OPC Server and reads data from it.
i stuck in a problem.
The problem is as follows:
i added the functionality to delete and add groups and items. For reading successfully from the server it is necessary that the groups and items should be registered. without deleting any thing if i start reading it works fine. But if i delete the group and re add the group by the same name it throws an exception that Unable to add group to the OPC Server.
the code is as follows please help me out


public void deleteItemFromTree()
{
DefaultMutableTreeNode nodeSelected = DefaultMutableTreeNode)GroupsDisplayPanel.this.componentTree.getLastSelectedPathComponent();
String selectedNode = nodeSelected.toString();
ArrayList updatedGroupList = null;
ArrayList itemList = null;
ListIterator groupIterator = null;
OpcGroup group = null;
this.treeModel.removeNodeFromParent(nodeSelected);
if(this.model.isDeleteFlag()&& this.model.getGroupList()!= null)
{
updatedGroupList = this.model.getGroupList();
groupIterator = updatedGroupList.listIterator();

outer: while(groupIterator.hasNext())
{
group = (OpcGroup)groupIterator.next();
itemList = group.getItems();
int groupIndex = updatedGroupList.indexOf(group);

// System.out.println(groupIndex);

if(selectedNode.equals(group.getGroupName()))
{
this.unregisterGroupsAndItems(group);
this.removeGroupsFromRegisteredGroups(group);
itemList.clear();
updatedGroupList.remove(group);
this.deleteGroupsFromOpcServer(group);
this.model.setRegisterFlag(true);
// this.model.setRegisterItemFlag(true);
this.model.getTargetNode().remove(groupIndex);
this.model.setGroupList(updatedGroupList);
this.model.setDeleteFlag(false);
break outer;
}
else if(itemList != null)
{
this.deleteItemFromGroup(group,itemList,selectedNode);
}
}
}
}

/**
* delete the particular item from the group
* @param group
* @param itemList
* @param selectedNode
*/
public void deleteItemFromGroup(OpcGroup group,ArrayList itemList, String selectedNode)
{
ListIterator itemIterator = itemList.listIterator();

loop: while(itemIterator.hasNext())
{
OpcItem item = (OpcItem)itemIterator.next();
//F1VI.PLC.F1VI01_RQ_VAR3_Name
if(selectedNode.equals(item.getItemName()))
{
group.removeItem(item);
this.model.getJopcInstance().updateGroups();
this.model.setDeleteFlag(false);
break loop;
}
}
}

public void deleteGroupsFromOpcServer(OpcGroup group)
{
if(!this.model.isCreateGroupFlag())
{
this.model.getJopcInstance().removeGroup(group);
}
}

public void removeGroupsFromRegisteredGroups(OpcGroup group)
{
if(this.model.isStopFlag())
{
group.getItems().clear();
this.model.getRegisteredGroups().remove(group);
}
}

public void unregisterGroupsAndItems(OpcGroup group)
{
ListIterator iterator = group.getItems().listIterator();

try
{
this.model.getJopcInstance().unregisterGroup(group);
this.model.getJopcInstance().updateGroups();
}
catch (ComponentNotFoundException e)
{
e.printStackTrace();
}
catch (UnableRemoveGroupException e)
{
e.printStackTrace();
}

while(iterator.hasNext())
{
try
{
this.model.getJopcInstance().unregisterItem(group, (OpcItem)iterator.next());
this.model.getJopcInstance().updateGroups();
}
catch (ComponentNotFoundException e)
{
e.printStackTrace();
}
catch (UnableRemoveItemException e)
{
e.printStackTrace();
}
}

}


The code for the registering groups is like this:-

ListIterator groupIterator = this.groupList.listIterator();
this.model.getJopcInstance().updateGroups();
if(this.model.isRegisterFlag())
{
try
{
outer:while(groupIterator.hasNext())
{
this.opcGroup = (OpcGroup)groupIterator.next();
if(this.checkFlag)
{
ListIterator registeredGroupIterator = this.registeredGroups.listIterator();
while(registeredGroupIterator.hasNext())
{
OpcGroup registeredGroup = (OpcGroup)registeredGroupIterator.next();
if((this.opcGroup.getGroupName().equals(registeredGroup.getGroupName())))
{
continue outer;
}
}
System.out.println("Add Group "+this.model.getJopcInstance().getGroupsAsArray().length);
this.model.getJopcInstance().addGroup(this.opcGroup);
System.out.println("Add Group "+this.model.getJopcInstance().getGroupsAsArray().length);
this.model.getJopcInstance().registerGroup(this.opcGroup); ********
this.model.getRegisteredGroups().add(this.opcGroup);
System.out.println("after stop Registered Groups"+this.opcGroup.getGroupName());
this.registeredGroups = this.model.getRegisteredGroups();
}
if(!(this.checkFlag))
{
this.model.getJopcInstance().registerGroup(this.opcGroup);
this.model.getRegisteredGroups().add(this.opcGroup);
System.out.println("Else Registered Groups");
}
}
this.model.setCheckFlag(true);
this.model.setRegisterFlag(false);
System.out.println("Registered Groups");
}
catch(ComponentNotFoundException e)
{
e.printStackTrace();
this.registerGroupsAndItemsParentHandle.showErrorMessage();
this.model.setReadFlag(false);
}
catch(UnableAddGroupException e)
{
e.printStackTrace();
this.registerGroupsAndItemsParentHandle.showErrorMessage();
this.model.setReadFlag(false);
}
}

the exceptions is thrown at the line indicated by line marked bold....

the exception is as follows

javafish.clients.opc.exception.UnableAddGroupException: Unable to register group to server: g1
at javafish.clients.opc.JOpc.registerGroup(JOpc.java:247)
at core.register.RegisterGroupAndItems.registerClientGroups(RegisterGroupAndItems.java:73)
at core.register.RegisterGroupAndItems.<init>(RegisterGroupAndItems.java:43)
at application.componentsdisplay.toolbar.ToolBar.startButtonActionPerformed(ToolBar.java:195)
at application.componentsdisplay.toolbar.ToolBar$3.actionPerformed(ToolBar.java:103)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)


Can any one help me out of this problem.

Edited by: Akhilesh_Sharma on Sep 12, 2008 9:03 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 10 2008
Added on Sep 12 2008
0 comments
371 views