Upload files to 'Archiv'
parent
f5d616a904
commit
008137f82b
|
@ -0,0 +1,48 @@
|
|||
import os
|
||||
import serial
|
||||
import time
|
||||
from smbus import SMBus
|
||||
|
||||
addr = 0x8
|
||||
bus = SMBus(1)
|
||||
|
||||
#ser = serial.Serial('/dev/ttyACM0', 115200) # change port to input port from arduino
|
||||
filename = 'i2C_Arduino_test'
|
||||
|
||||
start_time = time.time() # start time of read
|
||||
|
||||
with open(filename + '.bin', 'wb') as file:
|
||||
while os.path.getsize(filename + '.bin') < 1000: # change to the desired file size in bits/8 (1,000,000 Bits = 125000)
|
||||
#if ser.in_waiting > 0:
|
||||
data = bus.read_byte(addr)
|
||||
#data = ser.read(ser.in_waiting) # reading the data input from COM port
|
||||
#print(data)
|
||||
file.write(data)
|
||||
file.flush() # flush data to write
|
||||
|
||||
end_time = time.time() # end time of read
|
||||
elapsed_time = end_time - start_time
|
||||
|
||||
seconds = int(elapsed_time)
|
||||
milliseconds = int((elapsed_time % 1) * 100)
|
||||
|
||||
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
|
||||
|
||||
# Open the file in binary mode
|
||||
with open(new_filename, 'rb') as f:
|
||||
# Read the contents of the file as bytes
|
||||
content = f.read()
|
||||
|
||||
# Convert the bytes to a string of hexadecimal digits
|
||||
hex_str = content.hex()
|
||||
|
||||
# Convert the bytes to a string of binary digits
|
||||
#binary_str = ''.join(format(byte, '08b') for byte in content)
|
||||
|
||||
# Write the binary string back to the file
|
||||
#with open(new_filename.split('.')[0] + '_asTXT.txt', 'w') as f:
|
||||
#f.write(binary_str)
|
||||
|
||||
print(f"time needed in seconds: {elapsed_time:.2f}. New filename: {new_filename}.") # console write
|
|
@ -0,0 +1,75 @@
|
|||
import os
|
||||
import serial
|
||||
import time
|
||||
from smbus import SMBus
|
||||
|
||||
addr = 0x8
|
||||
bus = SMBus(1)
|
||||
|
||||
# define the number of numbers and bits per number to generate
|
||||
num_numbers = 60
|
||||
bits_per_number = 5000
|
||||
|
||||
# calculate the total file size in bits
|
||||
filesize = num_numbers * bits_per_number
|
||||
|
||||
# define the filename
|
||||
filename = f'{num_numbers}numbers_{bits_per_number}bits'
|
||||
|
||||
start_time = time.time() # start time of read
|
||||
|
||||
with open(filename + '.bin', 'wb') as file:
|
||||
for i in range(num_numbers):
|
||||
# write the separator between numbers except for the last one
|
||||
#if i != num_numbers - 1:
|
||||
#file.write(b'' + b'')
|
||||
for j in range(bits_per_number // 8):
|
||||
# read one byte from the serial port
|
||||
data = bus.read_byte(addr)
|
||||
file.write(bytes([data]))
|
||||
time.sleep(0.000001)
|
||||
|
||||
|
||||
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
|
||||
|
||||
# Open the file in binary mode
|
||||
with open(new_filename, 'rb') as f:
|
||||
# Read the contents of the file as bytes
|
||||
content = f.read()
|
||||
print(content)
|
||||
|
||||
# Convert the bytes to a string of hexadecimal digits with zero padding
|
||||
hex_str = ''.join(format(byte, '02x') for byte in content).zfill(num_numbers * (bits_per_number // 4))
|
||||
|
||||
# Write the hex string to the file with separators and newlines
|
||||
with open(filename + '.txt', 'w') as f:
|
||||
for i in range(num_numbers):
|
||||
hex_number = hex_str[i * (bits_per_number // 4) : (i+1) * (bits_per_number // 4)]
|
||||
# write the separator between numbers except for the last one
|
||||
if i != num_numbers - 1:
|
||||
hex_number += '//'
|
||||
f.write(hex_number + '\n')
|
||||
|
||||
print(f"time needed in seconds: {elapsed_time:.2f}. New filename: {new_filename}.") # console write
|
||||
|
||||
# Open the file in binary mode
|
||||
with open(new_filename, 'rb') as f:
|
||||
# Read the contents of the file as bytes
|
||||
content = f.read()
|
||||
|
||||
# Convert the bytes to a string of binary digits
|
||||
binary_str = ''.join(format(byte, '08b') for byte in content)
|
||||
|
||||
# Write the binary string back to the file with separators
|
||||
with open(filename + '_binary.txt', 'w') as f:
|
||||
for i in range(0, len(binary_str), bits_per_number):
|
||||
binary_number = binary_str[i:i+bits_per_number]
|
||||
f.write(binary_number + '')
|
|
@ -0,0 +1,72 @@
|
|||
import os
|
||||
import serial
|
||||
import time
|
||||
|
||||
ser = serial.Serial('/dev/ttyACM0', 115200) # change port to input port from arduino
|
||||
|
||||
# define the number of numbers and bits per number to generate
|
||||
num_numbers = 50
|
||||
bits_per_number = 5000
|
||||
|
||||
# calculate the total file size in bits
|
||||
filesize = num_numbers * bits_per_number
|
||||
|
||||
# define the filename
|
||||
filename = f'{num_numbers}numbers_{bits_per_number}bits'
|
||||
|
||||
start_time = time.time() # start time of read
|
||||
|
||||
with open(filename + '.bin', 'wb') as file:
|
||||
for i in range(num_numbers):
|
||||
# write the separator between numbers except for the last one
|
||||
if i != num_numbers - 1:
|
||||
file.write(b'' + b'')
|
||||
for j in range(bits_per_number // 8):
|
||||
# read one byte from the serial port
|
||||
byte = ser.read(1)
|
||||
file.write(byte)
|
||||
|
||||
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
|
||||
|
||||
# Open the file in binary mode
|
||||
with open(new_filename, 'rb') as f:
|
||||
# Read the contents of the file as bytes
|
||||
content = f.read()
|
||||
print(content)
|
||||
|
||||
# Convert the bytes to a string of hexadecimal digits with zero padding
|
||||
hex_str = ''.join(format(byte, '02x') for byte in content).zfill(num_numbers * (bits_per_number // 4))
|
||||
|
||||
# Write the hex string to the file with separators and newlines
|
||||
with open(filename + '.txt', 'w') as f:
|
||||
for i in range(num_numbers):
|
||||
hex_number = hex_str[i * (bits_per_number // 4) : (i+1) * (bits_per_number // 4)]
|
||||
# write the separator between numbers except for the last one
|
||||
if i != num_numbers - 1:
|
||||
hex_number += '//'
|
||||
f.write(hex_number + '\n')
|
||||
|
||||
print(f"time needed in seconds: {elapsed_time:.2f}. New filename: {new_filename}.") # console write
|
||||
|
||||
# Open the file in binary mode
|
||||
with open(new_filename, 'rb') as f:
|
||||
# Read the contents of the file as bytes
|
||||
content = f.read()
|
||||
|
||||
# Convert the bytes to a string of binary digits
|
||||
binary_str = ''.join(format(byte, '08b') for byte in content)
|
||||
|
||||
# Write the binary string back to the file with separators
|
||||
with open(filename + '_binary.txt', 'w') as f:
|
||||
for i in range(0, len(binary_str), bits_per_number):
|
||||
binary_number = binary_str[i:i+bits_per_number]
|
||||
f.write(binary_number + '\n')
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
import os
|
||||
import serial
|
||||
import time
|
||||
|
||||
ser = serial.Serial('/dev/ttyACM0', 115200) # change port to input port from arduino
|
||||
filename = '1MioTestdaten'
|
||||
filesize = 8000000
|
||||
|
||||
start_time = time.time() # start time of read
|
||||
|
||||
with open(filename + '.bin', 'wb') as file:
|
||||
while os.path.getsize(filename + '.bin') < filesize/8: # change to the desired file size in bits/8 (1,000,000 Bits = 125000)
|
||||
if ser.in_waiting > 0:
|
||||
data = ser.read(ser.in_waiting) # reading the data input from COM port
|
||||
#print(data)
|
||||
file.write(data)
|
||||
file.flush() # flush data to write
|
||||
|
||||
end_time = time.time() # end time of read
|
||||
elapsed_time = end_time - start_time
|
||||
|
||||
seconds = int(elapsed_time)
|
||||
milliseconds = int((elapsed_time % 1) * 100)
|
||||
|
||||
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
|
||||
|
||||
# Open the file in binary mode
|
||||
with open(new_filename, 'rb') as f:
|
||||
# Read the contents of the file as bytes
|
||||
content = f.read()
|
||||
|
||||
# Convert the bytes to a string of hexadecimal digits
|
||||
hex_str = content.hex()
|
||||
|
||||
# Convert the bytes to a string of binary digits
|
||||
#binary_str = ''.join(format(byte, '08b') for byte in content)
|
||||
|
||||
# Write the binary string back to the file
|
||||
#with open(new_filename.split('.')[0] + '_asTXT.txt', 'w') as f:
|
||||
#f.write(binary_str)
|
||||
|
||||
print(f"time needed in seconds: {elapsed_time:.2f}. New filename: {new_filename}.") # console write
|
|
@ -0,0 +1,14 @@
|
|||
import smbus
|
||||
|
||||
bus = smbus.SMBus(1) # I2C-Bus-Nummer
|
||||
address = 8 # Arduino-Geräteadresse
|
||||
|
||||
while True:
|
||||
data = []
|
||||
for i in range(8):
|
||||
buf = bus.read_i2c_block_data(address, i*4, 4) # 4 Bytes (32 Bit) lesen
|
||||
val = int.from_bytes(buf, byteorder='little') # Bytes in Integer-Wert konvertieren
|
||||
data.append(val)
|
||||
|
||||
# Daten verarbeiten
|
||||
print(data)
|
Loading…
Reference in New Issue