Advertisement
SyP-

Untitled

Sep 10th, 2022
762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import time
  3. import serial
  4. import sys
  5.  
  6.  
  7. ser = serial.Serial(
  8.         port='/dev/serial0', #Replace ttyS0 with ttyAM0 for Pi1,Pi2,Pi0
  9.         baudrate = 9600,
  10.         parity=serial.PARITY_NONE,
  11.         stopbits=serial.STOPBITS_ONE,
  12.         bytesize=serial.EIGHTBITS,
  13.         timeout=1
  14. )
  15.  
  16. ser.flush()
  17.  
  18. cw = int(sys.argv[1], 0)
  19. com = [cw]
  20. ser.write(serial.to_bytes(com))
  21. ser.flush()
  22. while True:
  23.         if ser.in_waiting > 0:
  24.             line = ser.readline().decode('utf-8', errors='replace').rstrip()
  25.             #time.sleep(0.1)
  26.             print(line)
  27.             ser.flush()
  28.             break
  29.    
  30. quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement