Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #!/usr/bin/python
  2. import sys,array,fcntl
  3.  
  4. # from /usr/lib/python2.7/site-packages/serial/serialposix.py
  5. # /usr/include/asm-generic/termbits.h for struct termios2
  6. # [2]c_cflag [9]c_ispeed [10]c_ospeed
  7. def set_special_baudrate(fd, baudrate):
  8. TCGETS2 = 0x802C542A
  9. TCSETS2 = 0x402C542B
  10. BOTHER = 0o010000
  11. CBAUD = 0o010017
  12. buf = array.array('i', [0] * 64) # is 44 really
  13. fcntl.ioctl(fd, TCGETS2, buf)
  14. buf[2] &= ~CBAUD
  15. buf[2] |= BOTHER
  16. buf[9] = buf[10] = baudrate
  17. assert(fcntl.ioctl(fd, TCSETS2, buf)==0)
  18. fcntl.ioctl(fd, TCGETS2, buf)
  19. if buf[9]!=baudrate or buf[10]!=baudrate:
  20. print("failed. speed is %d %d" % (buf[9],buf[10]))
  21. sys.exit(1)
  22.  
  23. set_special_baudrate(0, int(sys.argv[1]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement