0

I have added a couple of break points in my code to monitor the value of two variables when reached. The application basically receives a stream of data at 9600 baud from serial port generated by a micro controller working at 500 Hz and has to filter the messages according to certain rules "if" and "if else" to strip out header characters and address them to other variables for calculation usage. Here is the code:

 class Stripper
{
 public  void  Distri (string inComing, out string param1, out string param2, out string param3, out string param4)
    {
        string currentRes="";
        string currentMot = "";
        string temperature="";
        string numRPM="";
        string f = inComing;
        if (inComing.Length < 6)
        {
            f = ">123456<";
        }
        char firstChar = f[0];
        char lastChar = f[f.Length - 2];
        bool test1 =(firstChar.Equals('>'));
        bool test2 =(lastChar.Equals('<'));
        int messLenght = f.Length;

        try
        {
            if (test1 == true && test2 == true && messLenght <= 10)
            {
                f = f.Replace("<", "");
                f = f.Replace(">", "");

                if (f[0] == 'I')
                {
                    string _currentRes = f;
                    _currentRes = _currentRes.Replace("I", "");
                    currentRes = _currentRes;
                }

                else if (f[0] == 'M')
                {
                    string _currentMot = f;
                    _currentMot = _currentMot.Replace("M", "");
                    currentMot = _currentMot;
                }

                else if (f[0] == 'T')
                {
                    string _temperature = f;
                    _temperature = _temperature.Replace("T", "");
                    temperature = _temperature;
                }
                else if (f[0] == 'N')
                {
                    string _numRPM = f;
                    _numRPM = _numRPM.Replace("N", "");
                    numRPM = _numRPM;
                }

                else
                { }
            }

            else
            { }
        }
        catch (System.Exception)
        {

            throw;
        }

        param1 = currentRes;
        param2 = temperature;
        param3 = numRPM;
        param4 = currentMot;

        }
       }
      }

The problem I am facing is quite strange and at some point I was completely lost. Basically with the break points active on variable "f" and "inComing" the app was immediately unresponsive and, to make it work, I had to reduce the speed of the stream from serial to 1/100 introducing delays. Without the break points the app can take the full stream of data without any problem. May be this experience could also help other people in similar situations. Looks like the break points are slowing down the process quite dramatically.I do not think it has something to do with the pc I am using being this a monster with 16 Gb RAM and 2.4 Ghz processor i5. I am wondering why this is happening and if there a way to avoid such problem rather than not using the break points?

8
  • 2
    you could create an Logfile as alternative to breakpoints
    – WiiMaxx
    Commented Jun 17, 2013 at 9:47
  • Thanks for the advice. It is for sure a great alternative but does not give a real time vision of what is happening. However, I did not considered it before and I will try it.
    – FeliceM
    Commented Jun 17, 2013 at 9:50
  • you could also write to your output window in VS but i don't know how to do it i just now you can do it :D
    – WiiMaxx
    Commented Jun 17, 2013 at 9:52
  • Trace.TraceInformation?
    – Uwe Keim
    Commented Jun 17, 2013 at 9:55
  • The posted code is very unlikely to be related to the problem. The typical issue is using the DataReceived event and calling Begin/Invoke too often. Pummeling the UI thread with invoke requests and making it go catatonic when it can't keep up and stops painting and responding to user input. Which you fix by making the DataReceived event doing more work, collecting the entire device response before invoking. Ignoring the SerialPort.Read() return value is also a classic mistake. None of this is visible in the snippet. Commented Jun 17, 2013 at 10:28

1 Answer 1

1

I found it on an quick search Debug.WriteLine()
is the thing to write to your VS Output Window

so you will be able to get your realtime values

see also this link

2
  • Thank you. Very much appreciated but still I do not understand why the break points are causing such problem.
    – FeliceM
    Commented Jun 17, 2013 at 10:00
  • maybe based on the "normal" use of it so it tries to to get all information of the Value probably per reflection (but i don't know)
    – WiiMaxx
    Commented Jun 17, 2013 at 10:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.