Serial Optimization Help


hello in need of guidance optimize serial receive. prototyping @ moment  so apologies  rough messy code. method using blocks arduino while process command.

i know not best way parse ascii serial messages simplistic method think of @ time.

basically have c# app sending commands #a100.0 set acceleration in current mess takes arduino second processes while blocks else running command sent when needed it's not receiving.

any advice helpful.

code: [select]
void pcsyncin () {
  if (serial.available() >= 2)
  {
    if (serial.read() == '#')
    {
      int command = serial.read();
      if (command == 'u') {
        user = serial.parseint();
      }
      else if (command == 'f')
      {
        getgtfloor = serial.parseint();
        flrchng = true;
        srun = false;
        lcdgtfloordsp();
      }
      else if (command == 'l')
      {
        lcdlight = serial.parseint();
        digitalwrite(backlight, lcdlight);
      }
      else if (command == 's')
      {
        maxelevatorspeed = serial.parsefloat();

      }
      else if (command == 'a')
      {
        maxelevatoracceleration = serial.parsefloat();
      }
      else if (command == 'h')
      {
        hault();
      }
      else if (command == 'p')
      {
        liftpreci = serial.parseint();
      }
    }
  }
}

if/else if/else if/else if code both harder read , slower execute switch statement. rewrite code matches first character after "#" use switch statement.

however, long if statement, code posted should take milliseconds parse command, not second.

what baud rate using? , functions call "parsefloat()" do?






hello in need of guidance optimize serial receive. prototyping @ moment  so apologies  rough messy code. method using blocks arduino while process command.

i know not best way parse ascii serial messages simplistic method think of @ time.

basically have c# app sending commands #a100.0 set acceleration in current mess takes arduino second processes while blocks else running command sent when needed it's not receiving.

any advice helpful.

code: [select]
void pcsyncin () {
 if (serial.available() >= 2)
 {
 if (serial.read() == '#')
 {
 int command = serial.read();
   if (command == 'u'){
   user = serial.parseint();
 }
     else if (command == 'f')
 {
       getgtfloor = serial.parseint();
       flrchng = true;
       srun = false;
       lcdgtfloordsp();
 }
       else if (command == 'l')
 {
         lcdlight = serial.parseint();
         digitalwrite(backlight, lcdlight);
 }
           else if (command == 's')
 {
            maxelevatorspeed = serial.parsefloat();
   
 }
               else if (command == 'a')
 {  
                  maxelevatoracceleration = serial.parsefloat();
 }
                   else if (command == 'h')
 {  
                      hault();      
 }
                       else if (command == 'p')
 {  
                        liftpreci = serial.parseint();      
 }  
       }
     }
   }



Arduino Forum > Using Arduino > Programming Questions > Serial Optimization Help


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support