public bool Start() { try { bool bRet = InitOPCService(); if (!bRet) { return(false); } if (null == opcSerNodes || null == allOPCItemNodes) { NLogHelper.DefalutError("OPCBUSService.Start error,未配置opc服务"); return(false); } opcSer.Connect(host, guid); syncIOGroup = new SyncIOGroup(opcSer); refreshEventHandler = new RefreshEventHandler(RefreshEvent); refreshGroup = new RefreshGroup(opcSer, 10, refreshEventHandler); foreach (DriveNodeEntity item in allOPCItemNodes) { int iRet = refreshGroup.Add(item.nodeName); if (HRESULTS.Succeeded(iRet)) { Console.WriteLine(" true " + iRet); } } return(true); } catch (Exception ex) { NLogHelper.ExceptionInfo(ex, "Start StartOPCService exception: {0}", ex.Message); return(false); } }
private bool InitOPCService() { try { int iRet = OPCHelper.GetOpcAllItemByNodeRoot(opcSerNodes, out allOPCItemNodes); if (0 != iRet) { NLogHelper.DefalutError("GetOpcAllItemByNodeRoot 获取opc服务设备项失败:{0}", iRet.ToString()); return(false); } host = new Host(opcSerNodes.serviceIp); opcSer = new OpcServer(); guid = new Guid(opcSerNodes.nodeStrGuid); return(true); } catch (Exception ex) { NLogHelper.ExceptionInfo(ex, "InitOPCService exception: {0}", ex.Message); } return(false); }