test_connect.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from uhf.reader import *
  2. from time import *
  3. def receivedEpc(epcInfo: LogBaseEpcInfo):
  4. if epcInfo.result == 0:
  5. pass
  6. def receivedEpcOver(epcOver: LogBaseEpcOver):
  7. print("LogBaseEpcOver")
  8. def print_gclient_attrs(g_client):
  9. print("GClient 属性:")
  10. for attr in dir(g_client):
  11. if not attr.startswith('__') or attr in ['__ci', '__msgDic', '__serialNumber', '__callEpcInfo', '__callEpcOver',
  12. '__call6bInfo', '__call6bOver', '__callGbInfo', '__callGbOver',
  13. '__callGJbInfo', '__callGJbOver', '__callTcpDisconnect',
  14. '__callGpiStart', '__callGpiOver', '__callCacheDataOver', '__allGpiState']:
  15. try:
  16. value = getattr(g_client, attr)
  17. print(f"{attr}: {value}")
  18. except AttributeError:
  19. pass
  20. if __name__ == '__main__':
  21. g_client = GClient()
  22. # if g_client.openSerial(("COM7", 115200)):
  23. if g_client.openTcp(("10.41.191.107", 8160)):
  24. # 订阅标签回调
  25. g_client.callEpcInfo = receivedEpc
  26. g_client.callEpcOver = receivedEpcOver
  27. print_gclient_attrs(g_client=g_client)
  28. # 读epc
  29. msg = MsgBaseInventoryEpc(antennaEnable=EnumG.AntennaNo_1.value,
  30. inventoryMode=EnumG.InventoryMode_Inventory.value)
  31. if g_client.sendSynMsg(msg) == 0:
  32. # print(f'**********{msg.rtMsg}')
  33. pass
  34. # # 5s后执行停止盘点以及关闭连接
  35. # sleep(5)
  36. # stop = MsgBaseStop()
  37. # if g_client.sendSynMsg(stop) == 0:
  38. # print(stop.rtMsg)
  39. # g_client.close()