OPC Data Client - C# - OpcBrowseControl
How do I use the OpcBrowseControl?
{
//create the object
OpcLabs.BaseLib.Forms.Browsing.OpcBrowseControl opcBrowseControl1 = new OpcLabs.EasyOpc.Forms.Browsing.OpcBrowseControl();
//use the Kind property to change the look of the control
opcBrowseControl1.Kind = BrowseControlKinds.Tree;
//opcBrowseControl1.Kind = BrowseControlKinds.TreeAndList;
//opcBrowseControl1.Kind = BrowseControlKinds.List;
//to access information about the currently selected node, we use the InputsOutputs property
//the computer the OPC Server is on
String computer = opcBrowseControl1.InputsOutputs.CurrentNodeDescriptor.ServerDescriptor.MachineName;
//the progID of the OPC Server
String progID = opcBrowseControl1.InputsOutputs.CurrentNodeDescriptor.ServerDescriptor.ProgId;
//the name of the tag
String itemID = opcBrowseControl1.InputsOutputs.CurrentNodeDescriptor.DANodeDescriptor.ItemId;
//now let's use the EasyDAClient to read the currently selected node
OpcLabs.EasyOpc.DataAccess.EasyDAClient easyDAClient1 = new OpcLabs.EasyOpc.DataAccess.EasyDAClient();
try
{
//read the item and display the value in a MessageBox
//pass in the computer, progID, and tag to read
OpcLabs.EasyOpc.DataAccess.DAVtq result = easyDAClient1.ReadItem(computer,progID, itemID);
MessageBox.Show(result.DisplayValue());
}
catch (Exception ex)//if we try to read something that is not an opc item, or the read fails, display a message
{
MessageBox.Show(ex.Message);
}
}