Reading Serial Data from Motor using Serial1

I have an ultramotion linear servo that i am trying to read positional data from using an Arduino Mega2560's Serial1 pins. I havent been able to read the data in but i can control the motor perfectly fine when i issue it movement commands. The motor is supposed to be queried for position using the "AP\r"
command. I have gotten it so that i receive a -1 but that's the only thing I am receiving. The feedback is supposed to be carriage return terminated but all my other attempts at querying the data have given me nothing else back. The current code that I have will give me a y with two dots above it when i comment out the while Serial1.available part but if i dont comment that out i just get nothing

//Receiving Variables
const byte numChars = 32; //defines size of byte array
char receivedChars[numChars]; //defines receivedChars as character array
boolean newData = false; //Inititalezes boolean value

// timing variables
int ServoCorrectionInterval = 500;
unsigned long CurrentMillis = 0;
unsigned long CorrectionMillis = 0;

//Pressure Variables and Pins
int analogPin = 0; //sets the analog pin to

//Define Variables we'll be connecting to
double Setpoint, Input;
long IntError;
long Accel;
int MoveSet;
char* MOVE;
unsigned long PrintMillis = 0;
int PrintValMillis = 50;
long IntSet;
int scalar = 350;
int Activate=0;
char OnOff;

String read1; 
//Averaging values
const int numReadings = 5;
int readings[numReadings];      // the readings from the analog input
int readIndex = 0;              // the index of the current reading
int total = 0;                  // the running total
int average = 0;                // the average

long minVal = 5000;

void setup() {
  Input = analogRead(analogPin); //reads the pressure sensor
  Serial.begin(115200); //set baud rate for arduino to pc
  Serial1.begin(115200); //set baud rate for arduino to actuator
  
  while (!Serial) {
   ; // wait for serial port to connect. Needed for native USB port only
  }

  while (!Serial1) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial1.println("SP2500000"); //set initial speed
  Serial1.println("AC25000"); //set initial acceleration
  Serial1.println("TR"); //return to start of movement
  delay(500);
  Serial1.println("TA8000"); //cycle through some movements to let me know everythings working
  delay(500);
  Serial1.println("TR"); //return to start of movement
  delay(500);
}

void loop()
{
  CurrentMillis = millis();
  movePiston();
  readPiston();
  String content = "";
  char character;
  while(Serial.available()) {
  character = Serial.read();
  content.concat(character);
  }
  if (content != "") {
    Serial.println(content);
  }
}

void movePiston()
{
  if (CurrentMillis - CorrectionMillis >= ServoCorrectionInterval)
  {
    Serial1.println("TA" + String(minVal));
    minVal = minVal + 100;
    //Serial.println("Sent Value: TA" + String(minVal));
    if (minVal > 22500)
    {
      minVal = 5000;
    }
    CorrectionMillis += ServoCorrectionInterval;
  }

}

void readPiston()
{
  if (CurrentMillis - PrintMillis >= PrintValMillis)
  {
  Serial1.println("AP");
  PrintMillis += PrintValMillis;
  }
}

Thanks in advance for any help. Attached is the motor guide Appendix A has the important info

No attachment :wink:

You expect all the data to arrive as one bunch; that is not necessarily the case. You need to 'wait' for the carriage return before sending another read command to the motor.

void readPiston()
{
  if (CurrentMillis - PrintMillis >= PrintValMillis)
  {
  Serial1.println("AP");
  PrintMillis += PrintValMillis;
  }
}

This doesn't read anything. Why is the function called readX when it does not read X?

Can you tell us the line number where you actually read anything from Serial1?

PaulS:
Can you tell us the line number where you actually read anything from Serial1?

Good catch (as usual)

Sorry the attachment didn't upload and I had named it read piston because i was originally reading within that function but moved the reading lines to the main loop so that I could see if i was receiving any data in general not only when i sent the AP command

  String content = "";
  char character;
  while(Serial.available()) {
  character = Serial.read();
  content.concat(character);
  }
  if (content != "") {
    Serial.println(content);
  }

but moved the reading lines to the main loop

That code does NOT read from Serial1.

Sorry i didn't realize that i ran it with the Serial1 it looks like this

  String content = "";
  char character;
  
  while(Serial1.available()) {
  character = Serial1.read();
  content.concat(character);
  }
  if (content != "") {
    Serial.println(content);
  }

I copy and pasted from the wrong code i was using from an example.
This still results in me receiving nothing from the motor

This still results in me receiving nothing from the motor

This suggests that either you don't have the TX pin from the motor connected correctly to the Arduino or that the command you are sending it is not the correct command to read data from the device.