Exemple #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="cpp"></param>
 public void Remove(CommPortProxy cpp)
 {
     cpp.ReceiveAutoReport -= new EventHandler(cpp_ReceiveAutoReport);
     cpp.ReceiveComplete   -= new EventHandler(cpp_ReceiveComplete);
     cpp.WinsockError      -= new WinsockErrorHandler(cpp_WinsockError);
     this.InternalRemove(cpp);
 }
Exemple #2
0
        /// <summary>
        /// 执行Task
        /// </summary>
        /// <param name="commPortProxy">通过哪个串口执行</param>
        public void Execute(CommPortProxy commPortProxy)
        {
            // before execute
            //
            if (m_BeforeExecuteTaskDelegate != null)
            {
                m_BeforeExecuteTaskDelegate(this, EventArgs.Empty);
            }

            // execute
            //
            // 2006.12.13
            //
            //OnExecute( commPortProxy, m_Station, m_CommCmd, m_Parameters );
            OnExecute(commPortProxy, m_CommCmd);

            // update last execute time
            //
            this.LastExecute = DateTime.Now;
            //
            // 2006.12.15 Added update last send command datetime.
            //
            this.m_LastSendDateTime = DateTime.Now;

            // after execute
            //
            if (m_AfterExecuteTaskDelegate != null)
            {
                m_AfterExecuteTaskDelegate(this, EventArgs.Empty);
            }
        }
Exemple #3
0
        /// <summary>
        /// 处理
        /// </summary>
        /// <param name="requestID"></param>
        private void _winsock_ConnectionRequest(int requestID)
        {
            lock ( _lock )
            {
                try
                {
                    Winsock sck = new  WinsockClass();
                    sck.Accept(requestID);
                    //s_sckarray[ _idx ] = sck;

                    CommPortProxy cppsck = new CommPortProxy(sck);
                    //s_cppsckarray[ _idx ] = cppsck;
                    //_idx++;
                    //MessageBox.Show( cppsck.ToString() );

                    if (_log != null)
                    {
                        _log.AddLog(sck.RemoteHostIP);
                    }
                    _lastConnection = cppsck;

                    if (NewConnection != null)
                    {
                        NewConnection(this, System.EventArgs.Empty);
                    }
                }
                catch (Exception ex)
                {
                    Debug.Fail("At _winsock_ConnectionRequest", ex.ToString());
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Error
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void cpp_WinsockError(object sender, WinsockErrorArgs args)
        {
            CommPortProxy cpp = (CommPortProxy)sender;

            if (this.CppsWinsockErrorEvent != null)
            {
                CppsWinsockErrorArgs e = new CppsWinsockErrorArgs(cpp, args.ErrorMessage);
                CppsWinsockErrorEvent(this, e);
            }
        }
Exemple #5
0
        public CppsWinsockErrorArgs(CommPortProxy cpp, string errorMsg)
        {
            if (cpp == null)
            {
                throw new ArgumentNullException("cpp");
            }

            _cpp      = cpp;
            _errorMsg = errorMsg;
        }
Exemple #6
0
 public void RemoveNotConn()
 {
     for (int i = 0; i < this.List.Count; i++)
     {
         CommPortProxy cpp = List[i] as CommPortProxy;
         if (cpp.IsConnected == false)
         {
             this.RemoveAt(i);
         }
     }
 }
Exemple #7
0
        /// <summary>
        /// TimeOut
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cpp_ReceiveComplete(object sender, EventArgs e)
        {
            CommPortProxy cpp = (CommPortProxy)sender;

            if (ReceiveTimeOutEvent != null)
            {
                ReceiveTimeOutEventArgs args = new ReceiveTimeOutEventArgs(cpp, cpp.ReceiveData);

                ReceiveTimeOutEventHandler temp = ReceiveTimeOutEvent;
                temp(this, args);
            }
        }
Exemple #8
0
        /// <summary>
        /// ARD
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cpp_ReceiveAutoReport(object sender, EventArgs e)
        {
            CommPortProxy cpp = (CommPortProxy)sender;

            if (ReceiveARDEvent != null)
            {
                ReceiveARDEventArgs args = new ReceiveARDEventArgs(cpp, cpp.AutoReportData);
                //ReceiveARDEvent( this, args );
                ReceiveARDHandler temp = ReceiveARDEvent;
                temp(this, args);
            }
        }
Exemple #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cpp"></param>
        public void Add(CommPortProxy cpp)
        {
            if (cpp == null)
            {
                throw new ArgumentNullException("cpp");
            }
            this.InternalAdd(cpp);

            cpp.ReceiveAutoReport += new EventHandler(cpp_ReceiveAutoReport);
            cpp.ReceiveComplete   += new EventHandler(cpp_ReceiveComplete);
            cpp.WinsockError      += new WinsockErrorHandler(cpp_WinsockError);
            cpp.IsEnableAutoReport = true;
        }
        /// <summary>
        /// 查找匹配ip的CommPortProxy
        /// </summary>
        /// <param name="ip"></param>
        /// <returns></returns>
        private CommPortProxy SearchCPP(string ip)
        {
            for (int i = 0; i < _cppsCollection.Count; i++)
            {
                CommPortProxy cpp = _cppsCollection[i];
                if (cpp.RemoteHostIP == ip)
                {
                    return(cpp);
                }
            }

            return(null);
        }
        public TaskScheduler(CommPortProxy commPortProxy, int interval)
        {
            //System.Diagnostics.Debug.Assert (commPortProxy != null, "commPortProxy can't is null.");
            if (commPortProxy == null)
            {
                throw new ArgumentNullException("commPortProxy", SR.GetString("LE_CommPortProxyNull"));
            }

            m_SchedulerTimer          = new Timer();
            m_SchedulerTimer.Interval = interval;
            m_SchedulerTimer.Tick    += new EventHandler(SchedulerTimer_Tick);
            CommPortProxy             = commPortProxy;
        }
Exemple #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="commPortProxy"></param>
        /// <param name="cmd"></param>
        // 2006.12.13
        //
        //virtual protected void OnExecute ( CommPortProxy commPortProxy, Station station, CommCmdBase cmd, object[] parameters )
        virtual protected void OnExecute(CommPortProxy commPortProxy, CommCmdBase cmd)
        {
            // 2006.12.13
            //
            //byte[] bytesCmd = cmd.MakeCommand ( station, parameters );
            byte[] bytesCmd = cmd.MakeCommand();
            //Debug.Assert (bytesCmd != null && bytesCmd.Length >0 , "bytesCmd can't is null and must length >0" );

            // 2006.12.15 Added, save last send command byte[].
            //
            this.m_LastSendDatas = bytesCmd;

            commPortProxy.Send(bytesCmd, cmd.LatencyTime);
        }
Exemple #13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="index"></param>
        public void RemoveAt(int index)
        {
            CommPortProxy cpp = (CommPortProxy)GetItem(index);

            //TODO: unreg event
            //
            //if ( cpp.ReceiveAutoReport != null )
            cpp.ReceiveAutoReport -= new EventHandler(cpp_ReceiveAutoReport);
            //if ( cpp.ReceiveComplete != null )
            cpp.ReceiveComplete -= new EventHandler(cpp_ReceiveComplete);
            //if ( cpp.WinsockError != null )
            cpp.WinsockError -= new WinsockErrorHandler(cpp_WinsockError);

            this.InternalRemove(index);
        }
Exemple #14
0
 public ReceiveARDEventArgs(CommPortProxy cpp, byte[] datas)
 {
     if (cpp == null)
     {
         throw new ArgumentNullException("cpp");
     }
     _cpp = cpp;
     if (datas == null)
     {
         _datas = new byte[0];
     }
     else
     {
         _datas = (byte[])datas.Clone();
     }
 }
        private void cpps_ReceiveTimeOutEvent(object sender, ReceiveTimeOutEventArgs args)
        {
            CommPortProxy cpp = args.Source;

            byte[] datas = args.Datas;

            // 2007.03.16 Removed
            //
            //Debug.Assert (m_ActiveTask != null, "m_ActiveTask null");

            // 2007.03.04 Added check m_activeTask != null
            //
            if (m_ActiveTask != null)
            {
                m_ActiveTask.ProcessReceived(datas);
                if (Executed != null)
                {
                    EventHandler temp = Executed;
                    temp(this, null);
                }

                m_ActiveTask = null;
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="commPortProxy"></param>
 public TaskScheduler(CommPortProxy commPortProxy)
     : this(commPortProxy, DEFAULT_INTERVAL)
 {
 }
        /// <summary>
        /// 查找需要执行的任务,并执行
        /// </summary>
        private void ScanExecute()
        {
            Task needExecTask = FindNeedExecuteTask();

            if (needExecTask != null)
            {
                if (Executing != null)
                {
                    EventHandler temp = Executing;
                    temp(this, EventArgs.Empty);
                }
                //{

                // 2007.02.23 modify
                //
                //needExecTask.Execute( m_CommPortProxy );
                CommCmdBase cmd = needExecTask.CommCmd;
                Debug.Assert(cmd != null);

                Station st = cmd.Station;
                Debug.Assert(st != null);

                // use ip
                //
                if (st.IsUseIP)
                {
                    string ip = st.DestinationIP;
                    // TODO: 2007-10-18 Search cpp use ip or simNumber
                    //
                    // search commPortProxy match ip
                    //
                    CommPortProxy cpp = SearchCPP(ip);
                    if (cpp != null)
                    {
                        needExecTask.Execute(cpp);
                    }
                    else
                    {
                        // not find match cpp
                        //
                        // TODO: raise not find cpp event
                        //
                        if (this.NotFindMatchCPPEvent != null)
                        {
                            EventHandler temp = NotFindMatchCPPEvent;
                            temp(this, EventArgs.Empty);
                        }
                        needExecTask.LastExecute = DateTime.Now;
                        Debug.Assert(m_ActiveTask != null, "at not find match ip cpp, m_activeTask == null");
                        m_ActiveTask = null;
                    }
                }
                // use commport
                //
                else
                {
                    //CommPortProxy cpp;
                    //needExecTask.Execute( cpp );
                    Debug.Fail("need use IP");
                }
                //}
            }
        }