[英]Python ctypes callback function not getting any data
我正在使用Python開發C ++ SDK。 其中一個API看起來像這樣。 我指的是一篇SO帖子 。
我的目標是注冊一個回調函數並通過回調函數接收警報消息,但我沒有得到任何數據。 我懷疑我處理回調函數的方式是錯誤的。
我可以從這個setDVRMsgCallback
獲得一個True
,這意味着調用API是成功的,但是我沒有從msgCallback
獲得任何值
碼
class NET_DVR_ALARMER(Structure):
_fields_ = [
("byUserIDValid", c_byte),
("bySerialValid", c_byte),
("byVersionValid", c_byte),
("byDeviceNameValid", c_byte)
]
def msgCallback(lCommand, pAlarmer, pAlarmInfo, dwBufLen, pUser):
print("callback")
print(lCommand)
print(pAlarmer)
print(pAlarmInfo)
return True
def setDVRMsgCallback(sdk, callback):
sdk.NET_DVR_SetDVRMessageCallBack_V31.restype = c_bool
result = sdk.NET_DVR_SetDVRMessageCallBack_V31(callback, None)
print(result)
callback_t = CFUNCTYPE(c_bool, c_long, POINTER(NET_DVR_ALARMER), c_void_p, c_ulong, c_void_p)
callback = callback_t(msgCallback)
setDVRMsgCallback(sdk, callback)
API
BOOL NET_DVR_SetDVRMessageCallBack_V31(
MSGCallBack_V31 fMessageCallBack,
void *pUser
);
參數
fMessageCallBack
[in] Callback function
pUser
[in] User data
回調函數參數
lCommand
[out]Uploaded message type, and the types vary with alarm information. You can distinguish the alarm information according to the types,see details in the "Remarks" table.
pAlarmer
[out] Alarm device information, including device series No., IP address, user login ID handle.
pAlarmInfo
[out] Alarm information, judge the pAlarm structure via the lCommand value, see details in the "Remark" table.
dwBufLen
[out] Alarm information buffer size
pUser
[out] User data
您可以在此處下載其SDK
我已經參考了上面附帶的SDK文檔。 在通過NET_DVR_SetDVRMessageCallBack_V31
注冊回調函數后,您似乎需要調用NET_DVR_SetupAlarmChan_V41
API。
你的代碼對我來說似乎很好。
由於API的異步特性,您需要確保您的程序始終處於偵聽/等待模式,以便從回調函數中獲取結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.