Esempio n. 1
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);
 }
Esempio n. 2
0
        private void btn_action_Click(object sender, EventArgs e)
        {
            byte   n    = (byte)curr_node_index;
            string name = (sender as RectButton).Name;

            if (curr_packer.status == PackerStatus.RUNNING)
            {
                //Program.MsgShow("is_running");
                return;
            }

            if (name == "btn_mainvib")
            {
                NodeMaster.Action(new byte[] { curr_packer.bot_addr }, "fill");
            }
            if (name == "btn_pack")
            {
                NodeMaster.Action(new byte[] { curr_packer.bot_addr }, "trigger");
            }
            if (name == "btn_pass" || name == "btn_empty" || name == "btn_fill" || name == "btn_flash" || name == "btn_zero")
            {
                if (!runPan1.bSelectAll)
                {
                    NodeMaster.Action(new byte[] { n }, name.Replace("btn_", ""));
                }
                else
                {
                    NodeMaster.Action(curr_packer.wn_addrs, name.Replace("btn_", ""));
                }
            }
        }
Esempio n. 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);
     }
 }
Esempio n. 4
0
 //send group command
 private void group_action(string action)
 {
     if (curr_packer.status == PackerStatus.PAUSED || curr_packer.status == PackerStatus.RUNNING)
     {
         return;
     }
     NodeMaster.Action(curr_packer.wn_addrs, action);
 }
Esempio n. 5
0
 public void StartRun()
 {
     rStart = DateTime.Now;
     ProdHistory.InitNewRun(this);
     nc.Start();
     NodeMaster.Action(this.wn_addrs, "start");
     NodeMaster.Action(new byte[] { this.bot_addr }, "start");
     status = PackerStatus.RUNNING;
 }
Esempio n. 6
0
 private void button1_Click(object sender, EventArgs e)
 {
     //full time run , internal function only
     NodeMaster.Action(curr_packer.wn_addrs, "start");
     while (true)
     {
         Thread.Sleep(500);
         NodeMaster.Action(curr_packer.wn_addrs, "fill");
         Thread.Sleep(500);
         NodeMaster.Action(curr_packer.wn_addrs, "pass");
         Thread.Sleep(1000);
         NodeMaster.Action(curr_packer.wn_addrs, "empty");
         Thread.Sleep(500);
         NodeMaster.Action(new byte[] { curr_packer.bot_addr }, "fill");
     }
 }
Esempio n. 7
0
        public void StopRun()
        {
            NodeMaster.Action(new byte[] { this.bot_addr }, "stop");
            NodeMaster.Action(this.wn_addrs, "stop");
            Thread.Sleep(300);
            nc.Stop(100);
            status = PackerStatus.IDLE;

            if (!bSimulate)
            {
                ProdHistory.UpdateRecord(this);
                ResetHistory();
            }
            else
            {
                total_sim_packs   = 0;
                total_sim_weights = 0;
            }
        }
Esempio n. 8
0
        private void ApplySetting()
        {
            UInt16 delay = UInt16.Parse(intf_ckb_delay.Text.ToString());

            if (intf_input_trigger.SelectedIndex < 0 || intf_output_trigger.SelectedIndex < 0)
            {
                return;
            }
            vib_intf.b_Hasdelay   = (delay > 0);
            vib_intf.b_Hasmem     = intf_ckb_mem.Checked;
            vib_intf.b_Handshake  = intf_handshake.Checked;
            vib_intf.delay_length = delay;
            vib_intf.feed_times   = Convert.ToUInt16(UInt16.Parse(intf_lb_feed_times.Text.ToString()) - 1);
            vib_intf.fmt_input    = Convert.ToUInt16(intf_input_trigger.SelectedIndex);
            vib_intf.fmt_output   = Convert.ToUInt16(intf_output_trigger.SelectedIndex);
            NodeMaster.SetNodeReg(this.curr_packer.bot_addr, new string[] { "target_weight", "cs_filter" }, new UInt32[] { vib_intf.buf, Convert.ToUInt16(intf_pulse_width.Text) });
            NodeMaster.Action(new byte[] { this.curr_packer.bot_addr }, "intf");

            UpdateData();
        }
Esempio n. 9
0
        private void ReleaseAction(byte[] addrs, double weight)
        {
            string log = weight.ToString("F2") + "\t";

            log = weight.ToString("F2") + "\t";

            foreach (byte n in addrs)
            {
                log = log + String.Format("({0}){1}\t", n, NodeMaster.GetWeight(n));

                while (true)
                {
                    try
                    {
                        NodeMaster.Action(new byte[] { n }, "flag_release");
                        break;
                    }
                    catch
                    {
                        Program.MsgShow(StringResource.str("tryagain"));
                    }
                }
            }
            NodeMaster.HitMatch(addrs);
            StringResource.dolog(log);

            onepack o = new onepack();

            o.bucket    = new byte[5];
            o.bucket[1] = o.bucket[2] = o.bucket[3] = o.bucket[4] = o.bucket[0] = (byte)0;
            int i = 0;

            foreach (byte n in addrs)
            {
                o.bucket[i++] = n;
            }
            o.time   = DateTime.Now;
            o.weight = weight;
            packer.AddNewPack(o);
        }
Esempio n. 10
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);
                    }
                }
            }
        }
Esempio n. 11
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
        }
Esempio n. 12
0
 private void btn_run_Click(object sender, EventArgs e)
 {
     NodeMaster.Action(new byte[] { curr_packer.bot_addr }, "trigger");
 }
Esempio n. 13
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");
            }
        }
Esempio n. 14
0
        public void KbdData(string param, string data)
        {
            XElement cfg = Program.curr_cfg;

            if (param == "entersys")
            {
                if (Password.compare_pwd("admin", data))
                {
                    Process app = new Process();
                    app.StartInfo.FileName  = "Explorer.exe";
                    app.StartInfo.Arguments = "";
                    app.Start();
                    Thread.Sleep(2000);
                    Program.kbdwnd.Hide();
//                    Type shellType = Type.GetTypeFromProgID("Shell.Application");
//                    object shellObject = System.Activator.CreateInstance(shellType);
//                    shellType.InvokeMember("ToggleDesktop", System.Reflection.BindingFlags.InvokeMethod, null, shellObject, null);
                }

                return;
            }
            if (param == "quitlock")
            {
                if (Password.compare_pwd("lock", data))
                {
                    b_lockon = false;
                    Password.set_pwd("lock", "0");
                    b_lockon = false;
                    Program.runwnd.Disable(true);
                    Program.singlewnd.Disable(true);
                    UpdateDisplay(true);
                }
            }
            if (param == "enterlock")
            {
                //App should expire after desired packer number reached , data is the actual packer count
                Password.set_pwd("lock_on", data);
                DeleteRegist("lock_on");
                WTRegedit("lock_on", data);
                Password.set_pwd("lock", data);
                Program.SaveAppConfig();
                b_lockon = true;
                UpdateDisplay(false);
            }
            if (param.IndexOf("reg_") == 0)
            {
                SubNode n = null;
                if (curr_sel == -1)
                {
                    return;
                }
                Byte i = Convert.ToByte(curr_sel);
                NodeMaster.SetNodeReg(i, new string[] { param.Remove(0, 4) }, new UInt32[] { UInt32.Parse(data) });

                btn_refreshreg_Click(null, null);
            }
            if (param.IndexOf("chgnd_") == 0)
            {
                Byte oldaddr = Byte.Parse(param.Remove(0, 6));
                Byte newaddr = Byte.Parse(data);
                NodeMaster.ChangeAddress(oldaddr, newaddr);
            }
            if (param != "cali0" && (param.IndexOf("cali") == 0)) //cali1 to cali10
            {
                string msg = StringResource.str("put_poise") + "(" + data + StringResource.str("gram") + ")";

                Program.MsgShow(msg);
                int i = RunModeWnd.StringToId(param) - 1;
                if (curr_sel >= 0)
                {
                    NodeMaster.RefreshNodeReg((byte)curr_sel, new string[] { "cs_mtrl" });
                    UInt32 cs_mtrl_val = NodeMaster.GetNodeReg((byte)curr_sel, "cs_mtrl");
                    if (cs_mtrl_val <= WeighNode.MAX_VALID_WEIGHT)
                    {
                        if (i < 5)
                        {
                            NodeMaster.SetNodeReg((byte)curr_sel, new string[] { "poise_weight_gram" + i.ToString() }, new UInt32[] { cs_mtrl_val });
                        }
                        else
                        {
                            NodeMaster.SetNodeReg((byte)curr_sel, new string[] { "cs_poise" + (i - 5).ToString() }, new UInt32[] { cs_mtrl_val });
                        }
                        NodeMaster.Action(new byte[] { (byte)curr_sel }, "flash");
                        Program.MsgShow(StringResource.str("calidone"));
                        label3_MouseLeftButtonUp(null, null);
                        return;
                    }
                    Program.MsgShow(StringResource.str("tryagain"));
                }
                return;
            }
        }
Esempio n. 15
0
        public void PackerBoot()
        {
            try
            {
                UpdateMessage("App Version: " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + "\r\n");
                //search for nodes
                //UpdateMessage(StringResource.str("search_newnode"));
//                NodeMaster.SearchNode(byte.Parse(Program.curr_cfg.Element("def_addr").Value));

                boot_ok = 0;
                int tryfound;
                //check the availability of each board
                foreach (UIPacker pk in Program.packers)
                {
                    foreach (byte n in pk.weight_nodes)
                    {
                        if ((n % 4) == 3)
                        {
                            UpdateMessage("\r\n");
                        }
                        tryfound = 3;
                        while (!NodeMaster.SearchNode(n) && (tryfound > 0))
                        {
                            Thread.Sleep(500);
                            tryfound--;
                        }
                        if (tryfound <= 0)
                        {
                            UpdateMessage(StringResource.str("search_node") + n + StringResource.str("fail") + "\t\t");
                            Program.engwnd.btn_updatefw_Click(null, null);
                        }
                        else
                        {
                            boot_ok++;
                            UpdateMessage(n + ": ver " + NodeMaster.GetNodeReg(n, "fw_rev_uw").ToString() + "\t\t");
                        }
                    }
                    byte nvib = pk.vib_addr;
                    tryfound = 3;
                    while ((!NodeMaster.SearchNode(nvib)) && (tryfound > 0))
                    {
                        Thread.Sleep(500);
                        tryfound--;
                    }
                    if (tryfound <= 0)
                    {
                        UpdateMessage(StringResource.str("search_node") + nvib + StringResource.str("fail") + "\t\t");
                    }
                    else
                    {
                        boot_ok++;
                        UpdateMessage(nvib + ": ver " + NodeMaster.GetNodeReg(nvib, "fw_rev_uw").ToString() + "\t\t");
                    }
                    Thread.Sleep(2000);
                    if (boot_ok > 0)
                    {
                        //load config for node
                        UpdateMessage("\r\n" + StringResource.str("init_nodereg"));
                        //todo
                        pk.LoadPackConfig(pk.pkg_confs.cfg_name, true);
                        NodeMaster.Action(new byte[] { pk.vib_addr }, "intf");
                        NodeMaster.Action(pk.wn_addrs, "stop");
                        NodeMaster.Action(new byte[] { pk.vib_addr }, "stop");
                    }
                }
            }
            catch (Exception ex)
            {
                UpdateMessage(ex.Message);
                boot_ok = 0;
                Thread.Sleep(3000);
            }
        }