Esempio n. 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="cfg"></param>
 /// <param name="success"></param>
 /// <param name="cp"></param>
 /// <param name="ex"></param>
 public CommuniPortCreatedEventArgs(ICommuniPortConfig cfg, bool success, ICommuniPort cp, Exception ex)
 {
     this._communiPortConfig = cfg;
     this._success           = success;
     this._communiPort       = cp;
     this._exception         = ex;
 }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cp"></param>
        /// <returns></returns>
        public bool Remove(ICommuniPort cp)
        {
            if (cp == null)
            {
                throw new ArgumentNullException("cp");
            }

            // remove cp event handler
            //
            cp.Determined -= new EventHandler(cp_Determined);
            cp.Closed     -= new EventHandler(cp_Closed);

            //Hardware hd = this.Soft.Hardware;
            //StationCommuniPortBinder.Unbind(cp, hd);

            bool r = this.CommuniPorts.Remove(cp);

            //
            //
            if (RemovedCommuniPort != null)
            {
                RemovedCommuniPort(this, new CommuniPortEventArgs(cp));
            }
            return(r);
        }
Esempio n. 3
0
File: TaskBase.cs Progetto: wpmyj/c3
        /// <summary>
        ///
        /// </summary>
        /// <param name="cp"></param>
        public void Begin(ICommuniPort cp)
        {
            if (this.Status == TaskStatus.Ready)
            {
                OnBegining(EventArgs.Empty);


                byte[] bytes = this.Opera.CreateSendBytes(this.Device);

                this.LastSendBytes    = bytes;
                this.LastSendDateTime = DateTime.Now;
                this.LastExecute      = DateTime.Now;

                bool success = cp.Write(bytes);
                if (success)
                {
                    cp.Occupy(this.Timeout);
                    this.SetStatus(TaskStatus.Executing);
                }
                else
                {
                    ICommuniDetail sendFailCommuniDetail = new SendFailCommuniDetail(
                        this.Opera.Text, this.LastSendDateTime, this.LastSendBytes);

                    this.Device.CommuniDetails.Add(sendFailCommuniDetail);
                    this.SetStatus(TaskStatus.Executed);
                }

                OnBegined(EventArgs.Empty);
            }
            else
            {
                throw new InvalidOperationException("status must be 'Ready' when call Begin(...)");
            }
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void _socketListenerManager_NewCommuniPortEvent(object sender, EventArgs e)
        {
            SocketListenerManager sckListenMan = sender as SocketListenerManager;
            ICommuniPort          cp           = sckListenMan.NewCommuniPort;

            this.CommuniPortManager.Add(cp);
        }
Esempio n. 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ProcessReceived(ICommuniPort cp)
        {
            //ICommuniPort cp = (ICommuniPort)sender;
            byte[] bs = cp.Read();

            // TODO: cp.stations
            //
            StationCollection stations = new StationCollection();

            foreach (IStation st in this.Soft.Hardware.Stations)
            {
                if (st.CommuniPortConfig.IsMatch(cp))
                {
                    stations.Add(st);
                }
            }

            foreach (IStation st in stations)
            {
                foreach (IDevice d in st.Devices)
                {
                    if (bs.Length > 0)
                    {
                        //ITaskProcessor processor = d.Dpu.Processor;
                        //IUploadParseResult parseResult = processor.ProcessUpload(d, bs);
                        //bs = parseResult.Remain;
                        d.ProcessUpload(bs);
                    }
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cpCfg"></param>
        /// <returns></returns>
        public ICommuniPort GetOrCreateCommuniPort(ICommuniPortConfig cpCfg)
        {
            if (cpCfg == null)
            {
                throw new ArgumentNullException("cpCfg");
            }

            ICommuniPort r = null;

            foreach (ICommuniPort cp in this.CommuniPorts)
            {
                if (cpCfg.IsMatch(cp))
                {
                    r = cp;
                    break;
                }
            }

            if (r == null)
            {
                if (cpCfg.CanCreate)
                {
                    CommuniPortFactory f = CommuniPortFactory.Default;
                    bool added           = f.Add(cpCfg);
                    _log.Info("add " + cpCfg + " to communiport factory: " + added);
                }
            }

            return(r);
        }
Esempio n. 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cp"></param>
        public void Add(ICommuniPort cp)
        {
            if (cp == null)
            {
                throw new ArgumentNullException("cp");
            }

            // TODO: exist cp remove
            //
            this.CommuniPorts.Add(cp);

            //
            //
            cp.Filters         = this.Filters;
            cp.IdentityParsers = this.IdentityParsers;

            // register cp event
            //
            cp.Received   += new EventHandler(cp_Received);
            cp.Determined += new EventHandler(cp_Determined);
            cp.Closed     += new EventHandler(cp_Closed);

            //StationCommuniPortBinder.Bind(cp, this.Soft.Hardware);

            //
            //
            if (AddedCommuniPort != null)
            {
                AddedCommuniPort(this, new CommuniPortEventArgs(cp));
            }
        }
Esempio n. 8
0
File: Client.cs Progetto: wpmyj/c3
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void CommuniPort_Received(object sender, EventArgs e)
        {
            ICommuniPort cp = (ICommuniPort)sender;

            byte[] bs = cp.Read();

            RequestProcessManager.Default.Process(this, bs);
        }
Esempio n. 9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="cp"></param>
 public CommuniPortEventArgs(ICommuniPort cp)
 {
     if (cp == null)
     {
         throw new ArgumentNullException("cp");
     }
     this._cp = cp;
 }
Esempio n. 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void _socketListenerManager_NewCommuniPortEvent(object sender, EventArgs e)
        {
            SocketListenerManager slMan = sender as SocketListenerManager;
            ICommuniPort          cp    = slMan.NewCommuniPort;

            Debug.Assert(cp != null);

            this.CommuniPortManager.Add(cp);
        }
Esempio n. 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="task"></param>
        /// <param name="cp"></param>
        /// <returns></returns>
        private bool IsHighestLevel(ITask task, ICommuniPort cp)
        {
            bool r = false;
            StationCollection stations = GetStations(cp);

            TaskCollection tasks = GetNeedExecuteTasks(stations);

            r = IsHighestLevel(task, tasks);
            return(r);
        }
Esempio n. 12
0
        private void ExecutingTask(ITask headTask)
        {
            ICommuniPort cp     = GetCommuniPort(headTask);
            IDevice      device = headTask.Device;

            headTask.Begin(cp);

            //device.TaskManager.Current = headTask;
            device.TaskManager.CaptureCurrent(headTask);
        }
Esempio n. 13
0
 public bool IsMatch(ICommuniPort cp)
 {
     bool r = false;
     SocketCommuniPort scp = cp as SocketCommuniPort;
     if (scp != null)
     {
         r = this.LocalPort == ((IPEndPoint)scp.LocalEndPoint).Port;
     }
     return r;
 }
Esempio n. 14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void cp_Closed(object sender, EventArgs e)
        {
            if (this.ClosedCommuniPort != null)
            {
                this.ClosedCommuniPort(this, new CommuniPortEventArgs((ICommuniPort)sender));
            }

            ICommuniPort cp = sender as ICommuniPort;

            this.Remove(cp);
        }
Esempio n. 15
0
        override public bool IsMatch(ICommuniPort cp)
        {
            bool r = false;
            SocketCommuniPort scp = cp as SocketCommuniPort;

            if (scp != null)
            {
                r = this.LocalPort == ((IPEndPoint)scp.LocalEndPoint).Port;
            }
            return(r);
        }
Esempio n. 16
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private bool IsDeviceConnected()
        {
            bool         r  = false;
            ICommuniPort cp = this._device.Station.CommuniPort;

            if (cp != null)
            {
                r = cp.IsOpened;
            }
            return(r);
        }
Esempio n. 17
0
 internal void RemoveByCommuniPort(ICommuniPort cp)
 {
     for (int i = this.Clients.Count - 1; i >= 0; i--)
     {
         Client c = this.Clients[i];
         if (c.CommuniPort == cp)
         {
             this.Remove(c);
         }
     }
 }
Esempio n. 18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cp"></param>
        /// <returns></returns>
        private StationCollection GetStations(ICommuniPort cp)
        {
            StationCollection r = new StationCollection();

            foreach (IStation st in Soft.Hardware.Stations)
            {
                if (st.CommuniPort == cp)
                {
                    r.Add(st);
                }
            }
            return(r);
        }
Esempio n. 19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="current"></param>
        /// <returns></returns>
        private byte[] GetReceived(ITask current)
        {
            IDevice      device  = current.Device;
            IStation     station = device.Station;
            ICommuniPort cp      = station.CommuniPort;

            byte[] received = new byte[0];
            if (cp != null)
            {
                received = cp.Read();
            }
            return(received);
        }
Esempio n. 20
0
        private void Default_CommuniPortCreated(object sender, CommuniPortCreatedEventArgs e)
        {
            if (e.Success)
            {
                ICommuniPort cp = e.CommuniPort;
                this.Add(cp);
            }

            this.CreateCommuniPortResults.Add(new CreateCommuniPortResult(
                                                  e.Success, e.CommuniPortConfig, "", e.Exception));

            _log.Info(string.Format("CreateCommuniPort '{0}' is '{1}'", e.CommuniPortConfig, e.Success));
        }
Esempio n. 21
0
File: TaskBase.cs Progetto: wpmyj/c3
        /// <summary>
        ///
        /// </summary>
        /// <param name="cp"></param>
        public void End(ICommuniPort cp)
        {
            if (this.Status == TaskStatus.Timeout)
            {
                OnEnding(EventArgs.Empty);
                byte[] bytes = new byte[0];

                if (cp != null)
                {
                    bytes = cp.Read();
                }

                // filte bytes by device
                //
                bytes = this.Device.Filters.Filtrate(bytes);

                this.LastReceivedBytes    = bytes;
                this.LastReceivedDateTime = DateTime.Now;

                IParseResult pr = this.Opera.ParseReceivedBytes(this.Device, bytes);
                this.LastParseResult = pr;


                //
                //
                CommuniDetail cd = new CommuniDetail(
                    this.Opera.Text,
                    LastSendBytes,
                    LastExecute,
                    LastReceivedBytes,
                    LastReceivedDateTime,
                    //parseResult.ToString(),
                    //parseResult.IsSuccess
                    pr
                    );
                this.Device.CommuniDetails.Add(cd);

                DeviceCommuniLogger.Log(this.Device, cd);
                //this.device

                //
                //
                // this.SetStatus(TaskStatus.Executed);

                OnEnded(EventArgs.Empty);
            }
            else
            {
                throw new InvalidOperationException("status must be 'Timeout' when call End(...)");
            }
        }
Esempio n. 22
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cp"></param>
        /// <param name="hardware"></param>
        /// <returns></returns>
        static public StationCollection Unbind(ICommuniPort cp, Hardware hardware)
        {
            StationCollection unbinded = new StationCollection();

            foreach (IStation station in hardware.Stations)
            {
                if (station.CommuniPort == cp)
                {
                    station.CommuniPort = null;
                    unbinded.Add(station);
                }
            }
            return(unbinded);
        }
Esempio n. 23
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cp"></param>
        /// <returns></returns>
        override public bool IsMatch(ICommuniPort cp)
        {
            bool r = false;
            SerialCommuniPort scp = cp as SerialCommuniPort;

            if (scp != null)
            {
                bool isSameName = StringHelper.Equal(
                    scp.SerialPort.PortName,
                    this.SerialPortSetting.PortName);
                r = isSameName;
            }
            return(r);
        }
Esempio n. 24
0
        /// <summary>
        ///
        /// </summary>
        void Target()
        {
            while (this._startFlag)
            {
                for (int i = _cpCfgs.Count - 1; i >= 0; i--)
                {
                    ICommuniPortConfig cfg = _cpCfgs[i];


                    if (cfg.CanCreate)
                    {
                        ICommuniPort cp      = null;
                        bool         success = false;
                        Exception    ex      = null;

                        try
                        {
                            cp      = cfg.Create();
                            success = true;

                            CPCreateLog cpclog = new CPCreateLog(DateTime.Now,
                                                                 string.Format("创建 '{0}' 成功", cfg));
                            this.CPCreateLogs.Add(cpclog);
                        }
                        catch (Exception e)
                        {
                            ex      = e;
                            success = false;

                            CPCreateLog cpclog = new CPCreateLog(DateTime.Now,
                                                                 string.Format("创建 '{0}' 失败, {1}", cfg, ex.Message));
                            this.CPCreateLogs.Add(cpclog);
                        }
                        if (success)
                        {
                            this._cpCfgs.Remove(cfg);
                        }

                        if (CommuniPortCreated != null)
                        {
                            CommuniPortCreated(this,
                                               new CommuniPortCreatedEventArgs(
                                                   cfg, success, cp, ex));
                        }
                    }
                }
                Thread.Sleep(SLEEP_TIME);
            }
        }
Esempio n. 25
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void station_CommuniPortChanged(object sender, EventArgs e)
        {
            IStation station = sender as IStation;

            Debug.Assert(station != null, "station != null");
            ICommuniPort cp = station.CommuniPort;

            if (cp != null)
            {
                SetImageKey(IconNames.Connect);
            }
            else
            {
                SetImageKey(IconNames.Disconnect);
            }
        }
Esempio n. 26
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cp"></param>
        /// <returns></returns>
        private string GetStationNames(ICommuniPort cp)
        {
            string r = string.Empty;

            StationCollection stations = SoftManager.GetSoft().Hardware.Stations;

            foreach (IStation st in stations)
            {
                if (st.CommuniPort == cp)
                {
                    if (r.Length > 0)
                    {
                        r += ",";
                    }
                    r += st.Name;
                }
            }

            return(r);
        }
Esempio n. 27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="headTask"></param>
        /// <returns></returns>
        //private bool DoNotExecutingTask(ITask headTask)
        private bool CanExecutingTask(ITask headTask)
        {
            TaskStatus status = headTask.Check();

            if (status == TaskStatus.Ready)
            {
                ICommuniPort cp = GetCommuniPort(headTask);
                if ((cp != null) &&
                    (!cp.IsOccupy) &&
                    IsHighestLevel(headTask, cp))
                {
                    //IDevice device = headTask.Device;
                    //headTask.Begin(cp);

                    ////device.TaskManager.Current = headTask;
                    //device.TaskManager.CaptureCurrent(headTask);
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 28
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cp"></param>
        /// <returns></returns>
        override public bool IsMatch(ICommuniPort cp)
        {
            if (cp == null)
            {
                return(false);
            }

            bool r = false;

            if (cp is SocketCommuniPort)
            {
                SocketCommuniPort scp = cp as SocketCommuniPort;

                EndPoint   ep        = scp.RemoteEndPoint;
                IPEndPoint ipep      = ep as IPEndPoint;
                IPAddress  ipAddress = ipep.Address;

                r = ipAddress.Equals(RemoteIPAddress);
            }
            return(r);
        }
Esempio n. 29
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cp"></param>
        /// <param name="hardware"></param>
        static public StationCollection Bind(ICommuniPort cp, Hardware hardware)
        {
            StationCollection binded = new StationCollection();

            foreach (IStation station in hardware.Stations)
            {
                ICommuniPortConfig cpConfig = station.CommuniPortConfig;
                if (cpConfig.IsMatch(cp))
                {
                    ICommuniPort old = station.CommuniPort;
                    if (old != cp)
                    {
                        if (old != null)
                        {
                            old.Close();
                        }
                        station.CommuniPort = cp;
                        binded.Add(station);
                    }
                }
            }

            return(binded);
        }
Esempio n. 30
0
File: Events.cs Progetto: hkiaipc/C3
 /// <summary>
 /// 
 /// </summary>
 /// <param name="cp"></param>
 public CommuniPortEventArgs(ICommuniPort cp)
 {
     if (cp == null)
         throw new ArgumentNullException("cp");
     this._cp = cp;
 }
Esempio n. 31
0
        public void Add(ICommuniPort cp)
        {
            if (cp == null)
            {
                throw new ArgumentNullException("cp");
            }

            // TODO: exist cp remove
            //
            this.CommuniPorts.Add(cp);

            //
            //
            cp.Filters = this.Filters;
            cp.IdentityParsers = this.IdentityParsers;

            // register cp event
            //
            cp.Received += new EventHandler(cp_Received);
            cp.Determined += new EventHandler(cp_Determined);
            cp.Closed += new EventHandler(cp_Closed);

            StationCommuniPortBinder.Bind(cp, this.Soft.Hardware);
        }
Esempio n. 32
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="cp"></param>
        /// <returns></returns>
        public bool IsMatch(ICommuniPort cp)
        {
            if (cp == null)
            {
                return false;
            }

            bool r = false;
            if (cp is SocketCommuniPort)
            {
                SocketCommuniPort scp = cp as SocketCommuniPort;

                EndPoint ep = scp.RemoteEndPoint;
                IPEndPoint ipep = ep as IPEndPoint;
                IPAddress ipAddress = ipep.Address;

                r = ipAddress.Equals(RemoteIPAddress);
            }
            return r;
        }
Esempio n. 33
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="cp"></param>
 /// <returns></returns>
 override public bool IsMatch(ICommuniPort cp)
 {
     return(false);
 }
Esempio n. 34
0
        void _cpManager_ReceivedCommuniPort(object sender, CommuniPortEventArgs e)
        {
            ICommuniPort cp = e.CommuniPort;

            ProcessReceived(cp);
        }
Esempio n. 35
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="cp"></param>
 /// <returns></returns>
 public bool IsMatch(ICommuniPort cp)
 {
     bool r = false;
     SerialCommuniPort scp = cp as SerialCommuniPort;
     if (scp != null)
     {
         bool isSameName = StringHelper.Equal(
             scp.SerialPort.PortName,
             this.SerialPortSetting.PortName);
         r = isSameName;
     }
     return r;
 }
Esempio n. 36
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="cp"></param>
 /// <returns></returns>
 private StationCollection GetStations(ICommuniPort cp)
 {
     StationCollection r = new StationCollection();
     foreach (IStation st in Soft.Hardware.Stations)
     {
         if (st.CommuniPort == cp)
         {
             r.Add(st);
         }
     }
     return r;
 }
Esempio n. 37
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="cp"></param>
        /// <returns></returns>
        public bool Remove(ICommuniPort cp)
        {
            if (cp == null)
            {
                throw new ArgumentNullException("cp");
            }

            // remove cp event handler
            //
            cp.Determined -= new EventHandler(cp_Determined);
            cp.Closed -= new EventHandler(cp_Closed);

            Hardware hd = this.Soft.Hardware;
            StationCommuniPortBinder.Unbind(cp, hd);

            return this.CommuniPorts.Remove(cp);
        }
Esempio n. 38
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="cp"></param>
        public void End(ICommuniPort cp)
        {
            if (this.Status == TaskStatus.Timeout)
            {
                OnEnding(EventArgs.Empty);
                byte[] bytes = new byte[0];

                if (cp != null)
                {
                    bytes = cp.Read();
                }

                // filte bytes by device
                //
                bytes = this.Device.Filters.Filtrate(bytes);

                this.LastReceivedBytes = bytes;
                this.LastReceivedDateTime = DateTime.Now;

                IParseResult pr = this.Opera.ParseReceivedBytes(this.Device, bytes);
                this.LastParseResult = pr;

                //
                //
                CommuniDetail cd = new CommuniDetail(
                    this.Opera.Text,
                    LastSendBytes,
                    LastExecute,
                    LastReceivedBytes,
                    LastReceivedDateTime,
                    pr.ToString(),
                    pr.IsSuccess
                );
                this.Device.CommuniDetails.Add(cd);

                DeviceCommuniLogger.Log(this.Device, cd);
                //this.device

                //
                //
                // this.SetStatus(TaskStatus.Executed);

                OnEnded(EventArgs.Empty);
            }
            else
            {
                throw new InvalidOperationException("status must be 'Timeout' when call End(...)");
            }
        }
Esempio n. 39
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="task"></param>
        /// <param name="cp"></param>
        /// <returns></returns>
        private bool IsHighestLevel(ITask task, ICommuniPort cp)
        {
            bool r = false;
            StationCollection stations = GetStations(cp);

            TaskCollection tasks = GetNeedExecuteTasks(stations);
            r = IsHighestLevel(task, tasks);
            return r;
        }
Esempio n. 40
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="cp"></param>
        public void Begin(ICommuniPort cp)
        {
            if (this.Status == TaskStatus.Ready)
            {
                OnBegining(EventArgs.Empty);

                byte[] bytes = this.Opera.CreateSendBytes(this.Device);

                this.LastSendBytes = bytes;
                this.LastExecute = DateTime.Now;

                bool success = cp.Write(bytes);
                if (success)
                {
                    cp.Occupy(this.Timeout);
                    this.SetStatus(TaskStatus.Executing);
                }
                else
                {
                    this.SetStatus(TaskStatus.Executed);
                }

                OnBegined(EventArgs.Empty);
            }
            else
            {
                throw new InvalidOperationException("status must be 'Ready' when call Begin(...)");
            }
        }