OPC新手求助
/// <summary>
/// 创建组
/// </summary>
private bool CreateGroup()
{
try
{
KepGroups = KepServer.OPCGroups;
KepGroup = KepGroups.Add("OPCDOTNETGROUP");
SetGroupProperty();
KepGroup.DataChange += new DIOPCGroupEvent_DataChangeEventHandler(KepGroup_DataChange);
KepGroup.AsyncWriteComplete += new DIOPCGroupEvent_AsyncWriteCompleteEventHandler(KepGroup_AsyncWriteComplete);
KepItems = KepGroup.OPCItems;
}
catch (Exception err)
{
MessageBox.Show("创建组出现错误:"+err.Message,"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return false;
}
return true;
}
/// <summary>
/// 设置组属性
/// </summary>
private void SetGroupProperty()
{
KepServer.OPCGroups.DefaultGroupIsActive =Convert.ToBoolean(txtGroupIsActive.Text);
KepServer.OPCGroups.DefaultGroupDeadband = Convert.ToInt32(txtGroupDeadband.Text);
KepGroup.UpdateRate = Convert.ToInt32(txtUpdateRate.Text);
KepGroup.IsActive = Convert.ToBoolean(txtIsActive.Text);
KepGroup.IsSubscribed =Convert.ToBoolean(txtIsSubscribed.Text);
}
/// <summary>
/// 列出OPC服务器中所有节点
/// </summary>
/// <param name="oPCBrowser"></param>
private void RecurBrowse(OPCBrowser oPCBrowser)
{
//展开分支
oPCBrowser.ShowBranches();
//展开叶子
oPCBrowser.ShowLeafs(true);
int i = 0;
foreach (object turn in oPCBrowser)
{
listBox1.Items.Add(turn.ToString());
}
}
------------------------------------------------------------------------------------------
第一次接触OPC,想把所有的点,也就是listBox1所有的Item值都添加到Group里,然后每隔30秒刷新一次,把得到的值存到文本文件中。现在不知道怎么把Item值都添加Group里,还有怎么刷新。求高手指点!!!