예제 #1
0
        private void timerPollForData_Tick(object sender, EventArgs e)
        {
            Pk2.UploadData();
            if (Pk2.Usb_read_array[1] > 0)
            {
                ResOk = 1;
                string newData = "";
                if (radioButtonASCII.Checked)
                {
                    newData = Encoding.ASCII.GetString(Pk2.Usb_read_array, 2, Pk2.Usb_read_array[1]);
                }
                else
                { // hex mode
                    if (newRX)
                    {
                        newData = "RX:  ";
                        newRX   = false;
                    }
                    for (int b = 0; b < Pk2.Usb_read_array[1]; b++)
                    {
                        newData += string.Format("{0:X2} ", Pk2.Usb_read_array[b + 2]);
                    }
                }
                if (logFile != null)
                {
                    logFile.Write(newData);
                }
                textBoxDisplay.AppendText(newData);

                while (textBoxDisplay.Text.Length > 16400)
                {// about 200 lines
                    // delete a line
                    int endOfLine = textBoxDisplay.Text.IndexOf("\r\n") + 2;
                    if (endOfLine == 1)
                    {                                                   // no line found
                        endOfLine = textBoxDisplay.Text.Length - 16000; // delete several hundred chars
                    }
                    textBoxDisplay.Text = textBoxDisplay.Text.Substring(endOfLine);
                }
                textBoxDisplay.SelectionStart = textBoxDisplay.Text.Length;
                textBoxDisplay.ScrollToCaret();
            }
            else
            {
                if (!newRX && radioButtonHex.Checked)
                {
                    textBoxDisplay.AppendText("\r\n");
                    if (logFile != null)
                    {
                        logFile.Write("\r\n");
                    }
                    textBoxDisplay.SelectionStart = textBoxDisplay.Text.Length;
                    textBoxDisplay.ScrollToCaret();
                }
                newRX = true;
            }
        }