Ejemplo n.º 1
0
        private void Dowork(object state)
        {
            while (true)
            {
                List <PickZone> items = new List <PickZone>();
                try
                {
                    using (GeelyPtlEntities dbContext = new GeelyPtlEntities())
                    {
                        items = dbContext.PickZones.ToList();
                    }
                }
                catch
                {
                }
                foreach (var item in items)
                {
                    PickZoneDevice device = null;
                    dict.TryGetValue(item.Id, out device);
                    if (device != null)
                    {
                        if (item.Status != device.Status)
                        {
                            if (item.Status == 1)
                            {
                                device.OrangeLighthouse.Display();
                            }
                            else
                            {
                                device.OrangeLighthouse.Clear();
                            }


                            device.Status = item.Status;
                        }
                    }
                }

                Thread.Sleep(1000);
            }
        }
Ejemplo n.º 2
0
        public void Start()
        {
            this.Stop();
            try
            {
                List <PickZone> items = new List <PickZone>();
                using (GeelyPtlEntities context = new GeelyPtlEntities())
                {
                    items = context.PickZones.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];
                    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];

                    PickZoneDevice logicDevice = new PickZoneDevice
                    {
                        XGate            = xgate,
                        Bus              = bus,
                        M3               = m3,
                        RedLighthouse    = redLighthouse,
                        GreenLighthouse  = greenLighthouse,
                        OrangeLighthouse = orangeLighthouse,
                        CFG_ChannelId    = item.CFG_ChannelId,
                        Id               = item.Id
                    };

                    this.devices.Add(logicDevice);
                }

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

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

                    foreach (RS485Bus bus in xGate.Buses)
                    {
                        foreach (PtlDevice target in bus.Devices)
                        {
                            target.Initialize();
                        }
                    }
                }

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

                threadStatus = new Thread(new ParameterizedThreadStart(DoStatus));
                threadStatus.IsBackground = true;
                threadStatus.Start();
            }
            catch
            {
                this.Stop();
            }
        }