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; }
private void label3_MouseLeftButtonUp(object sender, EventArgs e) { if (curr_sel == -1) { return; } Byte i = Convert.ToByte(curr_sel); NodeMaster.RefreshNodeReg(i, new string[] { "mtrl_weight_gram", "mtrl_weight_decimal" }); lbl_weight.Text = NodeMaster.GetWeight(i).ToString("F2"); }
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); }
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; } }