1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- import time
- import pymysql as psql
- import message_pb2 as message
- import threading
- class DBSeacherPickCmd():
- def __init__(self,ip,port,database,user,password):
- self.ip=ip
- self.port=port
- self.database=database
- self.user=user
- self.password=password
- self._close=False
- self._opendoor_callback=None
- self.conn=psql.connect(host=ip,
- port=port,
- database=database,
- charset="utf8",
- user=user,
- passwd=password)
- def close(self):
- self._close=True
- self.join()
- self.conn.close()
- def search_pickcmd(self):
- # self.conn.begin()
- cursor=self.conn.cursor()
- SQL="select * from command_queue where statu=2 " #寻找已到出口的取车指令
- cursor.execute(SQL)
- pick_cmds=cursor.fetchall()
- self.conn.commit()
- cursor.close()
- return pick_cmds
- def delete_cmd(self,id):
- # self.conn.begin()
- cursor=self.conn.cursor()
- SQL1="select * from command_queue for update"
- cursor.execute(SQL1)
- SQL2="delete from command_queue where statu=2 and export_id=%d"%id
- cursor.execute(SQL2)
- self.conn.commit()
- cursor.close()
- '''
- def run(self):
- while self._close==False:
- cmds=self.search_pickcmd()
-
- for cmd in cmds:
- if len(cmd)>=9:
- table=message.pick_table()
- table.car_number=cmd[0]
- table.primary_key=cmd[1]
- table.unit=cmd[2]
- table.queue_id=cmd[3]
- table.type=cmd[4]
- table.statu=cmd[5]
- table.export_id=cmd[8]
- if not table.export_id==None:
- self._opendoor_callback(table.export_id,table)
- time.sleep(1)
- '''
|