Deferred debugging of the serial communication...

Arduino is not easy to debug, whenever the USB serial communication is not working like expected.

The serial monitor is not much of help, since the serial port is already used for the communication itself.

I have imagined to store the communication in an array in a first run, than stop the host, start the serial monitor to read the results.

The problem is to avoid the reset of the array between the two phases.

Since I am not very experienced with the Arduino and I expect it to be somewhat tricky, I would have highly appreciate if someone could give me some clues how to do that magic.

I would have highly appreciate if someone could give me some clues how to do that magic.

I don't think you can.

I have imagined to store the communication in an array in a first run

How much data? How do you define "a first run", so you know whether to store data or not?

than stop the host,

What do you mean by "the host"? The Arduino is busy all the time, doing something useful or just looking for something to do.

How do you intend to stop it?

start the serial monitor to read the results.

If you modify the Arduino to prevent resetting when the serial monitor application resets it as port of its startup process, the Arduino will have no way of knowing that the serial port now has something at the other end.

whenever the USB serial communication is not working like expected.

If your USB cable is bad, ASSuming you can make it better by using the process you have outlined is silly.

PaulS:

How much data? not much: less than 20 bytes in each direction

How do you define "a first run", so you know whether to store data or not? The problems happen during the initial shake-hands, that is what I must debug.

What do you mean by "the host"? The computer it's connected to.

The Arduino is busy all the time, doing something useful or just looking for something to do. How do you intend to stop it?

I did not intend to stop the Arduino, but the application it's connected to. And of course release the serial port. I am doing that regularily.

If you modify the Arduino to prevent resetting when the serial monitor application resets it as port of its startup process, the Arduino will have no way of knowing that the serial port now has something at the other end. Maybe writing to EEprom? That would survive a reset.

If your USB cable is bad, ASSuming you can make it better by using the process you have outlined is silly.

The USB cable is not bad, I am programing the Arduino through it.

Why not just intersperse your debug messages within the stream of normal messages. You could preface the debug message with "=======" so that it stands out. When you get the code working you can comment-out or delete the debug code.

If you are sending the data to a PC program it would be easy to arrange for the PC program to filter out messages that start with a given pattern.

...R