| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- 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)
- self._lock = threading.Lock()
- 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 " #寻找已到出口的取车指令
- self._lock.acquire()
- cursor.execute(SQL)
- self._lock.release()
- pick_cmds=cursor.fetchall()
- cursor.close()
- self.conn.commit()
- return pick_cmds
- def delete_cmd(self,id):
- self.conn.begin()
- cursor=self.conn.cursor()
- SQL1="select * from command_queue for update"
- self._lock.acquire()
- cursor.execute(SQL1)
- self._lock.release()
- SQL2="delete from command_queue where statu=2 and export_id=%d"%id
- self._lock.acquire()
- cursor.execute(SQL2)
- self._lock.release()
- cursor.close()
- self.conn.commit()
- '''
- 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)
- '''
|