private bool Caculation2() { double sum = 0; for (int i = 0; i < packer.weight_nodes.Count - 1; i++) { if (CacuInvalidNode(i)) { continue; } for (int j = i + 1; j < packer.weight_nodes.Count; j++) { if (CacuInvalidNode(j)) { continue; } sum = NodeMaster.GetWeight(packer.weight_nodes[i]) + NodeMaster.GetWeight(packer.weight_nodes[j]); if (sum > dvar && sum < uvar) { DoRelease(new byte[] { packer.weight_nodes[i], packer.weight_nodes[j] }, sum); return(true); } } } return(false); }
private Dictionary <byte, bool> bSimNodeValid; //array used to store the state of each node in simulation mode; private bool CacuInvalidNode(int i) { if (NodeMaster.GetStatus(packer.weight_nodes[i]) == NodeStatus.ST_LOST) { return(true); } if (NodeMaster.GetStatus(packer.weight_nodes[i]) == NodeStatus.ST_DISABLED) { return(true); } if ((bSimCombine) && (!bSimNodeValid[packer.weight_nodes[i]])) { return(true); } double wt = NodeMaster.GetWeight(packer.weight_nodes[i]); if (wt <= llim) { return(true); } if (wt < 0) { return(true); } if (wt > WeighNode.MAX_VALID_WEIGHT) { return(true); } return(false); }
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); }
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 bool Caculation5() { double sum = 0; for (int i = 0; i < packer.weight_nodes.Count - 4; i++) { if (CacuInvalidNode(i)) { continue; } for (int j = i + 1; j < packer.weight_nodes.Count - 3; j++) { if (CacuInvalidNode(j)) { continue; } for (int k = j + 1; k < packer.weight_nodes.Count - 2; k++) { if (CacuInvalidNode(k)) { continue; } for (int l = k + 1; l < packer.weight_nodes.Count - 1; l++) { if (CacuInvalidNode(l)) { continue; } for (int m = l + 1; m < packer.weight_nodes.Count; m++) { if (CacuInvalidNode(m)) { continue; } sum = NodeMaster.GetWeight(packer.weight_nodes[i]) + NodeMaster.GetWeight(packer.weight_nodes[j]) + NodeMaster.GetWeight(packer.weight_nodes[k]) + NodeMaster.GetWeight(packer.weight_nodes[l]) + NodeMaster.GetWeight(packer.weight_nodes[m]); if (sum > dvar && sum < uvar) { DoRelease(new byte[] { packer.weight_nodes[i], packer.weight_nodes[j], packer.weight_nodes[k], packer.weight_nodes[l], packer.weight_nodes[m] }, sum); return(true); } } } } } } return(false); }
public void RefreshRunNodeUI() //node ui update at run time { lbl_status.Text = ""; foreach (UIPacker pk in Program.packers) { foreach (byte naddr in pk.weight_nodes) { string param = "wei_node" + naddr.ToString(); byte n = (byte)(RunModeWnd.StringToId(param)); NodeCombination nc = pk.nc; double wt = NodeMaster.GetWeight(n); if (wt > -1000 && wt <= WeighNode.MAX_VALID_WEIGHT) { runPan1.SetText(n, wt.ToString("F1"), false); } if (NodeMaster.GetStatus(n) == NodeStatus.ST_LOST || NodeMaster.GetStatus(n) == NodeStatus.ST_DISABLED) { runPan1.SetStatus("weightbar", n, PanStatus.ERROR, false); } string err = NodeMaster.GetErrors(n); if (err != "" && AlertWnd.b_turnon_alert && AlertWnd.b_show_alert) { lbl_status.Text = n.ToString() + ":" + StringResource.str(err.Substring(0, err.IndexOf(';'))) + "\n"; } } if (pk.status == PackerStatus.RUNNING) { lbl_speed.Text = pk.speed.ToString(); lbl_lastweight.Text = pk.last_pack_weight.ToString("F1"); lbl_totalpack.Text = pk.total_packs.ToString(); RefreshVibUI(); } } if (lbl_status.Text.ToString() == "") { lbl_status.Text = StringResource.str("normal"); lbl_status.ForeColor = Color.Green; } else { lbl_status.ForeColor = Color.Red; if (AlertWnd.b_turnon_alert && AlertWnd.b_stop_onalert && (curr_packer.status == PackerStatus.RUNNING)) { btn_start_click(null, null); } } runPan1.ReDraw(); }
private void DoRelease(byte[] addrs, double weight) { if (bSimCombine) { foreach (byte addr in addrs) { bSimNodeValid[addr] = false; } } else { release_addrs = addrs; release_weight = weight; release_wts = new double[addrs.Length]; for (int i = 0; i < release_wts.Length; i++) { release_wts[i] = NodeMaster.GetWeight(addrs[i]); } } }
private void RefreshNodeUI() { foreach (UIPacker pk in Program.packers) { foreach (byte naddr in pk.weight_nodes) { byte n = naddr; double wt = NodeMaster.GetWeight(n); if (wt > -1000 && wt <= WeighNode.MAX_VALID_WEIGHT) { runPan1.SetText(n, wt.ToString("F1"), false); } else { if (wt > WeighNode.MAX_VALID_WEIGHT && wt < 65537) { runPan1.SetText(n, "ERR", false); runPan1.SetStatus("weightnode", n, PanStatus.ERROR, false); } } if (NodeMaster.GetStatus(n) == NodeStatus.ST_LOST || NodeMaster.GetStatus(n) == NodeStatus.ST_DISABLED) { runPan1.SetStatus("weightbar", n, PanStatus.DISBALED, false); } if (NodeMaster.GetStatus(n) == NodeStatus.ST_IDLE) { runPan1.SetStatus("weightbar", n, PanStatus.IDLE, false); } } } UIPacker p = curr_packer; if (p.status == PackerStatus.RUNNING) { lbl_speed.Text = p.speed.ToString(); lbl_lastweight.Text = p.last_pack_weight.ToString("F1"); lbl_totalpack.Text = p.total_sim_packs.ToString(); lbl_totalweights.Text = p.total_sim_weights.ToString("F1"); } }
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); }
public void UpdateNodeUI(byte n) { UIPacker pack = curr_packer; //display the variable based on current setting string err = NodeMaster.GetErrors(n); double wt = -1000; string ct = ""; if (err == "") { wt = NodeMaster.GetWeight(n); ct = wt.ToString("F1"); runPan1.SetStatus("passbar", n, PanStatus.IDLE, false); } else { if (AlertWnd.b_show_alert && AlertWnd.b_turnon_alert) { runPan1.SetStatus("passbar", n, PanStatus.ERROR, false); lbl_status.Text = StringResource.str(err.Substring(0, err.IndexOf(';'))) + "\n"; runPan1.SetText(n, StringResource.str(err.Substring(0, err.IndexOf(';'))), false); } } if (NodeMaster.GetStatus(n) == NodeStatus.ST_LOST || NodeMaster.GetStatus(n) == NodeStatus.ST_DISABLED) { runPan1.SetStatus("weightbar", n, PanStatus.DISBALED, false); } if (NodeMaster.GetStatus(n) == NodeStatus.ST_IDLE) { runPan1.SetStatus("weightbar", n, PanStatus.IDLE, false); } if (wt > -1000 && wt <= WeighNode.MAX_VALID_WEIGHT) { runPan1.SetText(n, ct, false); } }
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); } } } }
private void HitCombineNodeUI(CombineEventArgs ce) { foreach (byte naddr in Program.packers[ce.packer_id].weight_nodes) { byte n = naddr; double wt = NodeMaster.GetWeight(n); if (wt > -1000 && wt <= WeighNode.MAX_VALID_WEIGHT) { runPan1.SetText(n, NodeMaster.GetWeight(n).ToString("F1"), false); } else { if (wt > WeighNode.MAX_VALID_WEIGHT && wt < 65537) { runPan1.SetText(n, "ERR", false); runPan1.SetStatus("weightnode", n, PanStatus.ERROR, false); } } if (!ce.release_addrs.Contains(n)) { if (NodeMaster.GetStatus(n) == NodeStatus.ST_LOST || NodeMaster.GetStatus(n) == NodeStatus.ST_DISABLED) { runPan1.SetStatus("weightbar", n, PanStatus.DISBALED, false); } else { if (n != curr_packer.vib_addr) { runPan1.SetStatus("weightbar", n, PanStatus.IDLE, false); } } continue; } if (NodeMaster.GetStatus(n) == NodeStatus.ST_LOST || NodeMaster.GetStatus(n) == NodeStatus.ST_DISABLED) { runPan1.SetStatus("weightbar", n, PanStatus.DISBALED, false); } else { if (n != curr_packer.vib_addr) { if (ce.release_addrs.Contains(n)) { runPan1.SetStatus("weightbar", n, PanStatus.RELEASE, false); } else { runPan1.SetStatus("weightbar", n, PanStatus.IDLE, false); } } } } UIPacker p = curr_packer; if (p.status == PackerStatus.RUNNING) { lbl_speed.Text = p.speed.ToString(); lbl_lastweight.Text = p.last_pack_weight.ToString("F1"); lbl_totalpack.Text = p.total_sim_packs.ToString(); lbl_totalweights.Text = p.total_sim_weights.ToString("F1"); } }
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 }