예제 #1
0
        static public void MessageHandler()
        {
            while (true)
            {
                if (!WaitEvent.WaitOne(10, false))
                {
                    agent.ScanPort();
                    continue;
                }
                WaitEvent.Reset();
                try
                {
                    ActMessage msg = NodeMaster.actmsg;

                    #region write_regs
                    if ((msg.action == "write_regs") && (msg.addrs.GetLength(0) == 1)) //only reg of one node is allowed
                    {
                        byte addr = msg.addrs[0];
                        if (agent[addr].status == NodeStatus.ST_IDLE)
                        {
                            agent[addr].write_vregs(msg.regs, msg.values);
                        }
                        actmsg.action = "done";
                        OverEvent.Set();
                        continue;
                    }
                    #endregion
                    #region actions
                    if ((msg.action == "fill") || (msg.action == "zero") || (msg.action == "empty") ||
                        (msg.action == "pass") || (msg.action == "pass"))
                    {
                        foreach (byte addr in msg.addrs)
                        {
                            if (agent[addr].status == NodeStatus.ST_IDLE)
                            {
                                agent[addr].write_vregs(new string[] { "flag_enable" }, new UInt32[] { NodeMaster.flag_cmd(msg.action) });
                            }
                        }
                        actmsg.action = "done";
                        OverEvent.Set();
                        continue;
                    }
                    if (msg.action == "flag_goon")
                    {
                        foreach (byte addr in msg.addrs)
                        {
                            if (agent[addr].status == NodeStatus.ST_IDLE)
                            {
                                agent[addr].write_vregs(new string[] { "flag_goon" }, new UInt32[] { 1 });
                            }
                        }
                        actmsg.action = "done";
                        OverEvent.Set();
                        continue;
                    }
                    #endregion
                    #region refresh_regs
                    if ((msg.action == "refresh_regs") && (msg.addrs.GetLength(0) == 1))
                    {
                        if (agent[msg.addrs[0]] is SubNode)
                        {
                            GetRegister(msg.addrs[0], msg.regs);
                            OverEvent.Set();
                            continue;
                        }
                    }
                    #endregion
                    #region flag_release
                    if (msg.action == "flag_release")
                    {
                        if (!CriticalFlag(msg.addrs, "flag_release", 1))
                        {
                            msg.action = "fail";
                        }
                        else
                        {
                            foreach (byte n in msg.addrs)
                            {
                                if (agent[n] is WeighNode)
                                {
                                    (agent[n] as WeighNode).cnt_match = -1;
                                }
                            }
                            msg.action = "done";
                        }
                        OverEvent.Set();
                        continue;
                    }
                    #endregion
                    #region flash
                    if (msg.action == "flash")
                    {
                        msg.action = "done";
                        foreach (byte addr in msg.addrs)
                        {
                            if (agent[addr].status == NodeStatus.ST_IDLE)
                            {
                                agent[addr].write_vregs(new string[] { "NumOfDataToBePgmed" }, new UInt32[] { 45 });
                                int retry = 20;
                                do
                                {
                                    Thread.Sleep(200);
                                    if (GetRegister(addr, new string[] { "NumOfDataToBePgmed" }))
                                    {
                                        if (agent[addr]["NumOfDataToBePgmed"] == 0)
                                        {
                                            break;
                                        }
                                    }
                                } while (retry-- > 0);
                                if (retry <= 0)
                                {
                                    msg.action = "retry";
                                }
                            }
                        }
                        OverEvent.Set();
                        continue;
                    }
                    #endregion
                    #region start stop trigger
                    if ((msg.action == "stop") || (msg.action == "start") || (msg.action == "trigger") || (msg.action == "intf"))
                    {
                        if (!CriticalFlag(msg.addrs, "flag_enable", NodeMaster.flag_cmd(msg.action)))
                        {
                            msg.action = "retry";
                        }
                        else
                        {
                            if ((msg.action == "stop") || (msg.action == "start"))
                            {
                                foreach (byte n in msg.addrs)
                                {
                                    if (agent[n] is WeighNode)
                                    {
                                        (agent[n] as WeighNode).cnt_match = -1;
                                    }
                                }
                            }
                            msg.action = "done";
                        }
                        OverEvent.Set();
                        continue;
                    }
                    #endregion
                    #region query
                    if (msg.action == "query")
                    {
                        foreach (byte addr in msg.addrs)
                        {
                            if (agent[addr].status == NodeStatus.ST_IDLE)
                            {
                                GetRegister(addr, new string[] { "mtrl_weight_gram", "mtrl_weight_decimal" });
                            }
                        }
                        actmsg.action = "done";
                        OverEvent.Set();
                        continue;
                    }
                    #endregion
                    throw new Exception("Invalide commnad " + actmsg.action);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    actmsg.action = "fail";
                    OverEvent.Set();
                }
            }
        }
예제 #2
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     NodeMaster.SetNodeReg((byte)curr_sel, new string[] { "flag_enable" }, new UInt32[] { 14 });
     Program.MsgShow(StringResource.str("done"));
 }
예제 #3
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");
            }
        }
예제 #4
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;
            }
        }
예제 #5
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");
        }
예제 #6
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);
            }
        }