Update 'REST/I2C_Function.py'
parent
33a7e1bd7d
commit
9cf70dc3a5
|
@ -16,16 +16,20 @@ def read_data(num_numbers, bits_per_number):
|
||||||
# Define the filename
|
# Define the filename
|
||||||
filename = f'{num_numbers}numbers_{bits_per_number}bits.bin'
|
filename = f'{num_numbers}numbers_{bits_per_number}bits.bin'
|
||||||
|
|
||||||
with open(filename, 'wb') as file:
|
try:
|
||||||
bytes_received = 0
|
with open(filename, 'wb') as file:
|
||||||
while bytes_received < total_bytes:
|
bytes_received = 0
|
||||||
# Read a byte from the serial port
|
while bytes_received < total_bytes:
|
||||||
data = bus.read_byte(addr)
|
# Read a byte from the serial port
|
||||||
file.write(bytes([data]))
|
data = bus.read_byte(addr)
|
||||||
bytes_received += 1
|
file.write(bytes([data]))
|
||||||
time.sleep(0.0000001)
|
bytes_received += 1
|
||||||
|
time.sleep(0.0000001)
|
||||||
|
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
|
except IOError as e:
|
||||||
|
return False
|
||||||
|
|
||||||
def convert_to_hex(binary_filename, num_numbers, bits_per_number):
|
def convert_to_hex(binary_filename, num_numbers, bits_per_number):
|
||||||
with open(binary_filename, 'r') as f:
|
with open(binary_filename, 'r') as f:
|
||||||
|
@ -110,6 +114,8 @@ def analyze_data(num_numbers, bits_per_number, startup):
|
||||||
|
|
||||||
if startup:
|
if startup:
|
||||||
filename = read_data(10, 80000)
|
filename = read_data(10, 80000)
|
||||||
|
if not filename:
|
||||||
|
return False
|
||||||
binary_filename = convert_to_binary(filename, 10, 80000)
|
binary_filename = convert_to_binary(filename, 10, 80000)
|
||||||
perform_startup_tests(binary_filename)
|
perform_startup_tests(binary_filename)
|
||||||
perform_tot_online_tests(binary_filename)
|
perform_tot_online_tests(binary_filename)
|
||||||
|
@ -118,6 +124,8 @@ def analyze_data(num_numbers, bits_per_number, startup):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
filename = read_data(10, 20000)
|
filename = read_data(10, 20000)
|
||||||
|
if not filename:
|
||||||
|
return False
|
||||||
binary_filename = convert_to_binary(filename, 10, 20000)
|
binary_filename = convert_to_binary(filename, 10, 20000)
|
||||||
result = perform_tot_online_tests(binary_filename)
|
result = perform_tot_online_tests(binary_filename)
|
||||||
os.unlink(filename)
|
os.unlink(filename)
|
||||||
|
@ -150,7 +158,7 @@ def analyze_data(num_numbers, bits_per_number, startup):
|
||||||
os.unlink(filename)
|
os.unlink(filename)
|
||||||
os.unlink(binary_filename)
|
os.unlink(binary_filename)
|
||||||
os.unlink(hex_filename)
|
os.unlink(hex_filename)
|
||||||
return False
|
return 400
|
||||||
|
|
||||||
# Teste den Code
|
# Teste den Code
|
||||||
#result = analyze_data(8, 8, startup=True)
|
#result = analyze_data(8, 8, startup=True)
|
||||||
|
|
Loading…
Reference in New Issue