Problem with serial port data receive in C#
<p>I have a problem with a C# program.
Through the Serial port i Receive a large string about 110 characters.
This part works ok, but when i add code to split the string up i receive an error after some rows.
Here is the error I get:</p>

<p>**An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll</p>

<p>Additional information: Index and length must refer to a location within the string.**</p>

<p>Here is the code:</p>

<pre><code>private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
      if (!comport.IsOpen) return;

      if (CurrentDataMode == DataMode.Text)
      {
        // Read all the data waiting in the buffer
        string data = comport.ReadExisting();

        Log(LogMsgType.Incoming, data);
        string ziua = data.Substring(0, 8);
        string ora = data.Substring(8, 8);
        string linie = data.Substring(18, 1);
        string interior = data.Substring(22, 3);
        string durata1 = data.Substring(26, 4);
        string durata2 = data.Substring(30, 8);
        string nrtel = data.Substring(38, 10);
        string tipapel = data.Substring(75, 1);
        string acct = data.Substring(76, 5);


      }
      else
      {
        int bytes = comport.BytesToRead;

        byte[] buffer = new byte[bytes];

        comport.Read(buffer, 0, bytes);

        Log(LogMsgType.Incoming, ByteArrayToHexString(buffer));
      }
    }
</code></pre>

<p>EDIT:</p>

<p>i've tested every substring and all of them are ok.
the string lenght is 112. it can't be to short.</p>

<p>this error appears after a few lines of 112... about one and a half</p>
