node.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import time
  2. import asyncio
  3. import async_communication as ASC
  4. import ExportIO as EIO
  5. import google.protobuf.text_format as tf
  6. import threading
  7. import DatabaseSearchPickCmd as DBS
  8. import message_pb2 as message
  9. import queue
  10. #db参数
  11. db_parameter={"dbname":"ct_project","ip":"192.168.1.233","port":3306,"user":"zx","password":"zx123456"}
  12. rabbitmq_parameter={"ip":"192.168.1.233","port":5672,"user":"zx","password":"zx123456"}
  13. #[单元号,出口号,单片机ip,port]
  14. mcpu_paramters=[[1,1, "192.168.1.130", 40004],
  15. [2,2, "192.168.1.131", 40004],
  16. [2,3, "192.168.1.132", 40004],
  17. [2,4, "192.168.1.133", 40004]#,
  18. # [3,5,"192.168.1.134",40004],
  19. # [3,6,"192.168.1.135",40004]
  20. ]
  21. # mcpu_paramters=[[2,3,"192.168.1.132",40004]]
  22. g_rabbitmq=ASC.RabbitAsyncCommunicator(rabbitmq_parameter["ip"],rabbitmq_parameter["port"],
  23. rabbitmq_parameter['user'],rabbitmq_parameter['password'])
  24. g_db=DBS.DBSeacherPickCmd(db_parameter["ip"],db_parameter["port"],db_parameter["dbname"],
  25. db_parameter["user"],db_parameter["password"])
  26. g_exports={}
  27. def user_leave_callback(id):
  28. print("出口:%d 用户已经离开,删除出口取车指令"%(id))
  29. g_db.delete_cmd(id)
  30. if __name__=="__main__":
  31. print("出口 danpianji")
  32. for parameter in mcpu_paramters:
  33. id=parameter[1]
  34. if not g_exports.get(id)==None:
  35. raise("出口单片机id重复")
  36. g_exports[id]=EIO.ExportIO(parameter,rabbitmq_parameter)
  37. g_exports[id].SetUserLeaveCallback(user_leave_callback)
  38. for _,export in g_exports.items():
  39. export.start()
  40. while True:
  41. pickcmds=g_db.search_pickcmd()
  42. # print(pickcmds)
  43. if len(pickcmds)>0:
  44. for cmd in pickcmds:
  45. table=message.pick_table()
  46. # table.car_number=cmd[0]
  47. # table.primary_key=cmd[1]
  48. # table.unit_id=cmd[2]
  49. # table.queue_id=cmd[3]
  50. # table.export_id=cmd[8]
  51. table.car_number=cmd["car_number"]
  52. table.primary_key=cmd["primary_key"]
  53. table.unit_id=cmd["unit"]
  54. table.queue_id=cmd["queue_id"]
  55. table.export_id=cmd["export_id"]
  56. # print(table)
  57. if not table.export_id==None:
  58. export=g_exports.get(table.export_id)
  59. if not export==None:
  60. # if export.export_idle()==False:
  61. export.open_door(table)
  62. time.sleep(1)
  63. for _,export in g_exports.items():
  64. export.join()