def main(baudrate, pwm_freq, pwm_duty, num_samples, delays_file):
    ser = serial.Serial(port='/dev/ttyUSB0', baudrate=baudrate, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, rtscts=0)
    if (not ser.is_open):
        print('Error opening serial port device.')
        sys.exit(1)
    checkparams(pwm_freq, pwm_duty, num_samples)
    print('Params OK!')
    delays = np.empty(num_samples)
    ser.write(str.encode('{},{},{}\r\n'.format(pwm_freq, pwm_duty, num_samples)))
    timer_frequency = int(ser.readline().strip())
    ser.write(str.encode('\n'))
    for i in range(num_samples):
        delays[i] = int(ser.readline().strip())
    ser.close()
    delays *= (1e-06 / timer_frequency)
    delays = np.delete(delays, 0)
    delays = np.delete(delays, 0)
    print('min: {}, avg: {}, max = {}'.format(np.min(delays), np.mean(delays), np.max(delays)))
    print('std: ', np.std(delays))
    LOG_FILE = open(delays_file, 'w')
    np.save(delays_file, delays)
def main(baudrate, pwm_freq, pwm_duty, num_samples, delays_file):
    ser = serial.Serial(port='/dev/ttyUSB0', baudrate=baudrate, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, rtscts=0)
    if (not ser.is_open):
        print('Error opening serial port device.')
        sys.exit(1)
    checkparams(pwm_freq, pwm_duty, num_samples)
    print('Params OK!')
    delays = np.empty(num_samples)
    ser.write(str.encode('{},{},{}\r\n'.format(pwm_freq, pwm_duty, num_samples)))
    timer_frequency = int(ser.readline().strip())
    ser.write(str.encode('\n'))
    for i in range(num_samples):
        delays[i] = int(ser.readline().strip())
    ser.close()
    delays *= (1e-06 / timer_frequency)
    delays = np.delete(delays, 0)
    delays = np.delete(delays, 0)
    print('min: {}, avg: {}, max = {}'.format(np.min(delays), np.mean(delays), np.max(delays)))
    print('std: ', np.std(delays))
    LOG_FILE = open(delays_file, 'w')
    np.save(delays_file, delays)