Beispiel #1
0
        private void Dowork(object obj)
        {
            while (true)
            {
                List<CacheRegion> items = new List<CacheRegion>();
                try
                {
                    using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
                    {
                        items = dbContext.CacheRegions.ToList();
                    }
                }
                catch
                {

                }

                foreach (var item in items)
                {
                    CacheRegionDevice device = null;
                    dict.TryGetValue(item.Id, out device);
                    if (device != null)
                    {
                        if (item.Status != device.Status)
                        {
                            if (device.IsInteractive)//是交互灯
                            {
                                if (item.Status == 1)
                                {
                                    device.CallButton.Display(new Display900UItem(), LightColor.Green, true);//交互灯开启采集
                                }
                                else
                                {
                                    device.CallButton.Clear(true);
                                }
                            }
                            else
                            {
                                if (item.Status == 1)
                                {
                                    device.GreenLighthouse.Display();
                                }
                                else
                                {
                                    device.GreenLighthouse.Clear();
                                }
                            }

                            device.Status = item.Status;
                        }
                    }
                }

                Thread.Sleep(1000);
            }
        }
Beispiel #2
0
        private void DoLock(object obj)
        {
            while (true)
            {
                List<CacheRegion> items = new List<CacheRegion>();
                try
                {
                    using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
                    {
                        //只读取交互灯即可,因为只有交互灯才可以锁定
                        items = dbContext.CacheRegions.Where(x => x.IsInteractive == true).ToList();
                    }
                }
                catch
                {

                }

                foreach (var item in items)
                {
                    CacheRegionDevice device = null;
                    dict.TryGetValue(item.Id, out device);
                    if (device != null)
                    {
                        if (item.IsLocked != device.IsLocked)
                        {
                            if (item.IsLocked)
                            {
                                device.CallButton.Lock();
                            }
                            else
                            {
                                device.CallButton.Unlock();
                            }

                            device.IsLocked = item.IsLocked;
                        }
                    }
                }

                Thread.Sleep(1000);
            }
        }
Beispiel #3
0
        public void Start()
        {
            try
            {
                List<CacheRegion> items = new List<CacheRegion>();
                using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
                {
                    items = dbContext.CacheRegions.ToList();
                }
                foreach (var item in items)
                {
                    XGate xgate = this.xGates
                                     .FirstOrDefault(xg => xg.IPEndPoint.Address.ToString() == item.XGateIP);
                    if (xgate == null)
                    {
                        xgate = new XGate(item.XGateIP);
                        this.xGates.Add(xgate);
                    }
                    RS485Bus bus = xgate.Buses[(byte)item.Bus];
                    if (item.IsInteractive == true)//交互灯是PTL900U
                    {
                        Ptl900U callButton = (Ptl900U)bus.Devices.FirstOrDefault(d => d.Address == (byte)item.Address);
                        if (callButton == null)
                        {
                            callButton = new Ptl900U();
                            callButton.Address = (byte)item.Address;

                            bus.Devices.AddOrUpdate(callButton);
                        }

                        CacheRegionDevice logicDevice = new CacheRegionDevice
                        {
                            XGate = xgate,
                            Bus = bus,
                            CallButton = callButton,
                            IsInteractive = item.IsInteractive,
                            Id = item.Id,
                            AreaId = item.AreaId
                        };

                        this.devices.Add(logicDevice);
                    }
                    else
                    {
                        PtlMXP1O5 m3 = bus.Devices.FirstOrDefault(d => d.Address == (byte)item.Address) as PtlMXP1O5;
                        if (m3 == null)
                        {
                            m3 = new PtlMXP1O5();
                            m3.Address = (byte)item.Address;

                            bus.Devices.AddOrUpdate(m3);
                        }

                        Lighthouse redLighthouse = m3.Lighthouses[(byte)2];
                        Lighthouse orangeLighthouse = m3.Lighthouses[(byte)1];
                        Lighthouse greenLighthouse = m3.Lighthouses[(byte)4];

                        CacheRegionDevice logicDevice = new CacheRegionDevice
                        {
                            XGate = xgate,
                            Bus = bus,
                            M3 = m3,
                            RedLighthouse = redLighthouse,
                            GreenLighthouse = greenLighthouse,
                            OrangeLighthouse = orangeLighthouse,
                            IsInteractive = false,
                            Id = item.Id,
                            AreaId = item.AreaId
                        };

                        this.devices.Add(logicDevice);

                    }
                }
                //启动 PTL 通讯
                foreach (XGate xGate in this.xGates)
                {
                    xGate.StartUnicastCommandQueue();

                    foreach (RS485Bus bus in xGate.Buses)
                    {
                        foreach (PtlDevice target in bus.Devices)
                        {
                            target.Initialize();
                            if (target is Ptl900U)
                            {
                                (target as Ptl900U).Pressed += CallButton_Pressed;
                            }
                        }
                    }
                }

                dict = this.devices.ToDictionary(x => x.Id);

                thread = new Thread(new ParameterizedThreadStart(Dowork));
                thread.IsBackground = true;
                thread.Start();

                lockThread = new Thread(new ParameterizedThreadStart(DoLock));
                lockThread.IsBackground = true;
                lockThread.Start();

                var groups = this.devices.GroupBy(x => x.AreaId);
                foreach (var group in groups)
                {
                    dictBool.AddOrUpdate(group.Key, false, (a, b) => b);

                    Thread threadStatus = new Thread(new ParameterizedThreadStart(DoStatus));
                    threadStatus.IsBackground = true;
                    threadStatus.Start(group.Key);

                    dictThread.AddOrUpdate(group.Key, threadStatus, (a, b) => b);
                }
            }
            catch (Exception ex)
            {
                this.Stop();
            }
        }