diff --git a/pi_numbers_separated_I2C_function.py b/pi_numbers_separated_I2C_function.py index d151bff..9e468c6 100644 --- a/pi_numbers_separated_I2C_function.py +++ b/pi_numbers_separated_I2C_function.py @@ -12,11 +12,9 @@ def read_data(num_numbers, bits_per_number): total_bytes = (num_numbers * bits_per_number + 7) // 8 # Define the filename - filename = f'{num_numbers}numbers_{bits_per_number}bits' + filename = f'{num_numbers}numbers_{bits_per_number}bits.bin' - start_time = time.time() # start time of read - - with open(filename + '.bin', 'wb') as file: + with open(filename, 'wb') as file: bytes_received = 0 while bytes_received < total_bytes: # Read a byte from the serial port @@ -25,17 +23,7 @@ def read_data(num_numbers, bits_per_number): bytes_received += 1 time.sleep(0.0000001) - end_time = time.time() # end time of read - elapsed_time = end_time - start_time - - seconds = int(elapsed_time) - milliseconds = int((elapsed_time % 1) * 1000) - - new_filename = f"{filename}_TimeInSeconds_{seconds}_{milliseconds}.bin" # filename in format filename_seconds_milliseconds as txt with needed time to finish read - - os.rename(filename + '.bin', new_filename) # change filename to new filename - - return new_filename + return filename def convert_to_hex(binary_filename, num_numbers, bits_per_number): with open(binary_filename, 'r') as f: @@ -83,7 +71,7 @@ def convert_to_binary(filename, num_numbers, bits_per_number): with open(binary_filename, 'w') as f: for i in range(0, len(truncated_binary_str), bits_per_number): binary_number = truncated_binary_str[i:i+bits_per_number] - f.write(binary_number + '') + f.write(binary_number) return binary_filename @@ -153,5 +141,5 @@ def analyze_data(num_numbers, bits_per_number, startup=False): return False # Teste den Code -result = analyze_data(8, 10003, startup=False) +result = analyze_data(50, 2560, startup=False) print(result)