Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. import time
  2. import serial
  3. import server
  4. import requests
  5. from multiprocessing import Process
  6. from read_ports import serial_ports
  7.  
  8. ser=serial.Serial(serial_ports()[0],115200)
  9. START = 7
  10. DONE = 0
  11.  
  12.  
  13. def shelfarray(text):
  14. pspairs = text.split(';') # package-shelf-pairs
  15. instructions = [START]
  16. for i in range(0, len(pspairs)):
  17. pair = pspairs[i].split(',')
  18. package = pair[0]
  19. shelf = pair[1]
  20. instructions = instructions + [int(shelf)]
  21. instructions = instructions + [DONE]
  22. print instructions
  23. return instructions
  24.  
  25.  
  26. if __name__ == "__main__":
  27. process = Process(target=server.run)
  28. process.start()
  29. is_executing_plan = False
  30. time.sleep(5)
  31. while 1:
  32. if (not is_executing_plan):
  33. r = requests.get('http://0.0.0.0:5000/getinstructions')
  34. if (r.text != "0"):
  35. instructions = shelfarray(r.text.strip())
  36. ser.write(bytearray(instructions))
  37. is_executing_plan = True
  38. elif (ser.in_waiting > 0):
  39. line = ser.readline().strip()
  40. if (line == "done"):
  41. is_executing_plan = False
  42. else:
  43. requests.get('http://0.0.0.0:5000/addnotification?not=' + line)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement