Skip to content

Commit

Permalink
DA: fix dispose method and improve diagnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
itajaja committed Mar 23, 2015
1 parent 55a5316 commit a10f0b7
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions h-opc/Da/DaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public T Read<T>(string tag)
var item = new OpcDa.Item { ItemName = tag };
var result = _server.Read(new[] { item })[0];

CheckResult(result);
CheckResult(result, tag);

return (T)result.Value;
}
Expand All @@ -96,7 +96,7 @@ public void Write<T>(string tag, T item)
Value = item
};
var result = _server.Write(new[] { itmVal })[0];
CheckResult(result);
CheckResult(result, tag);
}

/// <summary>
Expand Down Expand Up @@ -143,7 +143,7 @@ public DaNode FindNode(string tag)
// try to find the tag otherwise
var item = new OpcDa.Item { ItemName = tag };
var result = _server.Read(new[] { item })[0];
CheckResult(result);
CheckResult(result, tag);
var node = new DaNode(this, item.ItemName, item.ItemName, RootNode);
AddNodeToCache(node);
return node;
Expand Down Expand Up @@ -179,7 +179,6 @@ public IEnumerable<DaNode> ExploreFolder(string tag)
/// </summary>
public void Dispose()
{
_server.Disconnect();
_server.Dispose();
GC.SuppressFinalize(this);
}
Expand All @@ -196,12 +195,12 @@ private void AddNodeToCache(DaNode node)
_nodesCache.Add(node.Tag, node);
}

private static void CheckResult(IResult result)
private static void CheckResult(IResult result, string tag)
{
if (result == null)
throw new OpcException("The server replied with an empty response");
if (result.ResultID.ToString() != "S_OK")
throw new OpcException(string.Format("Invalid response from the server. (Response Status: {0})", result.ResultID));
throw new OpcException(string.Format("Invalid response from the server. (Response Status: {0}, Opc Tag: {1})", result.ResultID, tag));
}
}
}

0 comments on commit a10f0b7

Please sign in to comment.