Skip to content

Instantly share code, notes, and snippets.

@yoggy
Created April 29, 2023 11:06
Show Gist options
  • Save yoggy/bfb197f69aaf3822e2b7a7476a86a9c0 to your computer and use it in GitHub Desktop.
Save yoggy/bfb197f69aaf3822e2b7a7476a86a9c0 to your computer and use it in GitHub Desktop.
pyserial samples
#!/usr/bin/python
import serial
import time
import datetime
s = serial.Serial("COM4", 9600)
while True:
line = s.readline().decode("utf-8")
print(line)
#!/usr/bin/python
import serial
import time
import datetime
s = serial.Serial("COM3", 9600)
while True:
time.sleep(10)
dt = datetime.datetime.now()
print(dt)
s.write(str.encode(dt.isoformat("T") + "\r\n"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment