Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import time
  4. import serial
  5. import sys
  6.  
  7. direc = {'1': 'left', '0': 'right'}
  8. yesno = {'1': 'yes', '0': 'no' }
  9. if __name__ == "__main__":
  10. ser = serial.Serial(
  11.  
  12. port='/dev/ttyUSB0',
  13. baudrate = 9600,
  14. parity=serial.PARITY_NONE,
  15. stopbits=serial.STOPBITS_ONE,
  16. bytesize=serial.EIGHTBITS,
  17. timeout=1
  18. )
  19.  
  20. ser.write(sys.argv[1])
  21. ser.flush()
  22. time.sleep(1)
  23. while True:
  24. ln = ser.readline().strip()
  25. if not ln:
  26. break
  27. cds = ln.split("/")
  28.  
  29. if cds[1] == '22':
  30. print("magnet: %s" % cds[2])
  31. elif cds[1] == '20':
  32. print("temper: %s" % cds[2])
  33. elif cds[1] == '21':
  34. print("step no: %s" % cds[2])
  35. elif cds[1] == '23':
  36. print("turn over at step no: %s" % cds[2])
  37. elif cds[1] == '24':
  38. print("begin step no: %s" % cds[2])
  39. elif cds[1] == '25':
  40. print("calibration: %s" % yesno[cds[2]])
  41. elif cds[1] == '26':
  42. print("direction: %s" % direc[cds[2]])
  43.  
  44.  
  45.  
  46.  
  47. else:
  48. print(ln)
  49. ser.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement