private void btn_refreshreg_Click(object sender, EventArgs e) { RectButton btn; SubNode n = null; if (curr_sel == -1) { return; } Byte i = Convert.ToByte(curr_sel); if (i < 17) { btn = IdToButton(i.ToString()); } else { btn = IdToButton("36"); } reg_dt.Rows.Clear(); foreach (string rtkey in SubNode.reg_type_tbl.Keys) { NodeMaster.RefreshNodeReg(i, new string[] { rtkey }); DataRow dr = reg_dt.NewRow(); dr[0] = rtkey; dr[1] = SubNode.reg_type_tbl[rtkey].pos.ToString(); dr[2] = NodeMaster.GetNodeReg(i, rtkey).ToString(); dr[3] = NodeMaster.GetNodeReg(i, rtkey).ToString("X"); reg_dt.Rows.Add(dr); } return; }
public void UpdateUI() { byte vn = curr_packer.vib_addr; if (curr_node_index < 0) { return; } sub_freq_input.Text = NodeMaster.GetNodeReg((byte)curr_node_index, "magnet_freq").ToString(); sub_amp_input.Text = NodeMaster.GetNodeReg((byte)curr_node_index, "magnet_amp").ToString(); sub_time_input.Text = NodeMaster.GetNodeReg((byte)curr_node_index, "magnet_time").ToString(); sub_filter_input.Text = NodeMaster.GetNodeReg((byte)curr_node_index, "cs_gain_wordrate").ToString(); wei_otime_input.Text = NodeMaster.GetNodeReg((byte)curr_node_index, "open_w").ToString(); wei_dtime_input.Text = NodeMaster.GetNodeReg((byte)curr_node_index, "delay_w").ToString(); col_dtime_input.Text = NodeMaster.GetNodeReg((byte)curr_node_index, "delay_s").ToString(); col_otime_input.Text = NodeMaster.GetNodeReg((byte)curr_node_index, "open_s").ToString(); openwei_input.Text = NodeMaster.GetNodeReg((byte)curr_node_index, "delay_f").ToString(); motor_speed_input.Text = NodeMaster.GetNodeReg((byte)curr_node_index, "motor_speed").ToString(); run_freq.Text = NodeMaster.GetNodeReg(curr_packer.vib_addr, "magnet_freq").ToString(); run_amp.Text = NodeMaster.GetNodeReg(curr_packer.vib_addr, "magnet_amp").ToString(); run_time.Text = NodeMaster.GetNodeReg(curr_packer.vib_addr, "magnet_time").ToString(); btn_prd_no.Text = curr_packer.curr_cfg.product_no.ToString(); btn_prd_desc.Text = curr_packer.curr_cfg.product_desc.ToString(); btn_target.Text = curr_packer.curr_cfg.target.ToString() + StringResource.str("gram"); btn_uvar.Text = curr_packer.curr_cfg.upper_var.ToString() + StringResource.str("gram"); btn_dvar.Text = curr_packer.curr_cfg.lower_var.ToString() + StringResource.str("gram"); cb_autoamp.Checked = (curr_packer.curr_cfg.target_comb > 0); if (cb_autoamp.Checked) { cb_autoamp.Text = StringResource.str("autoamp_on") + curr_packer.curr_cfg.target_comb.ToString(); } else { cb_autoamp.Text = StringResource.str("autoamp_off"); } lbl_node.Text = StringResource.str("bucketsetting") + "(" + (curr_node_index).ToString() + ")"; //load the corresponding pictiure. string path_to_jpg; path_to_jpg = ProdNum.baseDir + "\\prodpic\\" + StringResource.language + "\\" + this.curr_packer.curr_cfg.product_desc.ToString() + ".jpg"; if (!File.Exists(path_to_jpg)) { path_to_jpg = ProdNum.baseDir + "\\prodpic\\default.jpg"; } prdBmp = new Bitmap(path_to_jpg); ellipseWithImageBrush.Image = (Image)prdBmp; }
private void UpdateData() { vib_intf.buf = Convert.ToUInt16(NodeMaster.GetNodeReg(curr_packer.bot_addr, "target_weight")); intf_ckb_mem.Checked = vib_intf.b_Hasmem; intf_handshake.Checked = vib_intf.b_Handshake; intf_ckb_delay.Text = vib_intf.delay_length.ToString(); intf_lb_feed_times.Text = (vib_intf.feed_times + 1).ToString(); intf_input_trigger.SelectedIndex = vib_intf.fmt_input; intf_output_trigger.SelectedIndex = vib_intf.fmt_output; intf_pulse_width.Text = NodeMaster.GetNodeReg(curr_packer.bot_addr, "cs_filter").ToString(); }
private byte poll(string reg, byte quitval) { byte uc = quitval; byte timeout; do { NodeMaster.RefreshNodeReg(node, new string[] { reg }); uc = Convert.ToByte(NodeMaster.GetNodeReg(node, reg)); } while (uc == quitval); return(uc); }
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(); }
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 }
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"); } }
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; } }
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); } }