Arduino + vdip1 how to debug

Hello guys I'm working at a project using Arduino mega 2560 and VDIP1
< http://www.ftdichip.com/Firmware/Precompiled/UM_VinculumFirmware_V205.pdf >
The VDIP is connected to RX1 and TX1 on Arduino board.
I managed to write on the flash drive but the problem is that I need to run twice the open file write to file and close file block of code after I plugged in the flash drive. After that is writing well.

Another problem is that I can't manage to get all the messages from the vdip1. for example if I'm sending "FWV" command which should return the firmware version as: " FWV 0x0D 0x0D something 0x0D something 0x0D " I get back only FWV.

If anyone has any idea about my problems I would rely appreciate your help.

Another problem is that I can't manage to

post any code...

The code:

char incomingByte = 0;
int inPinFlow = 28;
int byte1= 0x61;

void setup(){
pinMode(inPinFlow, INPUT);
Serial.begin(57600);
Serial1.begin(9600);

Serial1.print("IPA");
Serial1.write(13);
WaitForResponse(1000);
Serial.println();
Serial.print("Initialization finished");
}

void loop(){

if (Serial.available()){

incomingByte = Serial.read();

Serial.println();
Serial.print("command = ");
Serial.print(incomingByte);
Serial.println();

if(incomingByte == '1'){

Serial1.print("OPW TEST2.HEX");
Serial1.write(13);
WaitForResponse(1000);

Serial.println();
Serial.print("Open file: ");
Serial.println();

Serial1.print("WRF 1");
Serial1.write(13);
WaitForResponse(1000);

Serial.println();
Serial.print("Prepare for writing: ");
Serial.println();

Serial1.write(byte1);
Serial1.write(13);
WaitForResponse(1000);

Serial.println();
Serial.print("Write: ");
Serial.println();
Serial1.print("CLF TEST2.HEX");
Serial1.write(13);
WaitForResponse(1000);

Serial.println();
Serial.print("Close file: ");
Serial.println();

Serial.print("END");
Serial.println();
}
else if(incomingByte == '2'){
Serial.print("FWV");
Serial.write(13);
WaitForResponse(1000);
}else if(incomingByte == '3'){

}
}
}

void WaitForResponse(unsigned long timeout)
{
char charRead;
unsigned long start = millis();
while (millis() - start <= timeout)
{
if (Serial1.available() > 0)
{
charRead = Serial1.read();
if (charRead == 0x0D) {
Serial.println();
} else {
Serial.print(charRead);
}
if (charRead == 0x0D)
{
return;
}
}
}
Serial.print("Timeout: ");
Serial.println(millis() - start);
}

or example if I'm sending "FWV" command which should return the firmware version as: " FWV 0x0D 0x0D something 0x0D something 0x0D " I get back only FWV.

What does your code do when it gets a 0x0D? It prints a carriage return and line feed, and then returns. Why?

I took that function from an example I tried to make a function to recognise the prompt recording each character that it was coming from VDIP into a array of 3 chars and compare it with ":>" but it didn't worked. Can you give me an example how I should get each respond from the VDIP?