andrecosta

Error: "Unable to obtain parent server of PIPoint"

Discussion created by andrecosta on Oct 24, 2012
Latest reply on Nov 5, 2012 by Ahmad Fattahi

 

 

Hi,

 

I’m trying to develop a Java application to access PI data via PI-SDK. I used COM4J to generate the Java interfaces for PI-SDK DLLs and most of the code is working fine except for one thing: Sometimes (1% of executions) when I try to query some points based on a criteria I got the following error:

 

“-2147220126 - Unable to obtain parent server of PIPoint”

 

The weird part is that, for the same criteria, most of the times I got the correct result and sometimes I got the csCompleteWithErrors.

 

 

 

 

 
public List queryTags(String server, String criteria) {
    List result = new ArrayList();
    Server piServer = null;
    try {
        IPISDK piSDK = ClassFactory.createPISDK(); //COM4J generated bind
        Servers servers = piSDK.servers();
        Server piServer = servers.item(serverName);
        piServer.open("ServerRole=Any");            
        _PIAsynchStatus asynchStatus = ClassFactory.createPIAsynchStatus();
        String clause = "Tag = '" + criteria + "' OR Descriptor='" + criteria + "'";
        _PointList pointList = piServer.getPoints(clause, asynchStatus);
        while (asynchStatus.status() == CallStatusConstants.csInitial || asynchStatus.status() == CallStatusConstants.csInProgress) {
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) { }
        }
        int size = pointList.count();
        if (size == 0 && asynchStatus.status() == CallStatusConstants.csCompleteWithErrors) {
            
            LOG.info("No results for:" 
                    + criteria
                    + "(" + asynchStatus.status().name() + 
                    ") Connected:"
                    + piServer.connected());
            _PIError pierror = ((Com4jObject)asynchStatus.result()).queryInterface(_PIError.class);
            LOG.info("Error:" 
                    + pierror.number() 
                    + "-" + pierror.description());
        }
        for (int i = 1; i <= size; i++) {
            PIPoint point = pointList.item(i);
            String tagName = point.name();
            String desc = point.pointAttributes("descriptor").value().toString();
            String uom = point.pointAttributes("engunits").value().toString();
            Tag tag = new Tag();
            tag.setName(tagName);
            tag.setServer(server);
            tag.setDescriptor(desc);
            tag.setUOM(uom);
            result.add(tag);
        }
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
    } finally {
        if (piServer != null && piServer.connected()) {
        piServer.close();
        }
    }
    return result;
}

 

 

 

 

 

 

 

Outcomes