PageRenderTime 170ms CodeModel.GetById 83ms RepoModel.GetById 1ms app.codeStats 0ms

/experimental/serial_read/testportread.py

http://cellbots.googlecode.com/
Python | 24 lines | 23 code | 1 blank | 0 comment | 0 complexity | e7964ee5e0efa81eac3df2cb23cab114 MD5 | raw file
  1. import os, time, socket, select
  2. svr_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  3. svr_sock.bind(('', 9002))
  4. svr_sock.listen(3)
  5. svr_sock.setblocking(0)
  6. rs = []
  7. while 1:
  8. r,w,_ = select.select([svr_sock] + rs, [], [])
  9. print "out of select loop"
  10. for cli in r:
  11. if cli == svr_sock:
  12. new_cli,addr = svr_sock.accept()
  13. rs = [new_cli]
  14. else:
  15. msg = cli.recv(1024)
  16. print "received: %s" % msg
  17. os.system("echo '%s\n' > /dev/ttyMSM2" % msg)
  18. time.sleep(1)
  19. os.system("echo 's\n' > /dev/ttyMSM2")