private void calibrate(string calreg) { App p = Application.Current as App; Byte i = Convert.ToByte(curr_sel); if (curr_sel == -1) { return; } if (calreg == "cali0") { NodeAgent n = p.agent; if (curr_sel >= 0) { if (MessageBox.Show(StringResource.str("put_empty"), "", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel) { return; } n.ClearNodeReg(i, "cs_mtrl"); string cs_mtrl_val = n.GetNodeReg(i, "cs_mtrl"); UInt32 val = UInt32.Parse(cs_mtrl_val); if (val <= WeighNode.MAX_VALID_WEIGHT) { n.SetNodeReg(i, "cs_zero", UInt32.Parse(cs_mtrl_val)); n.Action(i, "flash"); MessageBox.Show(StringResource.str("calidone")); label3_MouseLeftButtonUp(null, null); } else { MessageBox.Show(StringResource.str("tryagain")); } } } if (calreg == "empty") { NodeAgent n = p.agent; if (curr_sel >= 0) { n.Action(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"); } //p.WeightAction(i, "query"); //update the readings }
//load all the configuration and update the UI, //packer and sub node will share the same configuration name public void LoadPackConfig(string cfgname, bool init) { if (status == PackerStatus.RUNNING) { return; } pkg_confs.LoadConfig(cfgname); _curr_cfg.FromElement(pkg_confs.Current); foreach (byte n in weight_nodes) { if (init) { nodes_config[n] = new SqlConfig("node" + n);//new XmlConfig(ProdNum.baseDir + "\\node_" + n + ".xml"); nodes_config[n].LoadConfigFromFile(); } nodes_config[n].LoadConfig(cfgname); } if (!nodes_config.ContainsKey(vib_addr)) { if (init) { nodes_config[vib_addr] = new SqlConfig("node" + vib_addr);//new XmlConfig(ProdNum.baseDir + "\\node_" + vib_addr + ".xml"); nodes_config[vib_addr].LoadConfigFromFile(); } nodes_config[vib_addr].LoadConfig(cfgname); } if (!nodes_config.ContainsKey(bot_addr)) { if (init) { nodes_config[bot_addr] = new SqlConfig("node" + bot_addr);//new XmlConfig(ProdNum.baseDir + "\\node_" + bot_addr + ".xml"); nodes_config[bot_addr].LoadConfigFromFile(); } nodes_config[bot_addr].LoadConfig(cfgname); } //download the configuration of node settings foreach (string reg in new string[] { "magnet_freq", "magnet_amp", "magnet_time", "target_weight", "cs_filter" }) { try { agent.SetNodeReg(vib_addr, reg, UInt32.Parse(nodes_config[vib_addr].Current.Element(reg).Value)); }catch { } } if (bot_addr != vib_addr) { foreach (string reg in new string[] { "magnet_freq", "magnet_amp", "magnet_time", "target_weight", "cs_filter" }) { try { agent.SetNodeReg(bot_addr, reg, UInt32.Parse(nodes_config[bot_addr].Current.Element(reg).Value)); } catch { } } } foreach (byte n in weight_nodes) { foreach (string reg in new string[] { "magnet_freq", "magnet_amp", "magnet_time", "motor_speed", "cs_filter", "cs_gain_wordrate", "delay_f", "delay_w", "delay_s", "open_s", "open_w", "target_weight" }) { try { agent.SetNodeReg(n, reg, UInt32.Parse(nodes_config[n].Current.Element(reg).Value)); }catch { } } } }
public void KbdData(string param, string data) { App p = Application.Current as App; XElement cfg = p.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); 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; (Application.Current as App).runwnd.Disable(Visibility.Visible); (Application.Current as App).singlewnd.Disable(Visibility.Visible); 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); p.SaveAppConfig(); b_lockon = true; UpdateDisplay(false); } if (param.IndexOf("reg_") == 0) { Button btn; SubNode n = null; if (curr_sel == -1) { return; } Byte i = Convert.ToByte(curr_sel); if (i < 17) { btn = IdToButton(i.ToString()); n = p.agent[i]; } else { btn = IdToButton("36"); n = p.agent.missingnode; } if (n["addr"] != null) { param = param.Remove(0, 4); n[param] = UInt32.Parse(data); Thread.Sleep(1000); btn_refreshreg_Click(null, null); } } if (param.IndexOf("chgnd_") == 0) { Byte oldaddr = Byte.Parse(param.Remove(0, 6)); Byte newaddr = Byte.Parse(data); Button btn = IdToButton(newaddr.ToString()); if (btn != null && newaddr < 36) //valid new address { if (btn.Visibility != Visibility.Visible) { SubNode oldn; SubNode newn; if (oldaddr == 36) { oldn = p.agent.missingnode; } else { oldn = p.agent[oldaddr]; } newn = p.agent[newaddr]; newaddr += 0xC0; newn.status = NodeStatus.ST_IDLE; oldn["test_mode_reg2"] = newaddr; Thread.Sleep(500); newn.status = NodeStatus.ST_IDLE; newn["addr"] = null; oldn.status = NodeStatus.ST_LOST; Thread.Sleep(100); if (newn["addr"].HasValue) { MessageBox.Show(StringResource.str("change_addr_success")); return; } } } MessageBox.Show(StringResource.str("change_addr_fail")); } if (param != "cali0" && (param.IndexOf("cali") == 0)) //cali1 to cali10 { string msg = StringResource.str("put_poise") + "(" + data + StringResource.str("gram") + ")"; if (MessageBox.Show(msg, "", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel) { return; } NodeAgent n = p.agent; int i = RunMode.StringToId(param) - 1; if (curr_sel >= 0) { n.ClearNodeReg((byte)curr_sel, "cs_mtrl"); string cs_mtrl_val = n.GetNodeReg((byte)curr_sel, "cs_mtrl"); UInt32 val; if (UInt32.TryParse(cs_mtrl_val, out val)) { if (val <= WeighNode.MAX_VALID_WEIGHT) { if (i < 5) { n.SetNodeReg((byte)curr_sel, "poise_weight_gram" + i.ToString(), UInt32.Parse(cs_mtrl_val)); } else { n.SetNodeReg((byte)curr_sel, "cs_poise" + (i - 5).ToString(), UInt32.Parse(cs_mtrl_val)); } n.Action((byte)curr_sel, "flash"); MessageBox.Show(StringResource.str("calidone")); label3_MouseLeftButtonUp(null, null); return; } } MessageBox.Show(StringResource.str("tryagain")); } return; } }
public void KbdData(string param, string data) { //update the display based on keyboard input App p = Application.Current as App; bool bNeedUpdateComb = false; //whether target weight of each node is required try { UIPacker pack = curr_packer; NodeAgent n = curr_packer.agent; if (param == "sub_freq_input") { n.SetNodeReg((byte)curr_node_index, "magnet_freq", UInt32.Parse(data)); apply_regs.Insert(0, "magnet_freq"); } if (param == "sub_amp_input") { n.SetNodeReg((byte)curr_node_index, "magnet_amp", UInt32.Parse(data)); apply_regs.Insert(0, "magnet_amp"); } if (param == "sub_time_input") { n.SetNodeReg((byte)curr_node_index, "magnet_time", UInt32.Parse(data)); apply_regs.Insert(0, "magnet_time"); } if (param == "sub_filter_input") { n.SetNodeReg((byte)curr_node_index, "cs_gain_wordrate", UInt32.Parse(data)); apply_regs.Insert(0, "cs_gain_wordrate"); } if (param == "wei_otime_input") { n.SetNodeReg((byte)curr_node_index, "open_w", UInt32.Parse(data)); apply_regs.Insert(0, "open_w"); } if (param == "wei_dtime_input") { n.SetNodeReg((byte)curr_node_index, "delay_w", UInt32.Parse(data)); apply_regs.Insert(0, "delay_w"); } if (param == "col_dtime_input") { n.SetNodeReg((byte)curr_node_index, "delay_s", UInt32.Parse(data)); apply_regs.Insert(0, "delay_s"); } if (param == "col_otime_input") { n.SetNodeReg((byte)curr_node_index, "open_s", UInt32.Parse(data)); apply_regs.Insert(0, "open_s"); } if (param == "openwei_input") { n.SetNodeReg((byte)curr_node_index, "delay_f", UInt32.Parse(data)); apply_regs.Insert(0, "delay_f"); } if (param == "motor_speed_input") { n.SetNodeReg((byte)curr_node_index, "motor_speed", UInt32.Parse(data)); apply_regs.Insert(0, "motor_speed"); } if (param == "run_freq") { n.SetNodeReg(curr_packer.vib_addr, "magnet_freq", UInt32.Parse(data)); } if (param == "run_time") { n.SetNodeReg(curr_packer.vib_addr, "magnet_time", UInt32.Parse(data)); } if (param == "run_amp") { n.SetNodeReg(curr_packer.vib_addr, "magnet_amp", UInt32.Parse(data)); } if (param == "autoamp") { curr_packer.curr_cfg.target_comb = Double.Parse(data); cb_autoamp.IsChecked = (curr_packer.curr_cfg.target_comb > 1); bNeedUpdateComb = true; } if (param == "target") { curr_packer.curr_cfg.target = Double.Parse(data); bNeedUpdateComb = true; } if (param == "uvar") { curr_packer.curr_cfg.upper_var = Double.Parse(data); } if (param == "dvar") { curr_packer.curr_cfg.lower_var = Double.Parse(data); } ShowStatus("modifying"); if (bNeedUpdateComb) { curr_packer.UpdateEachNodeTarget(); } lastcall = "UpdateUI"; } catch (System.Exception e) { //MessageBox.Show("Invalid Parameter"); return; } }