eris2206

Documentation: http://frombelow.net/projects/eris2206/
Clone: git clone https://git.frombelow.net/eris2206.git
Log | Files | Refs | Submodules | README | LICENSE

send_serial.py (743B)


      1 #!/usr/bin/env python3
      2 
      3 # Copyright 2022 Gerd Beuster (gerd@frombelow.net). This is free soft
      4 # under the GNU GPL v3 license or any later version. See COPYING in
      5 # the root directory for details.
      6 
      7 import sys
      8 import serial
      9 import time
     10 
     11 PORT = '/dev/ttyUSB1'
     12 SPEED = 115200
     13 
     14 def send_file(filename):
     15     s = serial.Serial(PORT, SPEED)
     16     with open(filename, "r") as f:
     17         for line in f:
     18             line_as_bytes = map(lambda x: int(x, 16), filter(lambda x: x != '', line.split(" ")))
     19             for b in line_as_bytes:
     20                 print("{:02X}".format(b))
     21                 time.sleep(.1)
     22                 s.write(bytes([b]))
     23                 assert(s.read(1) == b'\xaa')
     24 
     25 if __name__ == '__main__':
     26     send_file(filename=sys.argv[1])