Skip to content

Instantly share code, notes, and snippets.

@executed
Created January 15, 2026 19:59
Show Gist options
  • Select an option

  • Save executed/d399ed8e4f209277543ffecdc954585a to your computer and use it in GitHub Desktop.

Select an option

Save executed/d399ed8e4f209277543ffecdc954585a to your computer and use it in GitHub Desktop.
DNA Board Serial Command Demo
#!/usr/bin/env python3
import serial, time, sys, binascii
PORT = '/dev/ttyACM0' # change if needed
CMD = b'P=GET SP\r\n' # example command; use CRLF
TIMEOUT = 2.0 # seconds to wait for reply
def main():
try:
ser = serial.Serial(PORT, 115200, timeout=0.1)
except Exception as e:
print("Open error:", e); sys.exit(1)
ser.reset_input_buffer()
ser.reset_output_buffer()
ser.write(CMD)
ser.flush()
print("Sent:", CMD)
# read up to TIMEOUT seconds and collect bytes
t0 = time.time()
buf = bytearray()
while time.time() - t0 < TIMEOUT:
chunk = ser.read(4096)
if chunk:
buf.extend(chunk)
else:
time.sleep(0.01)
ser.close()
if not buf:
print("No response within", TIMEOUT, "s")
else:
try:
print("ASCII:", buf.decode('utf-8', errors='replace'))
except:
pass
print("HEX: ", binascii.hexlify(buf))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment