Ejemplo n.º 1
0
        /// <summary>
        /// 添加状态点到ItemPoints
        /// </summary>
        /// <param name="point"></param>
        public IResult AddItem(ILE.IDataPoint point)
        {
            //此处把配置文件中的数据点名拆出来,放进模型
            string[] pms = point.parameter.Split(',');
            point.Item_name = pms[2];

            ILE.LEResult res = new LEResult();
            try
            {
                HaiGrang.Package.OpcNetApiChs.DaNet.RefreshEventHandler reh = new HaiGrang.Package.OpcNetApiChs.DaNet.RefreshEventHandler(this.DataChangeHandler);
                myRefreshGroup = new RefreshGroup(server, 500, reh);

                mySyncIOGroup = new SyncIOGroup(this.server);

                int i = myRefreshGroup.Add(point.Item_name);
                if (!HRESULTS.Succeeded(i))
                {
                    res.Result     = false;
                    res.ExtMessage = "新增监测点[" + point.dataPoint_name + "]失败";
                    this.server.Disconnect();
                    this.server = null;
                    return(res);
                }
                myRefreshGroup.Remove(point.Item_name);  //如果成功添加了,说明数据点可用,此时要拿出来,不能直接启动数据点。

                this.ItemPoints.Add(point);
                res.Result = true;
            }
            catch (Exception exc)
            {
                res.Result     = false;
                res.ExtMessage = "新增监测点失败";
            }
            return(res);
        }
Ejemplo n.º 2
0
 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);
     }
 }
Ejemplo n.º 3
0
 public void Dispose()
 {
     if (this.SioGrp != null)
     {
         this.SioGrp.Dispose();
         SioGrp = null;
     }
 }
Ejemplo n.º 4
0
 //--------------------------------------------------
 // Constructor
 public OpcThread(OpcServer srv)
 {
     OpcSrv       = srv;
     SioGrp       = OpcSrv.AddSyncIOGroup();
     Requests     = new RequestQueue();
     AccessThread = new Thread(new ThreadStart(OpcAccessThread));
     AccessThread.Start();
 }
Ejemplo n.º 5
0
 //--------------------------------------------------
 // Constructor
 public OpcThread(OpcServer srv)
 {
     // ParentForm = pForm;
     OpcSrv = srv;
     SioGrp = OpcSrv.AddSyncIOGroup();
     //Requests = new RequestQueue();
     //AccessThread = new Thread(new ThreadStart(OpcAccessThread));
     //AccessThread.Start();
 }
Ejemplo n.º 6
0
        public void Stop()
        {
            if (SioGrp == null)
            {
                return;
            }

            SioGrp.Dispose();
            SioGrp = null;
        }
Ejemplo n.º 7
0
 public OpcThreadImp(OpcServer srv)
 {
     try
     {
         OpcSrv = srv;
         SioGrp = OpcSrv.AddSyncIOGroup();
     }
     catch (Exception errmsg)
     {
     }
 }
Ejemplo n.º 8
0
        //---------------------------------------------------------------
        // Queue OPC server access request
        public void Stop()
        {
            if (SioGrp == null)
            {
                return;
            }

            // terminate the server access thread
            StopThread = new ManualResetEvent(false);
            StopThread.WaitOne(5000, true);
            StopThread.Close();
            StopThread = null;

            SioGrp.Dispose();
            SioGrp = null;
            OpcSrv.Disconnect();
        }
Ejemplo n.º 9
0
 /// <summary>
 /// This function adds all tag items provided to it.
 /// </summary>
 /// <param name="items"></param>
 private void AddRead(string[] items)
 {
     try
     {
         if (OpcSrver != null)
         {
             readGroup = new SyncIOGroup(OpcSrver);
             // Add all provided items to ReadWrite Group
             for (int i = 0; i < items.Length; i++)
             {
                 readGroup.Add(items[i]);
             }
         }
     }
     catch (Exception ex)
     {
         //       hf.LogException("Unable to add item: " + ex.ToString());
     }
 }
Ejemplo n.º 10
0
        public string conectar()
        {
            //variável auxiliar que será retornada
            string  aux  = "";
            Boolean erro = false;

            //conexão com o Servidor OPC;
            Srv = new OpcServer();
            int rtc      = Srv.Connect("HITecnologia.SOS.DA.1");
            int localeID = Srv.GetLocaleID(out localeID);

            if (HRESULTS.Failed(rtc))
            {
                aux  = "Erro na conexão: ";
                erro = true;
            }
            else
            {
                aux = "Conectado com Sucesso. LocaleId=" + localeID;
            }
            if (!erro)
            {
                srwGroup = new SyncIOGroup(Srv);
                OPCItemState resultadoLeitura;
                int          auxRtc;
                auxRtc = srwGroup.Read(OPCDATASOURCE.OPC_DS_DEVICE, "Server_2.Driver_1000.DEV255.state", out resultadoLeitura);

                if (HRESULTS.Failed(auxRtc))
                {
                    aux = "Erro na Leitura: " + resultado(auxRtc);
                }
                else
                {
                    aux = resultadoLeitura.DataValue.ToString();
                }
            }


            return(aux);
        }