View Issue Details

IDProjectCategoryView StatusLast Update
0000116.NET APIImplementation Bugpublic2008-05-10 08:50
ReporterSimon Guard Assigned ToRandy Armstrong  
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Summary0000116: HDA.NET Browser does not report branch as having children if GetItemID fails.
Description

This may not be a bug if I have not implemented IOPCHDA_Browser::GetItemID properly.

In my implementation of IOPCHDA_Browser::GetItemID I return E_FAIL if a 'pure' branch is provided for szNode. If this behaviour is wrong then this is not a bug.

The problem I have is that BrowseElement.HasChildren is not being set for branches when GetItemID returns E_FAIL. The following code is the problem:

OpcCom.Hda.Browser.cs: line 345

// create new element objects.
foreach (string name in names)
{
BrowseElement element = new BrowseElement();

element.Name   = name;
// lookup item id for element.
try
{
    string itemID = null;
    m_browser.GetItemID(name, out itemID);

    element.ItemName    = itemID;
    element.ItemPath    = null;
    element.HasChildren = isBranch; //<-- not set if GetItemID fails
}
catch
{
    // ignore errors.
}

elements.Add(element);

}

I think the correct behaviour should be to set 'element.HasChildren = isBranch' regardless of whether GetItemId fails or not (or call m_Browser.GetBranchPosition instead of GetItemId to get the element.ItemName when isBranch is true).

Note that this problem exists in OPC.NET API 1.30 and 2.00.

TagsNo tags attached.

Activities

Simon Guard

2007-02-22 22:25

reporter   ~0000167

Here is a fix that works for me...

/// <summary>
/// Fetches the full branch name for the relative branch name
/// </summary>
private string GetFullBranchName(string name)
{
string branch = null;
try
{
m_browser.ChangeBrowsePosition(OPCHDA_BROWSEDIRECTION.OPCHDA_BROWSE_DOWN, name);
}
catch
{
// if we can't get to the branch then something is wrong
return null;
}
try
{
m_browser.GetBranchPosition(out branch);
}
catch
{
// If something goes wrong then we still need to get back to where we were
}
m_browser.ChangeBrowsePosition(OPCHDA_BROWSEDIRECTION.OPCHDA_BROWSE_UP, "");

return branch;
}

/// <summary>
/// Fetches the element names and item ids for each element.
/// </summary>
private ArrayList FetchElements(EnumString enumerator, int maxElements, bool isBranch)
{
...
// create new element objects.
foreach (string name in names)
{
BrowseElement element = new BrowseElement();

element.Name   = name;
// lookup item id for element.
try
{
  string itemID = null;

  if (isBranch)
  {
    itemID = GetFullBranchName(name);
  }
  else
  {
    m_browser.GetItemID(name, out itemID);
  }

  element.ItemName    = itemID;
  element.ItemPath    = null;
  element.HasChildren = isBranch;
}
catch
{
  // ignore errors.
}

...

Randy Armstrong

2007-02-22 22:57

administrator   ~0000168

Changed code to:

BrowseElement element = new BrowseElement();

element.Name = name;
element.ItemPath = null;
element.HasChildren = isBranch;

try
{
string itemID = null;
m_browser.GetItemID(name, out itemID);
element.ItemName = itemID;
}
catch
{
element.ItemName = null;
}

elements.Add(element);

Randy Armstrong

2008-05-10 08:50

administrator   ~0000697

Will be part of Release 2.00.101

Issue History

Date Modified Username Field Change
2007-02-22 21:35 Simon Guard New Issue
2007-02-22 22:25 Simon Guard Note Added: 0000167
2007-02-22 22:56 Randy Armstrong Status new => assigned
2007-02-22 22:56 Randy Armstrong Assigned To => Randy Armstrong
2007-02-22 22:57 Randy Armstrong Status assigned => resolved
2007-02-22 22:57 Randy Armstrong Resolution open => fixed
2007-02-22 22:57 Randy Armstrong Note Added: 0000168
2007-02-23 03:31 Randy Armstrong Status resolved => acknowledged
2007-02-28 23:24 Randy Armstrong Status acknowledged => confirmed
2008-05-10 08:50 Randy Armstrong Status confirmed => resolved
2008-05-10 08:50 Randy Armstrong Note Added: 0000697