0

Every 2.5 seconds this string is sent to a textbox,which contains sensor values etcADR=0x0100000000,FW=0x010B,BV=26,UL=40,SRC=3,SEss=10,TAMB=73,SQ=32886,STAT=0x03,RFrssi=227

The string updates, the if else statements are doing there job but the textboxes containing the values are just staying the same. (txtUllage,txtSRC etc) They update the first time but dont update from their on. Is their something wrong with my loop

private void txtConsole_TextChanged(object sender, EventArgs e)
    {
        if ((txtConsole.Text.Contains("STAT")) && (txtConsole.Text.Length > 85))
        {
            string Stat = "";
            int Ullage_12cm = 0;
            int Sonic_Result_Code_12cm = 0;
            int BV_12cm = 0;
            int tamb_12cm = 0;
            int PassCounter = 0;
            int SEss_12cm = 0;

                string[] splitstring = txtConsole.Text.Split(',');

                BV_12cm = Convert.ToInt32(splitstring[2].Replace("BV=", ""));
                txtBatteryVoltage.Text = BV_12cm.ToString();

                Ullage_12cm = Convert.ToInt32(splitstring[3].Replace("UL=", ""));
                txtUllage.Text = Ullage_12cm.ToString();

                Sonic_Result_Code_12cm = Convert.ToInt32(splitstring[4].Replace("SRC=", ""));
                txtSRC.Text = Sonic_Result_Code_12cm.ToString();

                SEss_12cm = Convert.ToInt32(splitstring[5].Replace("SEss=", ""));
                txtSESS.Text = SEss_12cm.ToString();

                tamb_12cm = Convert.ToInt32(splitstring[6].Replace("TAMB=", ""));
                txtTAMB.Text = tamb_12cm.ToString();

                if ((BV_12cm < spnMinBatt.Value) || (Ullage_12cm < SpnSonicLowval.Value - 2) || (Ullage_12cm > SpnSonicLowval.Value + 2) ||
                    Sonic_Result_Code_12cm < spnSRCLow.Value || (SEss_12cm < spnSEssLow.Value) || ((tamb_12cm < spnTambLow.Value) || (tamb_12cm > spnTambHigh.Value)))
                {
                    txtResultsReading.AppendText("BATT=" + txtBatteryVoltage.Text + "   Ullage=" + txtUllage.Text + "   SRC=" + txtSRC.Text + "   SESS=" + txtSESS.Text + "   TAMB=" + txtTAMB.Text + "   (FAIL)\r\n");
                    txtUllage.BackColor = Color.Red;
                    // PassCounter = 0;//reset pass count
                }

                else
                {
                    txtResultsReading.AppendText("BATT=" + txtBatteryVoltage.Text + "   Ullage=" + txtUllage.Text + "   SRC=" + txtSRC.Text + "   SESS=" + txtSESS.Text + "   TAMB=" + txtTAMB.Text + "   (PASS)\r\n");
                    txtUllage.BackColor = Color.LightGreen;

                    /*if (++PassCounter >= 6)//increment pass count
                    {
                        MessageBox.Show(SpnSonicLowval.Value.ToString() + " cm test passed, now proceed to next test");
                    }*/
                }
            }
            Application.DoEvents();
        }
Gooner1990
  • 35
  • 5
  • possible duplicate of [Writing to a TextBox from another thread?](http://stackoverflow.com/questions/519233/writing-to-a-textbox-from-another-thread) – Mark Oct 20 '14 at 14:09
  • @Kami No The actual textbox itself is not updating. it only reads it once and doesnt check again it seems – Gooner1990 Oct 20 '14 at 14:13
  • has it something to do with application.doevents() – Gooner1990 Oct 20 '14 at 14:54

1 Answers1

0

You are using AppendText which appends the given text. It is likely this scrolls off-screen is not visible. Use the .Text property instead.

txtResultsReading.Text = "BATT=" + txtBatteryVoltage.Text + "   Ullage=" + txtUllage.Text + "   SRC=" + txtSRC.Text + "   SESS=" + txtSESS.Text + "   TAMB=" + txtTAMB.Text + "   (FAIL)\r\n";

MSDN:
TextBox.Append()
TextBox.Text

Kami
  • 19,134
  • 4
  • 51
  • 63