Not able to get serial print enable after uc awake from sleep , please suggest

*/
//#define Serial SerialUSB
#include <RTCZero.h>

/* Create an rtc object */
RTCZero rtc;
int AlarmTime;

void setup()
{
rtc.begin();
Serial.begin(9600);
while (! Serial); // Wait until Serial is ready
Serial.println("Ready!");
Serial.end();
}

void loop()
{

AlarmTime = rtc.getSeconds()+10; // Adds 10 seconds to alarm time
AlarmTime = AlarmTime % 60; // checks for roll over 60 seconds and corrects
Serial.print("Next Alarm Time:");
Serial.println(AlarmTime);

rtc.setAlarmSeconds(AlarmTime); // Wakes at next alarm time
rtc.enableAlarm(rtc.MATCH_SS); // Match seconds only
rtc.attachInterrupt(alarmMatch);

Serial.end();
USBDevice.detach(); // Safely detach the USB prior to sleeping
rtc.standbyMode(); // Sleep until next alarm match
USBDevice.init();
USBDevice.attach(); // Re-attach the USB, audible sound on windows machines

// Simple indication of being awake
digitalWrite(13, HIGH); // turn the LED on
delay(100);
digitalWrite(13, LOW); // turn the LED off
delay(100);
digitalWrite(13, HIGH); // turn the LED on
delay(100);
digitalWrite(13, LOW); // turn the LED off

delay(1000); // Delay added to make serial more reliable

Serial.begin(9600);
while (! Serial); _{}// Wait until Serial is ready
delay(1000);
Serial.println("Awake");
}

void alarmMatch() // Do something when interrupt called
{

}

Please correct your post above and add code tags around your code:
[code]`` [color=blue]// your code is here[/color] ``[/code].

It should look like this:// your code is here
(Also press ctrl-T (PC) or cmd-T (Mac) in the IDE before copying to indent your code properly)


when you re-attach to the PC, you are not guaranteed to attach at the same place also the client might have been disconnected.

You could try to add some sort tof reasonably long enough delay (5 to 10 seconds) after

USBDevice.attach(); // Re-attach the USB, audible sound on windows machines

(as hinted in in the other forum where you posted)