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

C#

 
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 
GeneralRe: Please help me understand serial communication Pin
turbosupramk313-Feb-12 4:18
turbosupramk313-Feb-12 4:18 
GeneralRe: Please help me understand serial communication Pin
turbosupramk317-Feb-12 11:52
turbosupramk317-Feb-12 11:52 
Hi Luc,

It isn't 20 lines, but it's pretty fast compared to what I had before, I have the uC push serial data every 10mS and it has no problem keeping up.

What do you think?

C#
public string[] produceParseConsumeSerial(byte serialByte)
 {
     try
     {
         startCharacters[0] = '@';
         startCharacters[1] = '@';
         startCharacters[2] = '@';
         endCharacters[0] = '|';
         endCharacters[1] = '|';
         endCharacters[2] = '|';
         valueDelimiter[0] = '\r';
         valueDelimiter[1] = '\r';
         //valueDelimiter[0] = '<';
         //valueDelimiter[1] = '>';
         readLine[readLineIndex] = serialByte;

         if (readLine[0] == startCharacters[0]) // check start character 1 for @ symbol
         {
             if (readLine[1] == startCharacters[1]) // check start character 2 for @ symbol
             {
                 if (readLine[2] == startCharacters[2]) // check start character 3 and that character 4 is not blank, this keeps the string from being built until it receives a complete line starting with the 3 start character combination
                 {
                     if ((readLine[readLineIndex] != valueDelimiter[0]) && (readLine[readLineIndex] != endCharacters[0]) && (readLine[readLineIndex] != 0) && (readLine[readLineIndex] != startCharacters[0]))
                         {
                             serialPortReadBytes[serialPortReadBytesIndex] = readLine[readLineIndex];
                             serialPortReadBytesIndex = serialPortReadBytesIndex + 1;
                         }
                         if ((readLine[readLineIndex] == valueDelimiter[1]) && (readLine[readLineIndex - 1] == valueDelimiter[0])) // look for a pair of carriage return value delimiter in between start and end line delimiters
                         {
                             int nullCount = 0;
                             string readLineString = System.Text.ASCIIEncoding.ASCII.GetString(serialPortReadBytes).ToString();
                             foreach (byte singleByte in serialPortReadBytes)
                             {
                                 if (singleByte != 0)
                                 {
                                     nullCount = nullCount + 1;
                                 }
                             }
                             int serialPortReadBytesCount = serialPortReadBytes.Count();
                             Array.Clear(serialPortReadBytes, 0, serialPortReadBytesCount);
                             serialPortReadBytesIndex = 0;
                             readLineString = readLineString.Remove(nullCount);
                             if (readLineString != "")
                             {
                                 completeLineByLineArray.Add(readLineString); // Add entire value of xxx=xxx to array line
                             }
                             readLineString = "";
                         }
                         else if ((readLine[readLineIndex] == valueDelimiter[0])) // look for a single carriage return value delimiter in between start and end line delimiters
                         {
                             int nullCount = 0;
                             string readLineString = System.Text.ASCIIEncoding.ASCII.GetString(serialPortReadBytes).ToString();
                             foreach (byte singleByte in serialPortReadBytes)
                             {
                                 if (singleByte != 0)
                                 {
                                     nullCount = nullCount + 1;
                                 }
                             }
                             int serialPortReadBytesCount = serialPortReadBytes.Count();
                             Array.Clear(serialPortReadBytes, 0, serialPortReadBytesCount);
                             serialPortReadBytesIndex = 0;
                             readLineString = readLineString.Remove(nullCount);
                             if (readLineString != "")
                             {
                                 completeLineByLineArray.Add(readLineString); // Add entire value of xxx=xxx to array line
                             }
                             readLineString = "";
                         }

                     if ((readLine[readLineIndex] == endCharacters[2]) && (readLine[readLineIndex - 1] == endCharacters[1]) && (readLine[readLineIndex - 2] == endCharacters[0])) // if readLine array value = endCharacter and previous 2 array values also = endCharacter
                     {
                         string[] delimitedAndParsedArray = new string[completeLineByLineArray.Count];
                         Array.Copy(completeLineByLineArray.ToArray(), delimitedAndParsedArray, completeLineByLineArray.Count);
                         completeLineByLineArray.Clear();
                         int readLineLength = readLine.Count();
                         Array.Clear(readLine, 0, readLineLength);
                         readLineIndex = 0;
                         int serialPortReadBytesCountInitialClear = serialPortReadBytes.Count();
                         Array.Clear(serialPortReadBytes, 0, serialPortReadBytesCountInitialClear);
                         serialPortReadBytesIndex = 0;
                         return delimitedAndParsedArray; // not sure if I should return a value, or update a public static array???
                     }
                 }
             }
             readLineIndex = readLineIndex + 1;
         }
         else
         {
             int serialPortReadBytesCount = serialPortReadBytes.Count();
             Array.Clear(serialPortReadBytes, 0, serialPortReadBytesCount);
             int readLineLength = readLine.Count();
             Array.Clear(readLine, 0, readLineLength);
             readLineIndex = 0;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("produceParseConsumeSerial() failure " + ex.Message + " " + ex.Data + " " + ex.StackTrace);
     }
     return null;
 }

AnswerRe: Please help me understand serial communication Pin
Luc Pattyn17-Feb-12 17:36
sitebuilderLuc Pattyn17-Feb-12 17:36 
GeneralRe: Please help me understand serial communication Pin
turbosupramk317-Feb-12 18:33
turbosupramk317-Feb-12 18:33 
AnswerRe: Please help me understand serial communication Pin
Dan Mos12-Feb-12 2:11
Dan Mos12-Feb-12 2:11 
GeneralRe: Please help me understand serial communication Pin
turbosupramk312-Feb-12 4:21
turbosupramk312-Feb-12 4:21 
GeneralRe: Please help me understand serial communication Pin
Dan Mos12-Feb-12 5:44
Dan Mos12-Feb-12 5:44 
AnswerRe: Please help me understand serial communication Pin
turbosupramk312-Feb-12 7:44
turbosupramk312-Feb-12 7:44 
Questioncom add in excel2010 Pin
PozzaVecia11-Feb-12 0:19
PozzaVecia11-Feb-12 0:19 
AnswerRe: com add in excel2010 Pin
Eddy Vluggen11-Feb-12 3:29
professionalEddy Vluggen11-Feb-12 3:29 
GeneralRe: com add in excel2010 Pin
PozzaVecia11-Feb-12 6:18
PozzaVecia11-Feb-12 6:18 
AnswerRe: com add in excel2010 Pin
Abhinav S11-Feb-12 5:08
Abhinav S11-Feb-12 5:08 
GeneralRe: com add in excel2010 Pin
PozzaVecia11-Feb-12 5:31
PozzaVecia11-Feb-12 5:31 
GeneralRe: com add in excel2010 Pin
Abhinav S11-Feb-12 17:04
Abhinav S11-Feb-12 17:04 
GeneralRe: com add in excel2010 Pin
PozzaVecia11-Feb-12 6:09
PozzaVecia11-Feb-12 6:09 
Questionocr from japenese to english using c# with MODI Pin
udayakumard10-Feb-12 23:21
udayakumard10-Feb-12 23:21 
AnswerRe: ocr from japenese to english using c# with MODI Pin
Dave Kreskowiak11-Feb-12 2:08
mveDave Kreskowiak11-Feb-12 2:08 
QuestionAccess is denied Pin
jon-8010-Feb-12 22:29
professionaljon-8010-Feb-12 22:29 
AnswerRe: Access is denied Pin
fjdiewornncalwe11-Feb-12 5:40
professionalfjdiewornncalwe11-Feb-12 5:40 

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.