added timer in console for writing and filename

main
Orell-Pieter Schwarzbach 2023-04-14 15:32:13 +02:00
parent d6168fd7d3
commit 2abc04b2b5
12 changed files with 35 additions and 9 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
const int adcPin = A0; // ADC-Pin const int adcPin = A0; // ADC-Pin
const int serialBaudRate = 9600; // Baudrate des seriellen Monitors const int serialBaudRate = 9600; // Baudrate des seriellen Monitors
const int toggleDelay = 0.5; // Verzögerung zwischen dem Umschalten der Bits, 1 ms evtl ausreichend -> testen! const float toggleDelay = 0.5; // Verzögerung zwischen dem Umschalten der Bits, in Mikrosekunden
void setup() { void setup() {
Serial.begin(serialBaudRate); // Starten des seriellen Monitors Serial.begin(serialBaudRate); // Starten des seriellen Monitors
@ -29,7 +29,9 @@ void loop() {
// Serial.print("Zahl: "); // Serial.print("Zahl: ");
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
Serial.print(vonNeumannAlgorithm(formatBinary(buffer[i]))); // Ausgabe der erzeugten 32-Bit-Werte im binären Format Serial.print(vonNeumannAlgorithm(formatBinary(buffer[i]))); // Ausgabe der erzeugten 32-Bit-Werte im binären Format mit von neumann
//Serial.print(formatBinary(buffer[i])); // Ausgabe der erzeugten 32-Bit-Werte im binären Format ohne von Neumann
} }
// Serial.println(); // Neue Zeile zur Trennung von anderen Ausgaben // Serial.println(); // Neue Zeile zur Trennung von anderen Ausgaben
} }
@ -58,3 +60,5 @@ String vonNeumannAlgorithm(String binaryString) {
return generatedString; // Rückgabe des erzeugten Strings return generatedString; // Rückgabe des erzeugten Strings
} }
//to do -> bin to hex, mit fuehrender 0

View File

@ -1,15 +1,28 @@
import os import os
import serial import serial
import time
ser = serial.Serial('COM3', 9600) # Hier musst du den richtigen Port und die richtige Baudrate einstellen ser = serial.Serial('COM3', 9600) # change port to input port from arduino
filename = 'binaryDataTestPython.bin' filename = 'mitNeumann_0_5'
start_time = time.time() # start time of read
with open(filename, 'wb') as file: with open(filename, 'wb') as file:
while os.path.getsize(filename) < 6000000: # prüfen, ob die Größe der Datei kleiner als 1 Kilobyte ist while os.path.getsize(filename) < 100000: # change to the desired file size in bits
if ser.in_waiting > 0: if ser.in_waiting > 0:
data = ser.read(ser.in_waiting) # Lesen Sie alle verfügbaren Bytes aus der seriellen Verbindung data = ser.read(ser.in_waiting) # reading the data input from COM port
print(data) print(data)
file.write(data) file.write(data)
file.flush() # Flushe die Datei, um die Daten zu schreiben 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.split('.')[0]}_TimeInSeconds_{seconds}_{milliseconds}.txt" # filename in format filename_seconds_milliseconds as txt with needed time to finish read
os.rename(filename, new_filename) # change filename to new filename
print(f"time needed in seconds: {elapsed_time:.2f}. New filename: {new_filename}.") # console write

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long