Bladeren bron

'lol.py' hinzufügen

maxscheinast 7 maanden geleden
bovenliggende
commit
25a05ed1d2
1 gewijzigde bestanden met toevoegingen van 31 en 0 verwijderingen
  1. 31 0
      lol.py

+ 31 - 0
lol.py

@@ -0,0 +1,31 @@
+def get_data():
+    import serial
+    import time
+
+    # Configure serial port (adjust port name as needed)
+    ser = serial.Serial('COM10', 9600)
+
+    # Wait for the serial connection to establish
+    ser.timeout = 2
+
+    #ser.write(b'testcom.py\n')  # Send command to start the script
+    while True:
+        
+        # Read data from serial port
+        data = ser.readline().decode().strip()
+
+        # Check if data is not empty
+        #print(data)
+        if data:
+            try:
+                # Attempt to convert data to float
+                value = float(data)
+                timestamp = time.time()
+                return timestamp, value
+            except ValueError:
+                print("Invalid data format:", data)
+        else:
+            print("Empty data received")
+        
+        # Add a small delay to prevent rapid looping
+        time.sleep(0.001)