SerialUSB instability - Program stalls

So I have been testing the stability of my SerialUSB stream for continuous output over long period of time and have been running into some problems.

Here is the Arduino code I am using to test:

void setup() {
  SerialUSB.begin(115200);
}

void loop() {
  double t_start=micros();
  
  SerialUSB.write(0x99);
  
  double t_end=micros();
  
  //Limit program to 200Hz speed
  while((t_end-t_start)<5000) {
    t_end=micros();
  }
}

And on my computer side I am using the following python module:

import time
import serial
import getPort //Module returns available serial ports for selection

portname=getPort.get_serial_port()
ser=serial.Serial(portname,115200,timeout=0.1)

try:
    while(1):
        t_loopstart=time.clock() 
        print ser.read(1)
        t_loopend=time.clock()
        print "Program Runspeed: %.1f\n" % (1/(t_loopend-t_loopstart))
finally:
    ser.close()
    print "Program Ended"

When I start these programs up at first communication is flawless. Then suddenly around 1 hour of runtime the arduino serial stream stops completely. No more data is transfered. If I stop the python program at this time then open the serial monitor in arduio there is still no serial data being transmitted. The only way to get the serial stream to begin again is to reupload the code to the arduino.

I really don't understand what is happening here, can anybody give me a hint?

I think your timer may have a hickup when rolling over to zero.

micros() should use a "unsigned long" and not a "double"

K

fiddler:
I think your timer may have a hickup when rolling over to zero.

micros() should use a "unsigned long" and not a "double"

K

Thanks, that was exactly the problem! Never would have guessed that.