368d6fafea
Code backup
33 lines
689 B
Python
33 lines
689 B
Python
import serial
|
|
import struct
|
|
import time
|
|
|
|
# configurazione porta
|
|
PORT = 'COM3' # cambia se serve
|
|
BAUD = 921600
|
|
|
|
# struttura Sample = 1 uint32 + 2 IMUData
|
|
# IMUData = 6 int16
|
|
# Formato struct: < = little-endian
|
|
fmt = '<I6h6h' # ts, imu1(6h), imu2(6h)
|
|
sample_size = struct.calcsize(fmt)
|
|
|
|
ser = serial.Serial(PORT, BAUD, timeout=1)
|
|
print(f"Listening on {PORT}...")
|
|
|
|
try:
|
|
while True:
|
|
data = ser.read(sample_size)
|
|
if len(data) != sample_size:
|
|
continue
|
|
|
|
s = struct.unpack(fmt, data)
|
|
ts = s[0]
|
|
imu1 = s[1:7]
|
|
imu2 = s[7:13]
|
|
|
|
print(f"{ts} | 1:{imu1} | 2:{imu2}")
|
|
except KeyboardInterrupt:
|
|
ser.close()
|
|
print("Closed")
|