mmu_man

dump from CMS 50F 3.7

Aug 17th, 2014
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. #cf. http://elinux.org/Serial_port_programming
  4.  
  5. import serial
  6. import sys
  7.  
  8. #port = serial.Serial("/dev/ttyUSB1")
  9.  
  10.  
  11.  
  12. def send_cmd(p, c):
  13. print "> %s" % c
  14. c = c.replace(' ', '')
  15. c = c.decode("hex")
  16. #print c.encode("hex")
  17. p.write(c)
  18.  
  19. def recv_data(p, l):
  20. data = ''
  21. for i in range(l):
  22. print "waiting for byte"
  23.  
  24. d = p.read(1)
  25. print "< %s" % d.encode("hex")
  26. data.append(d)
  27. return d
  28.  
  29. if len(sys.argv) < 2:
  30. print "Usage: %s serialdev" % sys.argv[0]
  31. exit(1)
  32.  
  33. with serial.Serial(sys.argv[1], 19200) as p:
  34. print p.isOpen()
  35. send_cmd(p, '7d 81 a7 80 80 80 80 80 80')
  36. recv_data(p, 2)
  37. send_cmd(p, '7d 81 a2 80 80 80 80 80 80')
  38. recv_data(p, 2)
  39. send_cmd(p, '7d 81 a0 80 80 80 80 80 80')
  40. recv_data(p, 4)
Add Comment
Please, Sign In to add comment