Exemplo n.º 1
0
        /// <summary>
        /// 停止所有转台的 PTL 通讯。
        /// </summary>
        public void Stop()
        {
            foreach (RS485Bus rs485Bus in this.xGate.Buses)
            {
                foreach (PtlDevice ptlDevice in rs485Bus.Devices)
                {
                    ptlDevice.InErrorChanged -= this.ptlDevice_InErrorChanged;
                }
            }

            this.xGate.StopUnicastCommandQueue();
            this.xGate.Dispose();
            this.xGate = null;

            this.installProject = null;

            this.channelPtlByChannelId.Clear();

            this.IsRunning = false;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 加载并启动所有转台的 PTL 通讯。
        /// </summary>
        public void Start()
        {
            using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
            {
                List <CFG_Channel> cfgChannels = dbContext.CFG_Channels
                                                 .ToList();
                CFG_ChannelPtlDevice firstCFG_ChannelPtlDevice = dbContext.CFG_ChannelPtlDevices
                                                                 .First();

                //单个 XGate
                this.xGate          = new XGate(firstCFG_ChannelPtlDevice.XGateIP);
                this.installProject = new InstallProject();
                this.installProject.XGates.AddOrUpdate(this.xGate);

                foreach (CFG_Channel cfgChannel in cfgChannels)
                {
                    ChannelPtl channelPtl = new ChannelPtl(cfgChannel.Id);

                    this.channelPtlByChannelId.Add(cfgChannel.Id, channelPtl);

                    List <CFG_ChannelPtlDevice> cfgChannelPtlDevices = dbContext.CFG_ChannelPtlDevices
                                                                       .Where(cpd => cpd.CFG_ChannelId == cfgChannel.Id)
                                                                       .ToList();
                    //各个分拣口的指示灯
                    foreach (CFG_ChannelPtlDevice cfgChannelPtlDevice in cfgChannelPtlDevices)
                    {
                        Ptl900U ptl900U = (Ptl900U)this.xGate.Buses[cfgChannelPtlDevice.RS485BusIndex].Devices
                                          .FirstOrDefault(d => d.Address == cfgChannelPtlDevice.Ptl900UAddress);
                        if (ptl900U == null)
                        {
                            ptl900U           = new Ptl900U();
                            ptl900U.Address   = cfgChannelPtlDevice.Ptl900UAddress;
                            ptl900U.MinorType = Ptl900UType.P0;

                            this.xGate.Buses[cfgChannelPtlDevice.RS485BusIndex].Devices.AddOrUpdate(ptl900U);
                        }

                        channelPtl.SetPtl900UByPosition(cfgChannelPtlDevice.Position, ptl900U);
                    }
                }

                this.xGate.StartUnicastCommandQueue();

                foreach (RS485Bus rs485Bus in this.xGate.Buses)
                {
                    foreach (PtlDevice ptlDevice in rs485Bus.Devices)
                    {
                        ptlDevice.InErrorChanged += this.ptlDevice_InErrorChanged;

                        ptlDevice.Initialize();

                        //转台上的标签始终锁定
                        ptlDevice.Lock();
                    }
                }

                this.installProject.HeartbeatGenerator.Period = TimeSpan.FromSeconds(10);
                this.installProject.HeartbeatGenerator.Enable = true;
            }

            this.IsRunning = true;
        }