Upload files to ''

main
Orell-Pieter Schwarzbach 2023-05-23 11:23:10 +02:00
parent 4b519b2969
commit e2bbf9031a
1 changed files with 5 additions and 17 deletions

View File

@ -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)