Click here to Skip to main content
15,889,462 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to make resistor color code Pin
Michel [mjbohn]12-Feb-12 4:38
Michel [mjbohn]12-Feb-12 4:38 
GeneralRe: How to make resistor color code Pin
Dave Kreskowiak12-Feb-12 4:39
mveDave Kreskowiak12-Feb-12 4:39 
AnswerRe: How to make resistor color code Pin
Luc Pattyn12-Feb-12 9:32
sitebuilderLuc Pattyn12-Feb-12 9:32 
RantRe: How to make resistor color code Pin
Paladin200013-Feb-12 7:47
Paladin200013-Feb-12 7:47 
QuestionDigit Presents Windows phone application development contest Pin
PrateekN11-Feb-12 8:48
PrateekN11-Feb-12 8:48 
QuestionHow to Handle DatagridView's keydown event during editing of cell Pin
Nabawoka11-Feb-12 6:27
Nabawoka11-Feb-12 6:27 
AnswerRe: How to Handle DatagridView's keydown event during editing of cell Pin
Nabawoka11-Feb-12 20:57
Nabawoka11-Feb-12 20:57 
QuestionPlease help me understand serial communication Pin
turbosupramk311-Feb-12 5:52
turbosupramk311-Feb-12 5:52 
I have a situation where I am parsing through a string generated by serialPort1.ReadExisting(). I started getting somewhat random errors, and to troubleshoot this I started writing each value of the string parsing, to a textbox window.

It appears that sometimes the entire stream is not being received, because the length of RxString is changes sometimes and I believe that my errors are caused when only 1/2 of a single value of data I am trying to parse, is received, so that when I'm doing string.indexof, there is nothing left and it is causing "failed StartIndex cannot be less than zero" error message.

Has anyone experienced this before? Or can anyone speculate what I might be doing wrong in my code?



C#
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            if (serialPort1.IsOpen)
            {
                RxString = serialPort1.ReadExisting(); 
                this.Invoke(new EventHandler(displayData));
            }
            else
            {
                return;
            }
        }


 private void displayData(object sender, EventArgs e)
        {
            int count = 0;
            try
            {
                count = 0;
               if (Regex.Match(RxString, @"\r") != null)
               {
                   RxString = Regex.Replace(RxString, @"\r", "\r\n", RegexOptions.Multiline); // Parse through data to split it up and make it readable
               }
  if (RxString.Contains("ps2="))
               {
                   count = count + 1;
                   txtDiagnostic.Text += count + ", ";
                   int totalLength = RxString.Length;
                   txtDiagnostic.Text += totalLength + ", ";
                   int startDelimiter3 = RxString.IndexOf("ps2=");
                   txtDiagnostic.Text += startDelimiter3 + ", ";
                   string ps2String = RxString.Remove(0, startDelimiter3 + 4);
                   int endDelimiter3 = ps2String.IndexOf("\r\n");
                   txtDiagnostic.Text += endDelimiter3 + ", ";
                   ps2String = ps2String.Remove(endDelimiter3);
                   rtbPressureSensor2.Text = ps2String;
                   txtDiagnostic.Text += ps2String + System.Environment.NewLine;
                   Application.DoEvents();
}

    Thread.Sleep(250);
            }
            catch (Exception ex)
            {
                
                MessageBox.Show("displayData() failed " + count + " " + ex.Message);
            }

AnswerRe: Please help me understand serial communication Pin
OriginalGriff11-Feb-12 9:50
mveOriginalGriff11-Feb-12 9:50 
GeneralRe: Please help me understand serial communication Pin
turbosupramk311-Feb-12 11:09
turbosupramk311-Feb-12 11:09 
AnswerRe: Please help me understand serial communication Pin
Luc Pattyn11-Feb-12 11:31
sitebuilderLuc Pattyn11-Feb-12 11:31 
GeneralRe: Please help me understand serial communication Pin
turbosupramk311-Feb-12 11:56
turbosupramk311-Feb-12 11:56 
GeneralRe: Please help me understand serial communication Pin
turbosupramk311-Feb-12 15:29
turbosupramk311-Feb-12 15:29 
AnswerRe: Please help me understand serial communication Pin
Luc Pattyn11-Feb-12 15:51
sitebuilderLuc Pattyn11-Feb-12 15:51 
GeneralRe: Please help me understand serial communication Pin
turbosupramk311-Feb-12 22:31
turbosupramk311-Feb-12 22:31 
AnswerRe: Please help me understand serial communication Pin
Luc Pattyn11-Feb-12 23:34
sitebuilderLuc Pattyn11-Feb-12 23:34 
GeneralRe: Please help me understand serial communication Pin
turbosupramk312-Feb-12 4:11
turbosupramk312-Feb-12 4:11 
GeneralRe: Please help me understand serial communication Pin
Luc Pattyn12-Feb-12 10:43
sitebuilderLuc Pattyn12-Feb-12 10:43 
GeneralRe: Please help me understand serial communication Pin
turbosupramk312-Feb-12 11:06
turbosupramk312-Feb-12 11:06 
GeneralRe: Please help me understand serial communication Pin
turbosupramk312-Feb-12 16:40
turbosupramk312-Feb-12 16:40 
AnswerRe: Please help me understand serial communication Pin
Luc Pattyn13-Feb-12 3:10
sitebuilderLuc Pattyn13-Feb-12 3:10 
GeneralRe: Please help me understand serial communication Pin
turbosupramk313-Feb-12 3:18
turbosupramk313-Feb-12 3:18 
AnswerRe: Please help me understand serial communication Pin
Luc Pattyn13-Feb-12 3:31
sitebuilderLuc Pattyn13-Feb-12 3:31 
GeneralRe: Please help me understand serial communication Pin
turbosupramk313-Feb-12 4:00
turbosupramk313-Feb-12 4:00 
AnswerRe: Please help me understand serial communication Pin
Luc Pattyn13-Feb-12 4:12
sitebuilderLuc Pattyn13-Feb-12 4:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.