예제 #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;
 }
예제 #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);
        }
예제 #3
0
파일: TaskBase.cs 프로젝트: 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(...)");
            }
        }
예제 #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);
        }
예제 #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);
                    }
                }
            }
        }
예제 #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);
        }
예제 #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));
            }
        }
예제 #8
0
파일: Client.cs 프로젝트: 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);
        }
예제 #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="cp"></param>
 public CommuniPortEventArgs(ICommuniPort cp)
 {
     if (cp == null)
     {
         throw new ArgumentNullException("cp");
     }
     this._cp = cp;
 }
예제 #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);
        }
예제 #11
0
파일: TaskScheduler.cs 프로젝트: wpmyj/c3
        /// <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);
        }
예제 #12
0
파일: TaskScheduler.cs 프로젝트: wpmyj/c3
        private void ExecutingTask(ITask headTask)
        {
            ICommuniPort cp     = GetCommuniPort(headTask);
            IDevice      device = headTask.Device;

            headTask.Begin(cp);

            //device.TaskManager.Current = headTask;
            device.TaskManager.CaptureCurrent(headTask);
        }
예제 #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;
 }
예제 #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);
        }
예제 #15
0
파일: LocalPortConfig.cs 프로젝트: wpmyj/c3
        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);
        }
예제 #16
0
파일: frmCustomTask.cs 프로젝트: wpmyj/c3
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private bool IsDeviceConnected()
        {
            bool         r  = false;
            ICommuniPort cp = this._device.Station.CommuniPort;

            if (cp != null)
            {
                r = cp.IsOpened;
            }
            return(r);
        }
예제 #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);
         }
     }
 }
예제 #18
0
파일: TaskScheduler.cs 프로젝트: wpmyj/c3
        /// <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);
        }
예제 #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);
        }
예제 #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));
        }
예제 #21
0
파일: TaskBase.cs 프로젝트: 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(...)");
            }
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
            }
        }
예제 #25
0
파일: StationTreeNode.cs 프로젝트: wpmyj/c3
        /// <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);
            }
        }
예제 #26
0
파일: frmCPInfo.cs 프로젝트: wpmyj/c3
        /// <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);
        }
예제 #27
0
파일: TaskScheduler.cs 프로젝트: wpmyj/c3
        /// <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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #30
0
파일: Events.cs 프로젝트: hkiaipc/C3
 /// <summary>
 /// 
 /// </summary>
 /// <param name="cp"></param>
 public CommuniPortEventArgs(ICommuniPort cp)
 {
     if (cp == null)
         throw new ArgumentNullException("cp");
     this._cp = cp;
 }
예제 #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);
        }
예제 #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;
        }
예제 #33
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="cp"></param>
 /// <returns></returns>
 override public bool IsMatch(ICommuniPort cp)
 {
     return(false);
 }
예제 #34
0
        void _cpManager_ReceivedCommuniPort(object sender, CommuniPortEventArgs e)
        {
            ICommuniPort cp = e.CommuniPort;

            ProcessReceived(cp);
        }
예제 #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;
 }
예제 #36
0
파일: TaskScheduler.cs 프로젝트: hkiaipc/C3
 /// <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;
 }
예제 #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);
        }
예제 #38
0
파일: TaskBase.cs 프로젝트: hkiaipc/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,
                    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(...)");
            }
        }
예제 #39
0
파일: TaskScheduler.cs 프로젝트: hkiaipc/C3
        /// <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;
        }
예제 #40
0
파일: TaskBase.cs 프로젝트: hkiaipc/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.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(...)");
            }
        }