コード例 #1
0
        protected virtual void                          Dispose(bool aDisposing)
        {
            if (!mDisposed)
            {
                if (aDisposing)
                {
                    SimulationRuntimeManager.OnRunTimemanagerLost -= onConnectionLost;

                    mItemList.Clear();
                    mItemRWList.Clear();
                    mSDataValue = null;

                    if (mTagBrowserForm != null)
                    {
                        mTagBrowserForm.Dispose();
                        mTagBrowserForm = null;
                    }

                    if (mItemListLock != null)
                    {
                        mItemListLock.Dispose();
                        mItemListLock = null;
                    }

                    if (mMainCycleTimer != null)
                    {
                        mMainCycleTimer.Dispose();
                        mMainCycleTimer = null;
                    }

                    if (mDisconnectEvent != null)
                    {
                        mDisconnectEvent.Dispose();
                        mDisconnectEvent = null;
                    }

                    if (mPLC != null)
                    {
                        mPLC.OnConfigurationChanged  -= onConfigurationChanged;
                        mPLC.OnConfigurationChanging -= onConfigurationChanging;
                        mPLC.Dispose();
                        mPLC = null;
                    }

                    if (mRRManager != null)
                    {
                        mRRManager.OnConnectionLost -= onRemoteConnectionLost;
                        mRRManager.Disconnect();
                        mRRManager.Dispose();
                        mRRManager = null;
                    }
                }

                mDisposed = true;
            }
        }
コード例 #2
0
        public void                                         connect()
        {
            if (mTagBrowserForm != null)
            {
                mTagBrowserForm.Dispose();
                mTagBrowserForm = null;
            }

            if (mPLC != null)
            {
                mPLC.OnConfigurationChanged  -= onConfigurationChanged;
                mPLC.OnConfigurationChanging -= onConfigurationChanging;
                mPLC.Dispose();
                mPLC = null;
            }

            if (mRRManager != null)
            {
                mRRManager.OnConnectionLost -= onRemoteConnectionLost;
                mRRManager.Disconnect();
                mRRManager.Dispose();
                mRRManager = null;
            }

            if (String.IsNullOrWhiteSpace(mPLCName))
            {
                throw new InvalidOperationException("PLC name is empty. ");
            }

            if (mRemote)
            {
                var lConnectionStr = mIP + ":" + mIPPort.ToString();
                if (String.IsNullOrWhiteSpace(lConnectionStr))
                {
                    throw new InvalidOperationException("Connection string is empty. ");
                }

                try
                {
                    mRRManager = SimulationRuntimeManager.RemoteConnect(lConnectionStr);
                }
                catch (SimulationRuntimeException lExc)
                {
                    throw new InvalidOperationException("Connection '" + lConnectionStr + "'. " + ErrorCodeMessage(lExc.RuntimeErrorCode), lExc);
                }

                try
                {
                    mPLC = mRRManager.CreateInterface(mPLCName);
                }
                catch (SimulationRuntimeException lExc)
                {
                    mRRManager.Dispose();
                    mRRManager = null;

                    throw new InvalidOperationException("PLC instance '" + mPLCName + "'. " + ErrorCodeMessage(lExc.RuntimeErrorCode), lExc);
                }

                mRRManager.OnConnectionLost += onRemoteConnectionLost;
            }
            else
            {
                try
                {
                    mPLC = SimulationRuntimeManager.CreateInterface(mPLCName);
                }
                catch (SimulationRuntimeException lExc)
                {
                    throw new InvalidOperationException("PLC instance '" + mPLCName + "'. " + ErrorCodeMessage(lExc.RuntimeErrorCode), lExc);
                }
            }

            if (mMainCycleTimer == null)
            {
                mMainCycleTimer           = new System.Timers.Timer(MiscUtils.TimeSlice);
                mMainCycleTimer.Elapsed  += new ElapsedEventHandler(MainCycle);
                mMainCycleTimer.AutoReset = false;
            }

            mPLC.UpdateTagList();

            mPLC.OnConfigurationChanged  += onConfigurationChanged;
            mPLC.OnConfigurationChanging += onConfigurationChanging;

            mConnected     = true;
            mDisconnect    = false;
            mReconnect     = false;
            mWriteRequests = 0;
            mMainCycleTimer.Start();
            raiseConnectionState();
        }