Files
my_py_tools/t2sdk/pyCallBack.py
2025-10-18 21:32:31 +08:00

69 lines
2.2 KiB
Python

# coding=utf-8
from importlib import reload # Python 3 推荐方式
import traceback
import sys
reload(sys)
sys.path.append(r"F:\sescode_review\toolset\hstools\py-hstools\cest")
import py_t2sdk
def PrintUnpack(lpUnpack):
iDataSetCount = lpUnpack.GetDatasetCount()
index = 0
print('count '+str(iDataSetCount))
while index < iDataSetCount :
lpUnpack.SetCurrentDatasetByIndex(index)
iRowCount = lpUnpack.GetRowCount()
RowIndex = 0
while RowIndex < iRowCount:
iColCount = lpUnpack.GetColCount()
iColIndex = 0
while iColIndex < iColCount:
ColType = lpUnpack.GetColType(iColIndex)
if ColType == 'S':
print(lpUnpack.GetColName(iColIndex) + ':' + lpUnpack.GetStrByIndex(iColIndex))
elif ColType == 'I':
print(lpUnpack.GetColName(iColIndex) + ':' + str(lpUnpack.GetIntByIndex(iColIndex)))
elif ColType == 'C':
print(lpUnpack.GetColName(iColIndex) + ':' + lpUnpack.GetCharByIndex(iColIndex))
elif ((ColType == 'D') | (ColType == 'F')):
print(lpUnpack.GetColName(iColIndex) + ':' + str(lpUnpack.GetDoubleByIndex(iColIndex)))
iColIndex += 1
lpUnpack.Next()
RowIndex += 1
index += 1
class pyCallBack:
def __init__(self):
print('init')
def OnRegister(self):
print('OnRegister')
def OnClose(self):
print('OnClose')
def OnReceivedBiz(self):
print('OnReceivedBiz')
def OnReceivedBizEx(self):
print('OnReceivedBizEx')
def OnReceivedBizMsg(self,hSend,sBuff,iLenght):
try:
print('OnReceivedBizMsg')
lpBizMsg = py_t2sdk.pyIBizMessage()
iRet = lpBizMsg.SetBuff(sBuff,iLenght)
iRet = lpBizMsg.GetErrorNo()
print(iRet)
if iRet == 0:
buf,len = lpBizMsg.GetContent()
LoginUnPack = py_t2sdk.pyIF2UnPacker()
LoginUnPack.Open(buf,len)
PrintUnpack(LoginUnPack)
LoginUnPack.Release()
else:
print(iRet)
print(lpBizMsg.GetErrorInfo())
lpBizMsg.Release()
except:
traceback.print_exc()
finally:
print('pyCallBack finally')