Exemple #1
0
        // Commands //

        public void Connect(string psOpcServerName, string psPlcAlias, int piWatchTime)
        {
            if (this.mConnectionState == TState.DISCONNECTED)
            {
                this.ChangeConnectionState(TState.CONNECTING);
                this.sOPCServerName = psOpcServerName;
                this.sPLCAlias      = psPlcAlias;
                this.iWatchTime     = piWatchTime;
                try
                {
                    //Thread.Sleep(2000); // for debugging without OFS

                    mOPCGroup = new SAOFSGroupXClass();
                    mOPCGroup.Init(this.sOPCServerName, "");
                    this.mAddAllItems();
                    mOPCGroup.OnDataChange += new _ISAOPCGrpXCallback_OnDataChangeEventHandler(mOPCGroup_OnOpcDataChange);
                    mOPCGroup.Start(piWatchTime);

                    this.ChangeConnectionState(TState.CONNECTED);
                }
                catch (Exception ex)
                {
                    ManageErrorConnection(ex.Message);
                }
            }
        }
Exemple #2
0
 public void Disconnect()
 {
     if ((this.mConnectionState == TState.CONNECTED) || (this.mConnectionState == TState.CONNECTING))
     {
         try
         {
             mOPCGroup.Stop();
         }
         catch { }
         if (mOPCGroup != null)
         {
             System.Runtime.InteropServices.Marshal.ReleaseComObject(mOPCGroup);
         }
         mOPCGroup           = null;
         this.sOPCServerName = null;
         this.sPLCAlias      = null;
         this.ChangeConnectionState(TState.DISCONNECTED);
     }
 }