示例#1
0
        //update weight of each node based on current setting
        public void UpdateEachNodeTarget()
        {
            if (curr_cfg.target_comb <= 1)
            {
                foreach (byte naddr in weight_nodes)
                {
                    if ((agent.GetStatus(naddr) == NodeStatus.ST_IDLE))
                    {
                        agent.SetNodeReg(naddr, "target_weight", 0);
                    }
                }
                return;
            }
            double avg  = curr_cfg.target / curr_cfg.target_comb;
            double step = avg * NodeAgent.VAR_RANGE / weight_nodes.Count; // +/-15% variation of avg , example: for 30, step will be 0.9 gram

            foreach (byte naddr in weight_nodes)
            {
                if ((agent.GetStatus(naddr) == NodeStatus.ST_IDLE))
                {
                    double per = avg + (Int32.Parse(naddr.ToString()) - (weight_nodes.Count) / 2) * step;
                    agent.SetNodeReg(naddr, "target_weight", Convert.ToUInt32(per));
                }
            }
        }
示例#2
0
        //update UI when a packer is hitted
        public void CombineNodeUI(CombineEventArgs ce)
        {
            foreach (byte naddr in currentApp().packers[ce.packer_id].weight_nodes)
            {
                string param = "wei_node" + naddr.ToString();
                Label  lb    = this.FindName(param) as Label;
                Button btn   = this.FindName(param.Replace("wei_node", "bucket")) as Button;

                NodeAgent agent = currentApp().packers[ce.packer_id].agent;

                //update weight first
                double wt = -100000;
                for (int i = 0; i < ce.release_addrs.Length; i++)
                {
                    if (ce.release_addrs[i] == naddr)
                    {
                        wt = ce.release_wts[i];
                        break;
                    }
                }

                if (wt > -1000 && wt <= WeighNode.MAX_VALID_WEIGHT)
                {
                    lb.Content = wt.ToString("F1");
                }

                //update status display
                if (agent.GetStatus(naddr) == NodeStatus.ST_LOST || agent.GetStatus(naddr) == NodeStatus.ST_DISABLED)
                {
                    btn.Template = this.FindResource("WeightBarError") as ControlTemplate;
                }
                else if (naddr != curr_packer.vib_addr)
                {
                    if (ce.release_addrs.Contains(naddr))
                    {
                        btn.Template = this.FindResource("WeightBarRelease") as ControlTemplate;
                    }
                    else
                    {
                        btn.Template = this.FindResource("WeightBar") as ControlTemplate;
                    }
                }
                btn.ApplyTemplate();
            }
            //Update speed information
            UIPacker p = currentApp().packers[ce.packer_id];

            if (p.status == PackerStatus.RUNNING)
            {
                lbl_speed.Content      = p.speed.ToString();
                lbl_lastweight.Content = p.last_pack_weight.ToString("F1");
                lbl_totalpack.Content  = p.total_packs.ToString();
                RefreshVibUI();
            }
        }
示例#3
0
        public void RefreshRunNodeUI() //node ui update at run time
        {
            lbl_status.Content = "";
            foreach (UIPacker pk in currentApp().packers)
            {
                foreach (byte naddr in pk.weight_nodes)
                {
                    string    param = "wei_node" + naddr.ToString();
                    Label     lb    = this.FindName(param) as Label;
                    Button    btn   = this.FindName(param.Replace("wei_node", "bucket")) as Button;
                    byte      n     = (byte)(RunMode.StringToId(param));
                    NodeAgent agent = pk.agent;

                    double wt = agent.weight(n);
                    if (wt > -1000 && wt <= WeighNode.MAX_VALID_WEIGHT)
                    {
                        lb.Content = agent.weight(n).ToString("F1");
                    }

                    if (agent.GetStatus(n) == NodeStatus.ST_LOST || agent.GetStatus(n) == NodeStatus.ST_DISABLED)
                    {
                        btn.Template = this.FindResource("WeightBarError") as ControlTemplate;
                        btn.ApplyTemplate();
                    }
                    string err = agent.GetErrors(n);
                    if (err != "" && AlertWnd.b_turnon_alert && AlertWnd.b_show_alert)
                    {
                        lbl_status.Content = n.ToString() + ":" + StringResource.str(err.Substring(0, err.IndexOf(';'))) + "\n";
                    }
                }
                if (pk.status == PackerStatus.RUNNING)
                {
                    lbl_speed.Content      = pk.speed.ToString();
                    lbl_lastweight.Content = pk.last_pack_weight.ToString("F1");
                    lbl_totalpack.Content  = pk.total_packs.ToString();

                    RefreshVibUI();
                }
            }
            if (lbl_status.Content.ToString() == "")
            {
                lbl_status.Content    = StringResource.str("normal");
                lbl_status.Foreground = Brushes.Green;
            }
            else
            {
                lbl_status.Foreground = Brushes.Red;
                if (AlertWnd.b_turnon_alert && AlertWnd.b_stop_onalert && (curr_packer.status == PackerStatus.RUNNING))
                {
                    btn_start_click(null, null);
                }
            }
        }
示例#4
0
        private void RefreshNodeUI()
        {
            foreach (UIPacker pk in currentApp().packers)
            {
                foreach (byte naddr in pk.weight_nodes)
                {
                    string    param = "wei_node" + naddr.ToString();
                    Label     lb    = this.FindName(param) as Label;
                    Button    btn   = this.FindName(param.Replace("wei_node", "bucket")) as Button;
                    byte      n     = (byte)(RunMode.StringToId(param));
                    NodeAgent agent = currentApp().packers[pk._pack_id].agent;

                    double wt = agent.weight(n);
                    if (wt > -1000 && wt <= WeighNode.MAX_VALID_WEIGHT)
                    {
                        lb.Content = agent.weight(n).ToString("F1");
                    }
                    else
                    {
                        if (wt > WeighNode.MAX_VALID_WEIGHT && wt < 65537)
                        {
                            lb.Content = "ERR";
                        }
                    }

                    if (agent.GetStatus(n) == NodeStatus.ST_LOST || agent.GetStatus(n) == NodeStatus.ST_DISABLED)
                    {
                        btn.Template = this.FindResource("WeightBarError") as ControlTemplate;
                    }
                    if (agent.GetStatus(n) == NodeStatus.ST_IDLE)
                    {
                        if (btn == curr_btn || bSelectAll)
                        {
                            btn.Template = this.FindResource("WeightBarFocus") as ControlTemplate;
                        }
                        else
                        {
                            btn.Template = this.FindResource("WeightBar") as ControlTemplate;
                        }
                    }
                    btn.ApplyTemplate();
                }
            }
            UIPacker p = curr_packer;

            if (p.status == PackerStatus.RUNNING)
            {
                lbl_speed.Content        = p.speed.ToString();
                lbl_lastweight.Content   = p.last_pack_weight.ToString("F1");
                lbl_totalpack.Content    = p.total_sim_packs.ToString();
                lbl_totalweights.Content = p.total_sim_weights.ToString("F1");
            }
        }
示例#5
0
        private void sub_applyall()
        {
            App       p     = Application.Current as App;
            UIPacker  pack  = curr_packer;
            NodeAgent agent = pack.agent;
            byte      cn    = (byte)curr_node_index;

            bool star = true;

            foreach (byte n in curr_packer.weight_nodes)
            {
                foreach (string reg in apply_regs.Distinct())
                {
                    if (agent.GetStatus(n) == NodeStatus.ST_LOST)
                    {
                        continue;
                    }
                    if (agent.GetStatus(n) == NodeStatus.ST_DISABLED)
                    {
                        continue;
                    }

                    if (n == cn)
                    {
                        continue;
                    }
                    UInt32 val = UInt32.Parse(curr_packer.agent.GetNodeReg(cn, reg));
                    if (!curr_packer.agent.SetNodeReg(n, reg, val))
                    {
                        return;
                    }

                    if (star)
                    {
                        Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, (Action) delegate
                        {
                            txt_oper.Content = StringResource.str("modifying") + " " + n.ToString() + "*";
                        });
                    }
                    else
                    {
                        Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, (Action) delegate
                        {
                            txt_oper.Content = StringResource.str("modifying") + " " + n.ToString();
                        });
                    }
                    star = !star;
                }
            }
            apply_regs.Clear();
        }
示例#6
0
        private void HitCombineNodeUI(CombineEventArgs ce)
        {
            foreach (byte naddr in currentApp().packers[ce.packer_id].weight_nodes)
            {
                string    param = "wei_node" + naddr.ToString();
                Label     lb    = this.FindName(param) as Label;
                Button    btn   = this.FindName(param.Replace("wei_node", "bucket")) as Button;
                byte      n     = (byte)(RunMode.StringToId(param));
                NodeAgent agent = currentApp().packers[ce.packer_id].agent;

                if (!ce.release_addrs.Contains(n))
                {
                    continue;
                }
                double wt = agent.weight(n);
                if (wt > -1000 && wt <= WeighNode.MAX_VALID_WEIGHT)
                {
                    lb.Content = agent.weight(n).ToString("F1");
                }

                if (agent.GetStatus(n) == NodeStatus.ST_LOST || agent.GetStatus(n) == NodeStatus.ST_DISABLED)
                {
                    btn.Template = this.FindResource("WeightBarError") as ControlTemplate;
                }
                else
                {
                    if (n != curr_packer.vib_addr)
                    {
                        if (ce.release_addrs.Contains(n))
                        {
                            btn.Template = this.FindResource("WeightBarRelease") as ControlTemplate;
                        }
                        else
                        {
                            btn.Template = this.FindResource("WeightBar") as ControlTemplate;
                            if (agent.GetStatus(n) == NodeStatus.ST_IDLE)
                            {
                                if (btn == curr_btn || bSelectAll)
                                {
                                    btn.Template = this.FindResource("WeightBarFocus") as ControlTemplate;
                                }
                            }
                        }
                    }
                }

                btn.ApplyTemplate();
            }
        }