Problem with the fingerprint sensor when writing a template in charBuf on sensor

Good day!
I want to make some program, who will connect with fingerprint sensor, send the database of templates and do scan of fingers. But I have problem: when I try send some template to controller, he send me answer {0xEF 0x1 0xFF 0xFF 0xFF 0xFF 0x7 0x0 0x3 0x1 0x0 0xB}, who means that have an error when receiving data package.
May be I send wrong data or I take mistake in sending, but I don't now what to do :cry: .

P.S.: I use zfm-20 (if I am not mistaken) & I tryed search any answers in Google, but without results

The code of my Arduino program

#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>

int getFingerprintIDez();
SoftwareSerial mySerial(2, 3);


Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup()  
{
  while(!Serial);
  Serial.begin(9600);
  Serial.println("finger template test");

  finger.begin(57600);

  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } 
  else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1);
  }

  uploadFingerpintTemplate(1);

}

void loop()
{

}

uint8_t getReply(uint8_t* packet){


  uint8_t reply[20], idx, ext;
  uint16_t timer=0;
  uint16_t timeout = 2000;
  ext = -1;
  idx = 0;
  delay(300);
  do{
    while (!mySerial.available()) {
      delay(1);
      timer++;
      if (timer >= timeout)
      {
        return idx;
      }
    }

    packet[idx] = mySerial.read();
    Serial.print("0x");
    Serial.print(packet[idx], HEX);
    Serial.print("\t");
    if((idx+1)%16==0)          { 
      Serial.println("");
    }
    //    packet[idx] = reply[idx];
    if ((idx == 0) && (packet[0] != (FINGERPRINT_STARTCODE >> 8)))
      continue;
    if(idx == 8)
    {
      uint8_t buf = packet[8];
      ext = buf + idx + 1;
    }
    idx++;

    if(ext == idx){
      Serial.println("");
      return idx;
    }



  } 
  while (mySerial.available());
  return idx;
}

uint8_t uploadFingerpintTemplate(uint16_t id) //Сделал Aronll
{
  uint8_t p ;

  uint8_t temp1[] = {
    0xEF, 0x1, 0xFF, 0xFF, 0xFF, 0xFF, 0x2, 0x0, 0x82, 0x3, 0x1, 0x61, 0x15,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 0xD3, 0x3F, 0xFA, 0x54, 0xEF, 
    0xFF, 0xFF, 0x0, 0x26, 0x56, 0x25, 0x18, 0xAF, 0x38, 0x23, 0x41, 0x1, 0x1D, 0x6C, 0xAE, 0xAF, 
    0x29, 0xD, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
    0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0    };

  p = finger.downloadImageToCharBuf(1);
  switch (p) {
  case FINGERPRINT_OK:
    Serial.println("0All good");
    break;
  default:
    Serial.println("0Unknown error ");
    return p;
  } 
  //  mySerial.write(temp1,256);

  uint8_t ans[20];
  int dsa = 0;
  int lon = 256;
  int leg = 0;
  for(int i = 0; i < lon; i++){
    Serial.print(i);
    ans[dsa] = mySerial.read();
    if ((ans[0] == (FINGERPRINT_STARTCODE >> 8)) ||
      (ans[1] == (FINGERPRINT_STARTCODE & 0xFF)))
    {        
      if(dsa==8){
        uint8_t packettype = ans[6];
        uint16_t len = ans[7];
        len <<= 8;
        len |= ans[8];
        lon = len;
        leg = len + 9;
        lon += i + 1;
      }      
      dsa++;
    }
    else{
      mySerial.write(temp1[i]);
    }
  }

  for(int i = 0; i < leg; i ++){
    Serial.print("\t0x");
    Serial.print(ans[i], HEX);

  }

  return 0;
}

And some code of my revision of the library Adafruit_Fingerprint.cpp

uint8_t Adafruit_Fingerprint::uploadImageFromCharBuf(uint8_t slot) {
    uint8_t packet[] = {0x08, slot};
    writePacket(theAddress, FINGERPRINT_COMMANDPACKET, sizeof(packet)+2, packet);
    uint8_t len = getReply(packet);
    
    if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
        return -1;
    return packet[1];
}

uint8_t Adafruit_Fingerprint::downloadImageToCharBuf(uint8_t slot) {
    uint8_t packet[] = {0x09, slot};
    writePacket(theAddress, FINGERPRINT_COMMANDPACKET, sizeof(packet)+2, packet);
    uint8_t len = getReply(packet);
    
    if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
        return -1;
    return packet[1];
}

uint8_t Adafruit_Fingerprint::loadModel1(uint16_t id, uint8_t slot) {
    uint8_t packet[] = {FINGERPRINT_LOAD, slot, id >> 8, id & 0xFF};
    writePacket(theAddress, FINGERPRINT_COMMANDPACKET, sizeof(packet)+2, packet);
    uint8_t len = getReply(packet);
    
    if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
        return -1;
    return packet[1];
}