using SPC NEO DC motor H-Bridge with Arduino Mega 2560 to control DC motor

I have connected the TX and RX Pin of my Arduino Mega 2560 to my RX and TX pin in my SPC Neo DC Motor 2.4A. The Arduino Rx Pin is connected to SPC Neo Tx Pin, and the arduino Tx pin to the SPC Neo Rx Pin.

The problem is, I don't really understand the inner working of how arduino communicate with the h-bridge using the Rx Tx port. It seems like the program I've written is not communicated properly with the DC Motor, so I'm unable to progress forward with the project.

any explanation will be helpful. thank you.

 #include <Wire.h>
#define encoder1B 4
#define encoder2B 5
volatile unsigned int encoderpulse= 0;
double errorM1;

void setup()
{
  Wire.begin();
  attachInterrupt (0, Encoder1, RISING);	 //if there is rising on pin 2, then process will be interrupt. Move 
			//to function Encoder1
  attachInterrupt (1, Encoder2, RISING); //if there is rising on pin 3, then process will be interrupt. Move 
			//to function Encoder2
  Serial.begin(38400);
  pinMode(2,INPUT);			 // Set pin as input for encoder A of motor 1
  pinMode(3,INPUT);			 // Set pin as input for encoder A of motor 2
  pinMode(4,INPUT);			 // Set pin as input for encoder B of motor 1
  pinMode(5,INPUT);			 // Set pin as input for encoder B of motor 2
}

void loop()
{
  errorM1 = 40 - encoder2pulse;
  {
    while(errorM1 >5 || errorM1<0)
              {
                errorM1 = 40 - encoder2pulse;

                if (errorM1 >= 5)
                   {
                      Serial.write(0x35); //ccw
                      Serial.write(0x40);
                    }
                else if(errorM1 <= 0)
                    {
                      Serial.write(0x34); //cw
                      Serial.write(0x40);
                    }
                else
                   {
                       Serial.write(0x33);
                   }
              }  
  }
}

void Encoder1()
{

  if(digitalRead(encoder1B) == HIGH)	//if encoder B of motor 1 is high
  {
    encoderpulse = encoderpulse +1;	//counting pulse
    if (encoderpulse >=1633)			//1644 PPR from 0 to 1633
    {
      encoderpulse = 0;		//if more than 1633 then reset
    }
  }
  else			//if encoder B of motor 1 is low
  {
    encoderpulse = encoderpulse -1;
    if (encoderpulse == 65535)	//the encoder will show 65535 after 0 if counting down
    {
      encoderpulse=1633;   
    }
  }
}

void Encoder2()
{

  if(digitalRead(encoder2B) == HIGH)	//if encoder B of motor 1 is high
  {
    encoder2pulse = encoder2pulse +1;	//counting pulse
    if (encoder2pulse >=1633)			//1644 PPR from 0 to 1633
    {
      encoder2pulse = 0;		//if more than 1633 then reset
    }
  }
  else if(digitalRead(encoder2B) == LOW)			//if encoder B of motor 1 is low
  {
    encoder2pulse = encoder2pulse -1;
    if (encoder2pulse == 65535)	//the encoder will show 65535 after 0 if counting down
    {
      encoder2pulse=1633;   
    }
  }
}

spc-neo-dc-motor-24a.jpg

this is the SPC Neo DC Motor Data sheet

SPC_Neo_DC_Motor_2.4A_Manual_eng.pdf (430 KB)