Sketch not processing all recieved serial data

Hi guys/girls

I have a sketch that reads incoming serial data, then displays it on 5x LED 7 Segment displays via a MAX7219 chip.

The serial data comes in as an identifier and value, separated by a colon - eg 9918:25000

The sketch will then assign the value to a variable, and update the displays there is a little code to split the value into digits for each display and omit the leading 0

One variable tells the display to show dashes if it is set to 1, otherwise it shows the full value.

It works, and the values change correctly most of the time, but switching the blanking variable to 1 then back to 0, sometimes it doesn't change the display. I have to do it 3-5 times for it change sometimes, other times if works fine.

To troubleshoot, i have tried changing the baud rate from 9600 right up to 115200, i have tried Uno, Mega and now even an ARM 32 board with the same results.

I have attached a serial monitor to the serial source, and all data is coming in correctly, even when the displays dont change. Also the Rx light on the board flickers every time as well, so its not the data coming in.

I have another more complex sketch that does the same thing, just randomly doesn't update. It seems to be more when a value is set to or from 0.

Both sketches use the same serial input processing, so im thinking it is something to do with that.

Anything obviously standing out that i have missed? or is there a better way to handle the serial input?

Sketch in question:

#include "LedControl.h"

LedControl lc=LedControl(5,6,7,1);  //Data, CLock, Load, device

unsigned long delaytime=5;

const int DevID = 99;  
const int flt1 = 18;    //Flt Alt
const int dash1 = 19;
int dash2;
int flt2;
int port;
int sts;
int stsold;
int dim;
int u1;
int t1;
int h1;
int th1;
int tth1;

void setup() {
  lc.shutdown(0,false);
  lc.setIntensity(0,9);
  lc.clearDisplay(0);
  lc2.shutdown(0,false);
  lc2.setIntensity(0,9);
  lc2.clearDisplay(0);
Serial.begin(9600);

}



void loop() {

  if (Serial.available()) {
    port = Serial.parseInt();   //Get identifier
    sts = Serial.parseInt();    //Get value
    delay(5);
   

  if ((port != 0) && (port - (DevID * 100) == flt1)) 
  {
  flt2 = sts;
  }

  if ((port != 0) && (port - (DevID * 100) == dash1)) 
  {
  dash2 = sts;
  }
   updateDisplay1();
  } 
}


void updateDisplay1(){

  if (dash2 == 1) {

  lc.setChar(0,1,'-',false);
  delay(delaytime);
  lc.setChar(0,2,' ',false);
  delay(delaytime);
  lc.setChar(0,3,'-',false);
  delay(delaytime);
  lc.setChar(0,4,' ',false);
  delay(delaytime);
  lc.setChar(0,5,'-',false);
  delay(delaytime);
  }
  
  else
  {
  u1=flt2%10;
  t1=(flt2/10)%10;
  h1=(flt2/100)%10;
  th1=(flt2/1000)%10;
  tth1=(flt2/10000)%10;
  lc.clearDisplay(0);
  
  if (tth1 > 0)
  {
  lc.setChar(0,5,tth1,false);
  delay(delaytime);
  } 
  else
  {
  lc.setChar(0,5,' ',false);
  delay(delaytime);
  }

  lc.setChar(0,4,th1,false);
  delay(delaytime);

  lc.setChar(0,3,h1,false);
  delay(delaytime);
   
  lc.setChar(0,2,t1,false);
  delay(delaytime);
     
  lc.setChar(0,1,u1,false);
  delay(delaytime);
      
    }
}

Maybe add the h (and cpp) files as well? Or a link to them if you got them from somewhere.

What is the format of the data that you send?Never mind.

And have a look at Serial Input Basics how to reliably read serial data.

h & cpp files are just the standard LedControl librabry by Wayoda on Github https://github.com/wayoda/LedControl