Update 'print_COM_as_bin_and_txt.py'

just bin file to use not so much RAM
main
Orell-Pieter Schwarzbach 2023-04-24 13:13:39 +02:00
parent 6d1400545a
commit 22cf5083c2
1 changed files with 8 additions and 7 deletions

View File

@ -2,16 +2,16 @@ import os
import serial
import time
ser = serial.Serial('COM3', 115200) # change port to input port from arduino
filename = 'baud115200_0_2_TEST'
ser = serial.Serial('/dev/ttyACM0', 115200) # change port to input port from arduino
filename = 'BSI_Testdaten'
start_time = time.time() # start time of read
with open(filename + '.bin', 'wb') as file:
while os.path.getsize(filename + '.bin') < 2500: # change to the desired file size in bits/8 (1,000,000 Bits = 125000)
while os.path.getsize(filename + '.bin') < 128000000: # 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)
#print(data)
file.write(data)
file.flush() # flush data to write
@ -34,10 +34,11 @@ with open(new_filename, 'rb') as f:
hex_str = content.hex()
# Convert the bytes to a string of binary digits
binary_str = ''.join(format(byte, '08b') for byte in content)
#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)
#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