Problem with SCADA

Hello!. Let me tell you.Run in Arduino Mega. The SCADA system uses the Modbus RTU protocol for data transmission and has two thermocouples and two pH meters. The system with two thermocouples and a pH meter goes perfectly and there are no problems of interference or failures of any kind on the server. The thing is that by connecting the second pH meter as it collapses and the server goes, I think that because it has problems processing the data of the RX3 TX3 and the RX2 TX2 at the same time we say. Obviously that has to be a matter of doing proper programming. And that’s where I fail … it occurs to you how to make sure they do not overlap. I leave the code: * The value of the pH meter is “sensorstring” and “sensorstring1”. Many thanks friends

#include <Adafruit_MAX31856.h>
Adafruit_MAX31856 max_A = Adafruit_MAX31856(10, 11, 12, 13);
Adafruit_MAX31856 max_B = Adafruit_MAX31856(9, 11, 12, 13); 
String termoparstring_A = "";
String termoparstring_B = "";  
String inputstring = "";   
String sensorstring = "";
String inputstring1 = "";  
String sensorstring1 = ""; 
boolean input_string_complete = false;                
boolean sensor_string_complete = false;  
boolean input_string_complete1 = false;                
boolean sensor_string_complete1 = false;       
void configure_mb_slave(long baud, char parity, char txenpin);

int update_mb_slave(unsigned char slave, int *regs, unsigned int regs_size);
enum {
        COMM_BPS = 9600, 
        MB_SLAVE = 1,	 
        PARITY = 'n'     
};

enum {        
        T_1,
        T_2,
        pH_1,
        pH_2,  
        MB_REGS	 	 
};

int regs[MB_REGS];
unsigned long wdog = 0;         
unsigned long tprev = 0;         

void setup() {
          configure_mb_slave(COMM_BPS, PARITY, 0);
          Serial3.begin(9600);
          Serial1.begin(9600);
          Serial2.begin(9600);
         inputstring.reserve(30);                            
         sensorstring.reserve(60);
         inputstring1.reserve(30);                            
        sensorstring1.reserve(60);
        max_A.begin();
        max_A.setThermocoupleType(MAX31856_TCTYPE_K);
        max_B.begin();
        max_B.setThermocoupleType(MAX31856_TCTYPE_K);
}
                          
void serialEvent() {                                  
  inputstring = Serial1.readStringUntil(13);          
  input_string_complete = true;  

}


void serialEvent3() {                                 
  sensorstring = Serial3.readStringUntil(13);         
  sensor_string_complete = true; 
  sensorstring1 = Serial2.readStringUntil(13);         
  sensor_string_complete1 = true;         
}


void loop() {
        update_mb_slave(MB_SLAVE, regs, MB_REGS);
        termoparstring_A =(max_A.readThermocoupleTemperature());
        termoparstring_B =(max_B.readThermocoupleTemperature());
    
       
        regs [T_1] = (max_A.readThermocoupleTemperature()*100);         // ec. del sensor y *100.0 para que aparezcan decimales en el SCADA 
        regs [T_2] = (max_B.readThermocoupleTemperature()*100);         // ec. del sensor y *100.0 para que aparezcan decimales en el SCADA 
        regs [pH_1] = (sensorstring.toFloat()*100); 
        regs [pH_2] = (sensorstring1.toFloat()*100); 
    
  sensorstring = "";
  sensorstring1 = "";                                  
  sensor_string_complete = false;
  sensor_string_complete1 = false;     
                                     
  }

I think that because it has problems processing the data of the RX3 TX3 and the RX2 TX2 at the same time we say.

That is NOT the problem. Serial data is interrupt driven. The Mega is perfectly capable of reading data arriving on all 4 ports simultaneously, because the pins, even at 115200 baud, stay high long enough for the interrupts to be handled before the pin changes state again.

There is NO excuse, except laziness, for using Strings. If you are lazy, you won't get much help here.

enum {
        COMM_BPS = 9600,
        MB_SLAVE = 1,	
        PARITY = 'n'     
};

An enum is used to collect related data, where the values are mutually exclusive (it can't be Wednesday and Monday at the same time). There is nothing about this collection of names and values that suggests that an enum is appropriate.

Unnamed enums are about useless.

void serialEvent() {                                 
  inputstring = Serial1.readStringUntil(13);         
  input_string_complete = true; 

}

WTF? The serialEvent() method gets called when there is data in Serial's incoming buffer to be read. Reading from some other port does NOT make sense.

The same holds true in serialEvent3().