引用OPCAutomation,网上找的OPC客户端的例子,代码如下
OPCServer ObjOPCServer;
OPCGroups ObjOPCGroups;
OPCGroup ObjOPCGroup;
string OPCServerName;
public Form1()
{
try
{
InitializeComponent();
OPCServerName = "KingView.View.1";
ObjOPCServer = new OPCServer();
ObjOPCServer.Connect(OPCServerName, "192.168.43.216");
ObjOPCGroups = ObjOPCServer.OPCGroups;
ObjOPCGroup = ObjOPCGroups.Add("OPCGroup1");
ObjOPCGroup.DataChange += new DIOPCGroupEvent_DataChangeEventHandler(ObjOPCGroup_DataChange);
ObjOPCGroup.OPCItems.AddItem("$Second.Value", 1);
ObjOPCGroup.IsActive = true;
ObjOPCGroup.UpdateRate = 1000;
ObjOPCGroup.IsSubscribed = true;
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
textBox1.Text = e.ToString();
}
}
程序运行至 ObjOPCGroup.IsSubscribed = true; 时报如下错误,请教各位大神,该如何解决?
System.Runtime.InteropServices.COMException (0x80010105): 服务器出现意外情况。 (异常来自 HRESULT:0x80010105 (RPC_E_SERVERFAULT))
在 OPCAutomation.OPCGroupClass.set_IsSubscribed(Boolean IsSubscribed)