Fingerprint Sensor GT-522C3 problem while getting image

Hi, i am having a problem concerning this product:

i am using Arduino Mega to in order to get the raw image of the fingerprint and i connected it properly and successfully sent the command packet and received the response packet as an ack while the data packet in the datasheet saying i will receive 19200 Bytes of data for raw image.
so when i set the for loop to receive data to (256X256) bytes to receive HEX the data is less than (256X256) bytes

// constants won't change. 
const int button1 = 3; //Define button to digital input pins 
const int button2 = 4; //Define button to digital input pins 
const int button3 = 5; //Define button to digital input pins 
const int ledPin = 13;// the number of the LED pin 
int f; // Counter for array position 
int b=0;
byte ResponseData[38]; //Array to recieve data from serial port. 
byte CommandPacket[12]; //Array to construct command packet
int previous =LOW;
uint16_t rawimageresponse;
int reading1 = 0;
int c;

//Call External libaries 

//Items that are run once go here 
void setup() { 
  pinMode(button1, INPUT); 
  pinMode(ledPin, OUTPUT); 

  //Serial.begin(38400); // Start serial comms for display out 
  Serial.begin(115200);
  Serial1.begin(9600);// Start serial comms for scanner 
baudrate ();
Serial1.end();
  Serial1.begin(115200);
  opencon();
  Serial.print("FirmwareVersion: "); 
  for (f = 16; f < 20; f++) 
  { 
    Serial.print(ResponseData[f],HEX); //FirmwareVersion 
  } 
  Serial.println(); 
  Serial.print("DeviceSerialNumber: "); 
  for (f = 20; f < 36; f++) 
  { 
    Serial.print(ResponseData[f],HEX); //SerialNumber 
  } 
  delay(1000); 
  f=16;
} 

// Main Programme Loop 
void loop() { 
  // read the state of the switch into a local variable: 
  int reading1 = digitalRead(button1); 
  if (reading1 == HIGH && previous == LOW)
  { 
    Serial.println("LED ON");
    digitalWrite(ledPin, HIGH);
    Serial.println();
    ledon();
    previous = HIGH;
    reading1=LOW;
   capturefinger();
   delay(5000);
   getimage();
  }
  if(reading1 ==HIGH && previous == HIGH) 
  {
    Serial.println("LED OFF");
    digitalWrite(ledPin, LOW);
    ledoff();
    previous = LOW;
  }

}
//Subroutines go here 
void SendCmdPacket() 
{ 
  int a = 0; //Counter value 
  int checkvalue = 0; 

  //Calculate the value for the checksum; sum of the first ten command values in decimal 
  for (a = 0; a < 10; a++) 
  { 
    checkvalue = (checkvalue + CommandPacket[a]); 
  } 

  a= 0; //Reset the counter 

  // Assign the results of the checksum to the 12th and 11th values of the array 
  CommandPacket[10] = (lowByte(checkvalue)); 
  CommandPacket[11] = (highByte(checkvalue)); 

  // Print out values for debuging 
  Serial.println(); 
  Serial.print("checksum value (Decimal):- "); 
  Serial.println(checkvalue); 
  Serial.print("checksum value (Hex):- "); 
  Serial.println(checkvalue, HEX); 
  //Serial.println(lowByte(checkvalue)); 
  //Serial.println(highByte(checkvalue)); 
  Serial.println(); 

  //Write contents of array to scanner 
  Serial.println("Command sent to scanner:- "); 
  for (a = 0; a < 12; a++) 
  { 
    Serial1.write(CommandPacket[a]),HEX; 
    Serial.print(CommandPacket[a], HEX); 
    Serial.print(", "); 
  } 
  Serial.println(); 
  delay(500); 

  a= 0; //Reset the counter 

  //Read data returned from the scanner and assemble into array ResponseData 
  if (Serial1.available() > 0 ){ 
    for (a = 0; a < 38; a++) 
    { 
      ResponseData[a] = Serial1.read(),HEX; 
    } 
    a= 0; //Reset the counter 

    Serial.println(); 
    Serial.println("Responce from scanner:- "); 
    for (a = 0; a < 12; a++){ 
      Serial.print(ResponseData[a], HEX); 
    } 
    Serial.println(); 
    a= 0; //Reset the counter 
  } 
}
void SendCmdPacket1() 
{ 
  int a = 0; //Counter value 
  int checkvalue = 0; 

  //Calculate the value for the checksum; sum of the first ten command values in decimal 
  for (a = 0; a < 10; a++) 
  { 
    checkvalue = (checkvalue + CommandPacket[a]); 
  } 
  a= 0; //Reset the counter 
  // Assign the results of the checksum to the 12th and 11th values of the array 
  CommandPacket[10] = (lowByte(checkvalue)); 
  CommandPacket[11] = (highByte(checkvalue)); 
  // Print out values for debuging 
  Serial.println(); 
  Serial.print("checksum value (Decimal):- "); 
  Serial.println(checkvalue); 
  Serial.print("checksum value (Hex):- "); 
  Serial.println(checkvalue, HEX); 
  //Serial.println(lowByte(checkvalue)); 
  //Serial.println(highByte(checkvalue)); 
  Serial.println(); 

  //Write contents of array to scanner 
  Serial.println("Command sent to scanner:- "); 
  for (a = 0; a < 12; a++) 
  { 
    Serial1.write(CommandPacket[a]),HEX; 
    Serial.print(CommandPacket[a], HEX); 
    Serial.print(", "); 
  } 
  Serial.println(); 
  delay(500); 

  a= 0; //Reset the counter 

  //Read data returned from the scanner and assemble into array ResponseData 
 if (Serial1.available() > 0 ){ 
    /*for (a = 0; a<16; a++) 
    { 
      rawimageresponse = Serial1.read(),HEX;
      Serial.print(rawimageresponse, HEX);
      Serial.println(); 
    } 
    a=0;*/
//    Serial.print("%");
  //  Serial.println();
    for( b=0;b<256;b++){
    for (a=0;a<256;a++)
    {
      
       while (!Serial1.available()) ;  // Wait until a character is available
        rawimageresponse = Serial1.read();
        Serial.print(rawimageresponse,HEX);
    }
    Serial.println(); 
    a= 0; //Reset the counter 
  } 
}}


void opencon()
{

  CommandPacket[0] = ((byte)0x55); // Head1 :fixed 
  CommandPacket[1] = ((byte)0xAA); // Head2 :fixed 
  CommandPacket[2] = ((byte)0x01); // Device ID :fixed #1 
  CommandPacket[3] = ((byte)0x00); // Device ID :fixed #2 
  //Set default values for the Dword set 
  CommandPacket[4] = ((byte)0x01); // Dword #1 
  CommandPacket[5] = ((byte)0x00); // Dword #2 
  CommandPacket[6] = ((byte)0x00); // Dword #3 
  CommandPacket[7] = ((byte)0x00); // Dword #4


  CommandPacket[8] = ((byte)0x01); // Command code #1 
  CommandPacket[9] = ((byte)0x00); // Command Code #2
  SendCmdPacket();

}
void baudrate()
{
  CommandPacket[0] = ((byte)0x55); // Head1 :fixed 
  CommandPacket[1] = ((byte)0xAA); // Head2 :fixed 
  CommandPacket[2] = ((byte)0x01); // Device ID :fixed #1 
  CommandPacket[3] = ((byte)0x00); // Device ID :fixed #2
  CommandPacket[4] = ((byte)0x00); // Dword #1 
  CommandPacket[5] = ((byte)0xC2); // Dword #2 
  CommandPacket[6] = ((byte)0x01); // Dword #3 
  CommandPacket[7] = ((byte)0x00); // Dword #4 

  // Array values 8&9 define the command code. Check communication with scanner by getting S/N and F/W 
  CommandPacket[8] = ((byte)0x04); // Command code #1 
  CommandPacket[9] = ((byte)0x00); // Command Code #2 

  SendCmdPacket();
}

void ledon()
{
  CommandPacket[0] = ((byte)0x55); // Head1 :fixed 
  CommandPacket[1] = ((byte)0xAA); // Head2 :fixed 
  CommandPacket[2] = ((byte)0x01); // Device ID :fixed #1 
  CommandPacket[3] = ((byte)0x00); // Device ID :fixed #2
  CommandPacket[4] = ((byte)0x01); // Dword #1
  CommandPacket[5] = ((byte)0x00); // Dword #2 
  CommandPacket[6] = ((byte)0x00); // Dword #3 
  CommandPacket[7] = ((byte)0x00); // Dword #4
  CommandPacket[8] = ((byte)0x12); // Command code #1 Request enrol count 
  CommandPacket[9] = ((byte)0x00); // Command Code #2
  SendCmdPacket();
}
void capturefinger()
{
  CommandPacket[0] = ((byte)0x55); // Head1 :fixed 
  CommandPacket[1] = ((byte)0xAA); // Head2 :fixed 
  CommandPacket[2] = ((byte)0x01); // Device ID :fixed #1 
  CommandPacket[3] = ((byte)0x00); // Device ID :fixed #2
  CommandPacket[4] = ((byte)0x01); // Dword #1
  CommandPacket[5] = ((byte)0x00); // Dword #2 
  CommandPacket[6] = ((byte)0x00); // Dword #3 
  CommandPacket[7] = ((byte)0x00); // Dword #4
  CommandPacket[8] = ((byte)0x60); // Command code #1 Request enrol count 
  CommandPacket[9] = ((byte)0x00); // Command Code #2
  SendCmdPacket();
}

void getimage()
{
  CommandPacket[0] = ((byte)0x55); // Head1 :fixed 
  CommandPacket[1] = ((byte)0xAA); // Head2 :fixed 
  CommandPacket[2] = ((byte)0x01); // Device ID :fixed #1 
  CommandPacket[3] = ((byte)0x00); // Device ID :fixed #2
  CommandPacket[4] = ((byte)0x00); // Dword #1
  CommandPacket[5] = ((byte)0x00); // Dword #2 
  CommandPacket[6] = ((byte)0x00); // Dword #3 
  CommandPacket[7] = ((byte)0x00); // Dword #4
  CommandPacket[8] = ((byte)0x62); // Command code #1 Request enrol count 
  CommandPacket[9] = ((byte)0x00); // Command Code #2
  SendCmdPacket1();
}

Serial data transmission is ssslllooowww. You are expecting that all 19,200 bytes will arrive all at once. That will most definitely not happen.

What you need to do is sit in a loop, reading characters as they arrive, until all 19,200 characters have arrived.

can you explain more please how can i slow it a bit !

thanks

If I tell you that this response contains 19,200 characters, can't you count how many you have read? Can you stop reading when you get to 19,200?

If I end up typing less than 19,200 characters, can you see that you need to wait for me to type some more?

Why do you need to slow anything down? Isn't sending serial data slow enough already?

Yeah but the thing is that the sensor runs perfectly instantaneous when connected with FTDI and using the SDK-Demo program delivering the whole 19200 bytes. However i used Serial Monitor to look for the sequence of commands and Acks and it is the same as mine.

Yeah but the thing is that the sensor runs perfectly instantaneous when connected with FTDI and using the SDK-Demo program

No, it is NOT instantaneous. The SDK-Demo program is aware of how long the acquisition of 19200 bytes of data will take, and that the bytes do NOT all arrive at once. Which is a good thing, since the serial buffer on the Arduino is only 64 bytes.

The demo program reads, and uses, the data as fast (or slow) as it arrives, but it KNOWS that it is to stop reading only when the proper amount of data has arrived, however long it takes.

so what should i do now ?!

i tried fixing the loop for the write amount of data i need but it doesn't even go near the 19200 mark.

i tried fixing the loop for the write amount of data i need but it doesn't even go near the 19200 mark.

I made some code changes. I'm not going to tell you what I changed, but I can tell you that the code still doesn't work. What am I now doing wrong?

Did I paraphrase you correctly?