Example #1
0
        private void passbar_MouseLeftButtonUp(int sid)
        {
            if (curr_packer.status == PackerStatus.RUNNING)
            {
                return;
            }
            if (!AlertWnd.b_manual_reset || !AlertWnd.b_turnon_alert) //auto reset or alert off
            {
                return;
            }

            byte id = (byte)sid;

            curr_node = id;
            if (AlertWnd.b_turnon_alert && AlertWnd.b_show_alert)
            {
                if ((NodeMaster.GetStatus(id) == NodeStatus.ST_LOST) || (NodeMaster.GetStatus(id) == NodeStatus.ST_DISABLED))
                {
                    lbl_alert3.Text = StringResource.str("alert_enable");
                }
                else
                {
                    lbl_alert3.Text = StringResource.str("alert_disable");
                }
                UpdateAlertWindow(true);
            }
        }
Example #2
0
        private Dictionary <byte, bool> bSimNodeValid; //array used to store the state of each node in simulation mode;

        private bool CacuInvalidNode(int i)
        {
            if (NodeMaster.GetStatus(packer.weight_nodes[i]) == NodeStatus.ST_LOST)
            {
                return(true);
            }
            if (NodeMaster.GetStatus(packer.weight_nodes[i]) == NodeStatus.ST_DISABLED)
            {
                return(true);
            }

            if ((bSimCombine) && (!bSimNodeValid[packer.weight_nodes[i]]))
            {
                return(true);
            }
            double wt = NodeMaster.GetWeight(packer.weight_nodes[i]);

            if (wt <= llim)
            {
                return(true);
            }
            if (wt < 0)
            {
                return(true);
            }
            if (wt > WeighNode.MAX_VALID_WEIGHT)
            {
                return(true);
            }
            return(false);
        }
Example #3
0
 private void lbl_alert_MouseLeftButtonUp(object sender, EventArgs e)
 {
     if ((sender is Button) && (curr_node != 0xff))
     {
         Button l  = sender as Button;
         byte   id = curr_node;
         if (l.Name == "lbl_alert1") //alert solved
         {
             NodeMaster.ClearErrors(id);
         }
         if (l.Name == "lbl_alert2") //alert force
         {
             NodeMaster.Action(new byte[] { id }, "empty");
             NodeMaster.ClearErrors(id);
         }
         if (l.Name == "lbl_alert3") //alert disable
         {
             if ((NodeMaster.GetStatus(id) == NodeStatus.ST_LOST) || (NodeMaster.GetStatus(id) == NodeStatus.ST_DISABLED))
             {
                 NodeMaster.SetStatus(id, NodeStatus.ST_IDLE);
             }
             else
             {
                 NodeMaster.SetStatus(id, NodeStatus.ST_DISABLED);
             }
         }
         if (l.Name == "lbl_alert4") //alert quit
         {
         }
         curr_node = 0xff;
         UpdateAlertWindow(false);
     }
 }
Example #4
0
 private bool ProcessGoonNodes() //send command to nodes that needs to goon
 {
     foreach (byte addr in bSimNodeValid.Keys)
     {
         if (bSimNodeValid[addr] == false)
         {
             continue;
         }
         if (NodeMaster.GetStatus(addr) == NodeStatus.ST_LOST || NodeMaster.GetStatus(addr) == NodeStatus.ST_DISABLED)
         {
             continue;
         }
         double wt = NodeMaster.GetWeight(addr);
         if ((wt < (packer.curr_cfg.target / 2)) && (wt >= 0.0) && (wt <= WeighNode.MAX_VALID_WEIGHT))
         {
             NodeMaster.Action(new byte[] { addr }, "flag_goon"); //no match hit
         }
         else
         {
             if ((wt > packer.curr_cfg.target / 2) && (wt <= WeighNode.MAX_VALID_WEIGHT))
             {
                 wt = 100;
             }
         }
         bSimNodeValid[addr] = false;
         return(true);
     }
     return(false);
 }
Example #5
0
        public void RefreshRunNodeUI() //node ui update at run time
        {
            lbl_status.Text = "";
            foreach (UIPacker pk in Program.packers)
            {
                foreach (byte naddr in pk.weight_nodes)
                {
                    string          param = "wei_node" + naddr.ToString();
                    byte            n     = (byte)(RunModeWnd.StringToId(param));
                    NodeCombination nc    = pk.nc;

                    double wt = NodeMaster.GetWeight(n);
                    if (wt > -1000 && wt <= WeighNode.MAX_VALID_WEIGHT)
                    {
                        runPan1.SetText(n, wt.ToString("F1"), false);
                    }

                    if (NodeMaster.GetStatus(n) == NodeStatus.ST_LOST || NodeMaster.GetStatus(n) == NodeStatus.ST_DISABLED)
                    {
                        runPan1.SetStatus("weightbar", n, PanStatus.ERROR, false);
                    }
                    string err = NodeMaster.GetErrors(n);
                    if (err != "" && AlertWnd.b_turnon_alert && AlertWnd.b_show_alert)
                    {
                        lbl_status.Text = n.ToString() + ":" + StringResource.str(err.Substring(0, err.IndexOf(';'))) + "\n";
                    }
                }
                if (pk.status == PackerStatus.RUNNING)
                {
                    lbl_speed.Text      = pk.speed.ToString();
                    lbl_lastweight.Text = pk.last_pack_weight.ToString("F1");
                    lbl_totalpack.Text  = pk.total_packs.ToString();

                    RefreshVibUI();
                }
            }
            if (lbl_status.Text.ToString() == "")
            {
                lbl_status.Text      = StringResource.str("normal");
                lbl_status.ForeColor = Color.Green;
            }
            else
            {
                lbl_status.ForeColor = Color.Red;
                if (AlertWnd.b_turnon_alert && AlertWnd.b_stop_onalert && (curr_packer.status == PackerStatus.RUNNING))
                {
                    btn_start_click(null, null);
                }
            }
            runPan1.ReDraw();
        }
Example #6
0
        //update UI when a packer is hitted
        public void CombineNodeUI(CombineEventArgs ce)
        {
            foreach (byte naddr in Program.packers[ce.packer_id].weight_nodes)
            {
                string param = "wei_node" + naddr.ToString();

                //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)
                {
                    runPan1.SetText(naddr, wt.ToString("F1"), false);
                }

                //update status display
                if (NodeMaster.GetStatus(naddr) == NodeStatus.ST_LOST || NodeMaster.GetStatus(naddr) == NodeStatus.ST_DISABLED)
                {
                    runPan1.SetStatus("weightbar", naddr, PanStatus.DISBALED, false);
                }
                else if (naddr != curr_packer.vib_addr)
                {
                    if (ce.release_addrs.Contains(naddr))
                    {
                        runPan1.SetStatus("weightbar", naddr, PanStatus.RELEASE, false);
                    }
                    else
                    {
                        runPan1.SetStatus("weightbar", naddr, PanStatus.IDLE, false);
                    }
                }
            }
            //Update speed information
            UIPacker p = Program.packers[ce.packer_id];

            if (p.status == PackerStatus.RUNNING)
            {
                lbl_speed.Text      = p.speed.ToString();
                lbl_lastweight.Text = p.last_pack_weight.ToString("F1");
                lbl_totalpack.Text  = p.total_packs.ToString();
                RefreshVibUI();
            }
        }
Example #7
0
        private void sub_applyall()
        {
            UIPacker pack = curr_packer;

            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 (NodeMaster.GetStatus(n) == NodeStatus.ST_LOST)
                    {
                        continue;
                    }
                    if (NodeMaster.GetStatus(n) == NodeStatus.ST_DISABLED)
                    {
                        continue;
                    }

                    if (n == cn)
                    {
                        continue;
                    }
                    UInt32 val = NodeMaster.GetNodeReg(cn, reg);
                    NodeMaster.SetNodeReg(n, new string[] { reg }, new UInt32[] { val });

                    if (star)
                    {
                        txt_oper.Text = StringResource.str("modifying") + " " + n.ToString() + "*";
                    }
                    else
                    {
                        txt_oper.Text = StringResource.str("modifying") + " " + n.ToString();
                    }
                    star = !star;
                }
            }
            apply_regs.Clear();
        }
Example #8
0
        private void RefreshNodeUI()
        {
            foreach (UIPacker pk in Program.packers)
            {
                foreach (byte naddr in pk.weight_nodes)
                {
                    byte   n  = naddr;
                    double wt = NodeMaster.GetWeight(n);
                    if (wt > -1000 && wt <= WeighNode.MAX_VALID_WEIGHT)
                    {
                        runPan1.SetText(n, wt.ToString("F1"), false);
                    }
                    else
                    {
                        if (wt > WeighNode.MAX_VALID_WEIGHT && wt < 65537)
                        {
                            runPan1.SetText(n, "ERR", false);
                            runPan1.SetStatus("weightnode", n, PanStatus.ERROR, false);
                        }
                    }
                    if (NodeMaster.GetStatus(n) == NodeStatus.ST_LOST || NodeMaster.GetStatus(n) == NodeStatus.ST_DISABLED)
                    {
                        runPan1.SetStatus("weightbar", n, PanStatus.DISBALED, false);
                    }
                    if (NodeMaster.GetStatus(n) == NodeStatus.ST_IDLE)
                    {
                        runPan1.SetStatus("weightbar", n, PanStatus.IDLE, false);
                    }
                }
            }
            UIPacker p = curr_packer;

            if (p.status == PackerStatus.RUNNING)
            {
                lbl_speed.Text        = p.speed.ToString();
                lbl_lastweight.Text   = p.last_pack_weight.ToString("F1");
                lbl_totalpack.Text    = p.total_sim_packs.ToString();
                lbl_totalweights.Text = p.total_sim_weights.ToString("F1");
            }
        }
Example #9
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)
                {
                    NodeMaster.SetNodeReg(naddr, new string[] { "target_weight" }, new UInt32[] { 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 ((NodeMaster.GetStatus(naddr) == NodeStatus.ST_IDLE))
                {
                    double per = avg + (Int32.Parse(naddr.ToString()) - (weight_nodes.Count) / 2) * step;
                    NodeMaster.SetNodeReg(naddr, new string[] { "target_weight" }, new UInt32[] { Convert.ToUInt32(per) });
                }
            }
        }
Example #10
0
        public void UpdateNodeUI(byte n)
        {
            UIPacker pack = curr_packer;

            //display the variable based on current setting
            string err = NodeMaster.GetErrors(n);
            double wt  = -1000;
            string ct  = "";

            if (err == "")
            {
                wt = NodeMaster.GetWeight(n);
                ct = wt.ToString("F1");
                runPan1.SetStatus("passbar", n, PanStatus.IDLE, false);
            }
            else
            {
                if (AlertWnd.b_show_alert && AlertWnd.b_turnon_alert)
                {
                    runPan1.SetStatus("passbar", n, PanStatus.ERROR, false);
                    lbl_status.Text = StringResource.str(err.Substring(0, err.IndexOf(';'))) + "\n";
                    runPan1.SetText(n, StringResource.str(err.Substring(0, err.IndexOf(';'))), false);
                }
            }
            if (NodeMaster.GetStatus(n) == NodeStatus.ST_LOST || NodeMaster.GetStatus(n) == NodeStatus.ST_DISABLED)
            {
                runPan1.SetStatus("weightbar", n, PanStatus.DISBALED, false);
            }
            if (NodeMaster.GetStatus(n) == NodeStatus.ST_IDLE)
            {
                runPan1.SetStatus("weightbar", n, PanStatus.IDLE, false);
            }
            if (wt > -1000 && wt <= WeighNode.MAX_VALID_WEIGHT)
            {
                runPan1.SetText(n, ct, false);
            }
        }
Example #11
0
        public void CheckNodeStatus() //update node status after combination is completed
        {
            double wt;

            foreach (byte addr in packer.weight_nodes)
            {
                if (NodeMaster.GetStatus(addr) == NodeStatus.ST_LOST || NodeMaster.GetStatus(addr) == NodeStatus.ST_DISABLED)
                {
                    continue;
                }
                //no match case
                NodeMaster.IncMatchCount(addr);
                //over_weight check
                wt = NodeMaster.GetWeight(addr);
                double nw = wt;
                if (nw > (packer.curr_cfg.target * 0.66) && (nw <= WeighNode.MAX_VALID_WEIGHT)) //has overweight
                {
                    if (AlertWnd.b_turnon_alert)
                    {
                        NodeMaster.SetOverWeight(addr, true);
                        if (!AlertWnd.b_manual_reset) //auto reset
                        {
                            NodeMaster.Action(new byte[] { addr }, "empty");
                        }
                    }
                    continue;
                }
                else
                {
                    if ((nw > -1000) && (nw <= WeighNode.MAX_VALID_WEIGHT))
                    {
                        NodeMaster.SetOverWeight(addr, false);
                    }
                }
            }
        }
Example #12
0
        private void HitCombineNodeUI(CombineEventArgs ce)
        {
            foreach (byte naddr in Program.packers[ce.packer_id].weight_nodes)
            {
                byte n = naddr;

                double wt = NodeMaster.GetWeight(n);
                if (wt > -1000 && wt <= WeighNode.MAX_VALID_WEIGHT)
                {
                    runPan1.SetText(n, NodeMaster.GetWeight(n).ToString("F1"), false);
                }
                else
                {
                    if (wt > WeighNode.MAX_VALID_WEIGHT && wt < 65537)
                    {
                        runPan1.SetText(n, "ERR", false);
                        runPan1.SetStatus("weightnode", n, PanStatus.ERROR, false);
                    }
                }
                if (!ce.release_addrs.Contains(n))
                {
                    if (NodeMaster.GetStatus(n) == NodeStatus.ST_LOST || NodeMaster.GetStatus(n) == NodeStatus.ST_DISABLED)
                    {
                        runPan1.SetStatus("weightbar", n, PanStatus.DISBALED, false);
                    }
                    else
                    {
                        if (n != curr_packer.vib_addr)
                        {
                            runPan1.SetStatus("weightbar", n, PanStatus.IDLE, false);
                        }
                    }
                    continue;
                }

                if (NodeMaster.GetStatus(n) == NodeStatus.ST_LOST || NodeMaster.GetStatus(n) == NodeStatus.ST_DISABLED)
                {
                    runPan1.SetStatus("weightbar", n, PanStatus.DISBALED, false);
                }
                else
                {
                    if (n != curr_packer.vib_addr)
                    {
                        if (ce.release_addrs.Contains(n))
                        {
                            runPan1.SetStatus("weightbar", n, PanStatus.RELEASE, false);
                        }
                        else
                        {
                            runPan1.SetStatus("weightbar", n, PanStatus.IDLE, false);
                        }
                    }
                }
            }
            UIPacker p = curr_packer;

            if (p.status == PackerStatus.RUNNING)
            {
                lbl_speed.Text        = p.speed.ToString();
                lbl_lastweight.Text   = p.last_pack_weight.ToString("F1");
                lbl_totalpack.Text    = p.total_sim_packs.ToString();
                lbl_totalweights.Text = p.total_sim_weights.ToString("F1");
            }
        }
Example #13
0
        public void Step()
        {
            //phase 0_start, 1_collect weight, 2_comb_release, 3 packer,
            if (phase == 0)
            {
                NodeMaster.ClearWeights(packer.wn_addrs);
                NodeMaster.Action(packer.wn_addrs, "query");
                phase = 10;
                return;
            }
            //collect weight
            if (phase == 10)
            {
                int cnt = packer.wn_addrs.Length;
                foreach (byte addr in packer.wn_addrs)
                {
                    double wt = NodeMaster.GetWeight(addr);
                    if (NodeMaster.GetStatus(addr) != NodeStatus.ST_IDLE)
                    {
                        cnt--;
                        continue;
                    }
                    if (wt > -1000 && wt <= WeighNode.MAX_VALID_WEIGHT)
                    {
                        cnt--;
                    }
                }
                if (cnt <= NodeAgent.LASTCOMB_NUM)
                {
                    phase = 20;
                    return;
                }
                //prepare for next round query
                if (cnt > 0)
                {
                    byte[] addrs = new byte[cnt];
                    //
                    int idx = 0;
                    foreach (byte addr in packer.wn_addrs)
                    {
                        if (NodeMaster.GetStatus(addr) != NodeStatus.ST_IDLE)
                        {
                            continue;
                        }
                        double wt = NodeMaster.GetWeight(addr);
                        if (wt > -1000 && wt <= WeighNode.MAX_VALID_WEIGHT)
                        {
                            continue;
                        }

                        addrs[idx++] = addr;
                    }
                }
                NodeMaster.Action(packer.wn_addrs, "query");
                return;
            }
            if (phase == 20)
            {
                if (packer.status != PackerStatus.RUNNING)
                {
                    phase = 0;
                    return;
                }
                //do simulated combination
                bSimCombine = true;
                foreach (byte b in packer.weight_nodes)
                {
                    bSimNodeValid[b] = true;
                }
                while (CheckCombination())
                {
                    ;
                }
                bSimCombine = false;
                foreach (byte b in packer.weight_nodes)
                {
                    if (!bSimNodeValid[b]) //has a combination
                    {
                        phase = 30;
                    }
                }
                if (phase == 30)
                {
                    ProcessGoonNodes();
                }
                else  //no combination at all
                {
                    while (ProcessGoonNodes())
                    {
                        ;
                    }
                    CheckNodeStatus();
                    phase = 0;
                    return;
                }
            }
            if (phase == 30)
            {
                if (!CheckCombination())
                {
                    phase = 50;
                    return;
                }
                ProcessGoonNodes();
                ReleaseAction(release_addrs, release_weight);
                q_hits.Enqueue(new CombineEventArgs((byte)packer._pack_id, release_addrs, release_wts, release_weight));


                Intf intf_reg = new Intf(Convert.ToUInt16(NodeMaster.GetNodeReg(packer.vib_addr, "target_weight")));
                //if (pack_cnt % (intf_reg.feed_times + 1) != 0)
                //{
                //    phase = 30;
                //    return;
                //}
                {
                    pack_cnt = 0;
                    NodeMaster.Action(new byte[] { packer.vib_addr }, "trigger");
                    ProcessGoonNodes();
                    phase = 40;
                }
            }
            if (phase == 40)
            {
                NodeMaster.RefreshNodeReg(packer.vib_addr, new string[] { "pack_rel_cnt" });
                UInt32 lw_ub = NodeMaster.GetNodeReg(packer.vib_addr, "pack_rel_cnt");
                if (lw_ub != release_cnt)
                {
                    release_cnt     = lw_ub;
                    release_timeout = 0;
                    phase           = 30;
                }
                else
                {
                    if (release_timeout++ > 4)
                    {
                        release_timeout = 0;
                        NodeMaster.Action(new byte[] { packer.vib_addr }, "trigger");
                    }
                    ProcessGoonNodes();
                    return;
                }
            }
            if (phase == 50)
            {
                NodeMaster.Action(new byte[] { packer.vib_addr }, "fill");
                while (ProcessGoonNodes())
                {
                    ;
                }
                CheckNodeStatus();
                phase = 0;
                return;
            }

            //do combination
            //release action
        }
Example #14
0
        private void calibrate(string calreg)
        {
            if (curr_sel == -1)
            {
                return;
            }
            Byte i = Convert.ToByte(curr_sel);

            if (calreg == "cali0")
            {
                if (curr_sel >= 0 && NodeMaster.GetStatus(i) != NodeStatus.ST_LOST)
                {
                    Program.MsgShow(StringResource.str("put_empty"));

                    NodeMaster.RefreshNodeReg(i, new string[] { "cs_mtrl" });
                    UInt32 val = NodeMaster.GetNodeReg(i, "cs_mtrl");
                    if ((val <= WeighNode.MAX_VALID_WEIGHT) && (val > 0))
                    {
                        NodeMaster.SetNodeReg(i, new string[] { "cs_zero" }, new UInt32[] { val });
                        NodeMaster.Action(new byte[] { i }, "flash");
                        Program.MsgShow(StringResource.str("calidone"));
                        label3_MouseLeftButtonUp(null, null);
                    }
                    else
                    {
                        Program.MsgShow(StringResource.str("tryagain"));
                    }
                }
            }
            if (calreg == "empty")
            {
                if (curr_sel >= 0)
                {
                    NodeMaster.Action(new byte[] { i }, "empty");
                }
                return;
            }
            if (calreg == "cali1")
            {
                KbdData(calreg, "20");
            }
            if (calreg == "cali2")
            {
                KbdData(calreg, "50");
            }
            if (calreg == "cali3")
            {
                KbdData(calreg, "100");
            }
            if (calreg == "cali4")
            {
                KbdData(calreg, "200");
            }
            if (calreg == "cali5")
            {
                KbdData(calreg, "300");
            }
            if (calreg == "cali6")
            {
                KbdData(calreg, "400");
            }
            if (calreg == "cali7")
            {
                KbdData(calreg, "500");
            }
            if (calreg == "cali8")
            {
                KbdData(calreg, "700");
            }
            if (calreg == "cali9")
            {
                KbdData(calreg, "900");
            }
            if (calreg == "cali10")
            {
                KbdData(calreg, "1000");
            }
        }
Example #15
0
        public void UpdateDisplay(bool refresh)
        {
            RectButton btn;

            if (b_lockon)
            {
                btn_entersys.SetStyle(Color.Gray, MyButtonType.roundGradientButton);
                btn_locksys.Text = StringResource.str("lockon");
            }
            else
            {
                btn_locksys.SetStyle(Color.LightGreen, MyButtonType.roundGradientButton);
                btn_locksys.Text = StringResource.str("locksystem");
            }
            for (Byte i = 1; i < 18; i++)
            {
                if (i < 17)
                {
                    btn = IdToButton(i.ToString());
                }
                else
                {
                    btn = IdToButton("36");
                }

                if ((NodeMaster.GetErrors(i) != "") || (NodeMaster.GetStatus(i) == NodeStatus.ST_LOST))
                {
                    btn.SetStyle(Color.Gray, MyButtonType.roundButton);
                }
                else
                {
                    if (i == curr_sel || all_sel)
                    {
                        btn.SetStyle(Color.DarkGreen, MyButtonType.round2Button);
                    }
                    else
                    {
                        btn.SetStyle(Color.DarkGreen, MyButtonType.roundButton);
                    }
                }
                btn.Visible = true;
                continue;
            }

            btn_cali0.Text       = StringResource.str("cmd_cali0");
            btn_cali1.Text       = StringResource.str("cmd_cali1");
            btn_cali2.Text       = StringResource.str("cmd_cali2");
            btn_cali3.Text       = StringResource.str("cmd_cali3");
            btn_cali4.Text       = StringResource.str("cmd_cali4");
            btn_cali5.Text       = StringResource.str("cmd_cali5");
            btn_cali6.Text       = StringResource.str("cmd_cali6");
            btn_cali7.Text       = StringResource.str("cmd_cali7");
            btn_cali8.Text       = StringResource.str("cmd_cali8");
            btn_cali9.Text       = StringResource.str("cmd_cali9");
            btn_cali10.Text      = StringResource.str("cmd_cali10");
            btnSave.Text         = StringResource.str("cmd_save");
            btn_empty.Text       = StringResource.str("cmd_empty");
            btn_refreshaddr.Text = StringResource.str("refresh");
            btn_selectall.Text   = StringResource.str("cmd_selectall");
            lbl_title.Text       = StringResource.str("engineerpage");
            lbl_seladdr.Text     = StringResource.str("seladdr");
            lbl_reg.Text         = StringResource.str("setregs");
            btn_changeaddr.Text  = StringResource.str("changeaddr");
            btn_updatefw.Text    = StringResource.str("updatefw");
            btn_refreshaddr.Text = StringResource.str("refresh");
            btn_locksys.Text     = StringResource.str("locksystem");
            btn_entersys.Text    = StringResource.str("entersystem");
            btn_language.Text    = StringResource.str("language");
            btn_refreshreg.Text  = StringResource.str("refresh");
        }