private void BTN_Run_Click(object sender, EventArgs e) { if (BTN_Run.Text == "Run Step") { string setmsg = ""; bool validcmd = true; string sentlist = ""; foreach (RelationalItem2 r in PAN_Send.Controls) { if (r.KVPValue(false) != "") { setmsg += r.KVPMessage(); sentlist += "(0x" + r.KeyValue + ")" + r.KeyName + ": " + r.KVPValue(false) + "\r\n"; } else { validcmd = false; } } /*if (validcmd && setmsg.Length > 0) * { * parent.SendExternal(setmsg, false, true); * } * else * { * MessageBox.Show("All command KVPs must have an assigned value."); * }*/ parent.listenList.Clear(); foreach (RelationalItem2 r in PAN_Recv.Controls) { DataRow dr = parent.listenList.NewRow(); dr["Key"] = r.KeyValue; dr["Name"] = r.KeyName; dr["Value"] = r.KVPValue(false); dr["HexValue"] = r.KVPMessage(); dr["Result"] = ""; dr["Pass"] = ""; parent.listenList.Rows.Add(dr); } try { //parent.listenUntil = DateTime.Now.AddMilliseconds(int.Parse(TB_Wait.Text)); parent.listenTimer.Interval = int.Parse(TB_Wait.Text); if ((validcmd && setmsg.Length > 0) || PAN_Send.Controls.Count == 0) { parent.listening = true; parent.listenTimer.Enabled = true; bool sent = parent.SendExternal(setmsg, false, true); if (sent) { RTB_Log.AppendText("Running " + TB_Name.Text + "...\r\n\r\n"); RTB_Log.AppendText("Sent:\r\n" + sentlist + "\r\n"); RTB_Log.AppendText("Waiting " + TB_Wait.Text + "ms for responses...\r\n\r\n"); RTB_Log.ScrollToCaret(); if (!batchrunning) { BTN_Run.Text = "Stop"; LB_Batch.Enabled = false; foreach (Button b in PAN_Buttons.Controls) { if (!(b == BTN_Run || b == BTN_Close)) { b.Enabled = false; } } } } else { parent.listening = false; parent.listenTimer.Enabled = false; batchrunning = false; LB_Batch.Enabled = true; BTN_Run.Text = "Run Step"; BTN_BatchRun.Text = "Run Batch"; foreach (Button b in PAN_Buttons.Controls) { b.Enabled = true; } } } else { MessageBox.Show("All command KVPs must have an assigned value."); } } catch { MessageBox.Show("Wait time is an invalid value."); } } else { BTN_Run.Text = "Run Step"; parent.listening = false; parent.listenTimer.Enabled = false; RTB_Log.AppendText("Aborted.\r\n\r\n"); LB_Batch.Enabled = true; foreach (Button b in PAN_Buttons.Controls) { b.Enabled = true; } } }
public void UpdateLog() { bool pass = true; bool check = false; foreach (DataRow dr in parent.listenList.Rows) { if (dr["Result"].ToString() != "") { string result = "PASS"; Color resultcolor = Color.LightGreen; if (!dr["Pass"].ToString().Contains("0")) { result = "\r\nPASS:"******"Pass"].ToString().Contains("1")) { result = "\r\nFAIL:"; resultcolor = Color.LightCoral; pass = false; } else { result = "\r\nCHECK:"; resultcolor = Color.Yellow; check = true; } result += "\r\n\tExpected result: (0x" + dr["Key"] + ")" + dr["Name"] + ": " + dr["Value"] + "\r\n"; int selstart = RTB_Log.TextLength; RTB_Log.AppendText(result); int selend = RTB_Log.TextLength; RTB_Log.Select(selstart, selend - selstart); RTB_Log.SelectionBackColor = resultcolor; string[] results = dr["Result"].ToString().Split('\t'); string[] passes = dr["Pass"].ToString().Split(';'); string[] timestamps = dr["TimeStamp"].ToString().Split(';'); for (int i = 1; i < results.Length; i++) { selstart = RTB_Log.TextLength; resultcolor = passes[i] == "1" ? Color.LightGreen : Color.LightCoral; RTB_Log.AppendText(timestamps[i] + "\t" + results[i]); selend = RTB_Log.TextLength; RTB_Log.Select(selstart, selend - selstart); RTB_Log.SelectionBackColor = resultcolor; } } else { int selstart = RTB_Log.TextLength; RTB_Log.AppendText("FAIL:\r\n" + DateTime.Now.ToString("MMddyy hh:mm:ss") + "\t(0x" + dr["Key"] + ")" + dr["Name"] + " not received in " + TB_Wait.Text + "ms\r\n"); int selend = RTB_Log.TextLength; RTB_Log.Select(selstart, selend - selstart); RTB_Log.SelectionBackColor = dr["Result"].ToString().StartsWith("PASS") ? Color.LightGreen : Color.LightCoral; pass = false; } RTB_Log.SelectionLength = 0; } RTB_Log.AppendText("Done. Overall Result = "); int start = RTB_Log.TextLength; string overalltext = check && pass ? "CHECK" : "PASS"; overalltext = pass ? overalltext : "FAIL"; RTB_Log.AppendText(overalltext + "\r\n\r\n"); int end = RTB_Log.TextLength; RTB_Log.Select(start, end - start); Color overallcolor = check && pass ? Color.Yellow : Color.LightGreen; overallcolor = pass ? overallcolor : Color.LightCoral; RTB_Log.SelectionBackColor = overallcolor; RTB_Log.SelectionLength = 0; RTB_Log.ScrollToCaret(); if (batchrunning || BTN_Run.Text == "Stop") { if (LB_Batch.SelectedIndex < LB_Batch.Items.Count - 1 && BTN_Run.Text != "Stop") { LB_Batch.SelectedIndex++; } else { batchrunning = false; parent.listening = false; parent.listenTimer.Enabled = false; BTN_BatchRun.Text = "Run Batch"; BTN_Run.Text = "Run Step"; LB_Batch.Enabled = true; foreach (Button b in PAN_Buttons.Controls) { b.Enabled = true; } } } }
private void RTB_Log_TextChanged(object sender, EventArgs e) { RTB_Log.SelectionStart = RTB_Log.Text.Length; //Set the current caret position at the end RTB_Log.ScrollToCaret(); //Now scroll it automatically }