Pages: 1 [2]   Go Down
Author Topic: Serial parsing with Serial Proxy  (Read 1735 times)
0 Members and 1 Guest are viewing this topic.
Monterey CA
Offline Offline
Sr. Member
****
Karma: 0
Posts: 321
Addicted to Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Darn it! I just realized even though it seemed to sort of work the main loop isn't running, the LCD isn't updating until I click a command so back to the drawing board!!!  smiley-cry

Edit:
I tired this program is this post and the same result. So weird!!

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1218590225

SerialServer
http://itp.nyu.edu/~dbo3/SerialServer/SerialServer.html

At least now I can see the data in the debug window.
« Last Edit: July 14, 2011, 10:40:04 pm by MobileWill » Logged

Current Projects:                    Arduinos:
Security Robot Tank               Uno
Security Robot II 4WD            Mega2560

http://mobilewill.blogspot.com

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46227
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I think it is hanging up here
Nope. Incoming serial data triggers an interrupt. During that interrupt, the incoming character is added to a buffer. All that Serial.available() is doing is looking to see if the head and tail of the ring buffer used are at the same place (no data available) or at different places (some data available - the amount being the difference in the head and tail values).
Logged

Monterey CA
Offline Offline
Sr. Member
****
Karma: 0
Posts: 321
Addicted to Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks. that helps.

For now I did this.

Code:
Dim outStream As Byte() = System.Text.Encoding.ASCII.GetBytes(vbCrLf + cmdCamera + vbCrLf + vbCrLf)


I added another Carriage Return at the end of the command sequence.

It came to me in my sleep. Good thing cause I didn't want to think about it all weekend since I won't be able to work on it.

Now in the mean time to speed up my code. I am thinking of moving this function into the loop function. Would that make a difference?
« Last Edit: July 15, 2011, 01:56:58 pm by MobileWill » Logged

Current Projects:                    Arduinos:
Security Robot Tank               Uno
Security Robot II 4WD            Mega2560

http://mobilewill.blogspot.com

New Hampshire
Offline Offline
God Member
*****
Karma: 13
Posts: 779
There are 10 kinds of people, those who know binary, and those who don't.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks. that helps.

For now I did this.

Code:
Dim outStream As Byte() = System.Text.Encoding.ASCII.GetBytes(vbCrLf + cmdCamera + vbCrLf + vbCrLf)


I added another Carriage Return at the end of the command sequence.

It came to me in my sleep. Good thing cause I didn't want to think about it all weekend since I won't be able to work on it.

Now in the mean time to speed up my code. I am thinking of moving this function into the loop function. Would that make a difference?

Actually, I'd have to recommend the opposite.  Your code is a bit too disorganized and redundant.  You have a getMessage function that does a lot more than just get a Message.  It gets it, and conditionally processes based on the first character.  Actually, it doesn't even get the whole message first. You also have two separate blocks of code that both are reading in the serial data, and then processing it.  That's just a bad design and prone to errors.

You really should refactor your code.  First, modify getMessage so it does just one single thing.  Get an entire message.  Don't look at what's in the message.  Just get the entire string (without code duplication), ideally with both a start and end character, but still workable with just an end character. 

After you have your entire message, then you can parse and process it.  Check the first character, if it's your 'command' character, send the string to a separate command process function.  If it isn't, send it to your speech processing function.

The overhead involved with function calls is effectively non-existent when dealing with serial data.  You aren't going to see any sort of performance gain by eliminating a few functions, but you will significantly impact code readability and the likelihood of introducing more bugs into your code.
Logged


Monterey CA
Offline Offline
Sr. Member
****
Karma: 0
Posts: 321
Addicted to Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for all the help. Here is my rewrite, that works well, very well. Now I can string commands together.

Code:
boolean getMessage2()
{
  char in_char = '\0';    //Create a character to store the incoming byte from the serial port.
  inCount = 0;
 
  if (Serial.available() > 0) {
    in_char=Serial.read();
   if (in_char=='#'){
    while(in_char != '!'){
      while(Serial.available() <=0);
       in_char = Serial.read();  
       inString[inCount]=in_char;
      inCount++;
      //Serial.println(in_char);
    }
        
    inString[inCount+1]='\0';    //Strings must end with a Null terminator so we need to add this to our message.
  
    return true;
   }
  }
  
 return false;
}

void parseCmd()
{
    char cmd[5]="";
    char cmdChar;
    int cmdValue=0;
    int code=0;
  
      if (inString[0] == '/'){
        
        for (int x = 0; x < inCount; x++)
        {
           cmd[x] = inString[x+1];
        
        }
        
        cmdChar = cmd[0];
        
        for (int x = 0; x < inCount-1; x++)
        {
           cmd[x] = cmd[x+1];
        }
        
        cmdValue = atoi(cmd);
        
        pCmd(cmdChar, cmdValue);

      }
      
      else {
      
      int x=0;
      for (int i = 0; i < inCount-1; i++){
        
       speakCmd[x]=inString[i];
        
      if (inString[i] == 0x5C){
      
      cmd[0]=inString[i+1];
      cmd[1]=inString[i+2];
      cmd[2]=inString[i+3];
      
      code = atoi(cmd);
      
      speakCmd[x]=code;

      i = i + 3;
      }
      x++;

      }
                inString[inCount-1]='\0';
                speakCmd[inCount-1]=0x0D;
                speakCmd[inCount]='\0';
                speak();
    
      }
}

Just need to comment the code.
Logged

Current Projects:                    Arduinos:
Security Robot Tank               Uno
Security Robot II 4WD            Mega2560

http://mobilewill.blogspot.com

Pages: 1 [2]   Go Up
Jump to: