Using HardwareSerial to print to serial failing

Hello
I am a newbie so be gentle.

Here is my sketch I am trying to write to the serial port with no success.

#include "HardwareSerial.h"

long previousMillis = 0;
long interval = 2000;    

void setup() {
  // put your setup code here, to run once:
 pinMode(13, OUTPUT);
 digitalWrite(13, HIGH);
 Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  unsigned long currentMillis = millis();
  if(currentMillis - previousMillis > interval) {
    previousMillis = currentMillis; 
      String test = SendInstruction(Serial,"Test");
  }
}

This is the code in the function

SendInstruction(HardwareSerial serial,String command)
{
  int i;
  int commandLength = command.length();
  
  for(i=0; i < commandLength ;i++)
  {
    serial.print(command.charAt(i));
  }
  serial.print("#");
}

Now when I monitor the serial port all I get every 2 seconds is

"Te"

When I use Serial.print then it is fine but I need to get it working with HardwareSerial

The String Class uses dynamic memory which can cause too fragmented memory to be workable.
Looking at the code this seems not the case

THis line cannot work as SendInstruction does not return anything. It however might corrupt its call.
String test = SendInstruction(Serial,"Test");

Please try

SendInstruction(HardwareSerial serial,String command)
{
  int i;
  int commandLength = command.length();

  serial.println(commandLength);

  for(i=0; i < commandLength ;i++)
  {
    serial.print(command.charAt(i));
  }
  serial.print("#");
}

to see what length is processed

Hello

The result is 4 for serial.println(commandLength) and it prints nothing else after that just 4 every 2 seconds

and I added

return "true";

to the bottom of the method and still no success.

Please try this slightly modified version

unsigned long previousMillis = 0;
unsigned long interval = 2000;

void setup() {
  // put your setup code here, to run once:
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;
    SendInstruction(Serial, "Test");
  }
}

void SendInstruction(Stream &serial, String command)  // <<<<<<<<<<<
{
  int i;
  int commandLength = command.length();
 
  for (i = 0; i < commandLength ; i++)
  {
    serial.print(command.charAt(i));
  }
  serial.print("#");
}

no need to include HWSerial,
used the Stream baseclass (so you can also pass SWserial as param)
and most important used a reference &

Thank you that is what I was looking for works like a charm

When I use Serial.print then it is fine but I need to get it working with HardwareSerial

Serial IS an instance of the HardwareSerial class, so this statement makes no sense.