Created
February 16, 2022 05:10
-
-
Save rdandy/df1622af2087d7deec5b87b256793c81 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# serial_write.py | |
import serial, time | |
SERIALPORT = "/dev/ttyS0" | |
ser = serial.Serial(SERIALPORT, baudrate=115200, bytesize=8, parity="N", stopbits=1, rtscts=False, xonxoff=False) | |
def write_data(): | |
while True: | |
txt = input("input some thing ...\r\n") | |
if txt.startswith("exit"): | |
break | |
print(txt) | |
ser.write(bytearray(txt.strip().encode()) + b'\r\n') | |
print("bye!") | |
if __name__ == '__main__': | |
print(ser) | |
print("write data") | |
write_data() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment