Python ctypes回调函数没有得到任何

2024-03-29 14:47:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Python来处理C++ SDK。其中一个api如下所示。我指的是SO post。你知道吗

我的目标是注册一个回调函数,并通过回调函数接收报警消息,但我没有得到任何数据。我怀疑我处理回调函数的方法是错误的。你知道吗

我能够从这个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 here


Tags: the函数innetinformationcallbacksdkbyte
1条回答
网友
1楼 · 发布于 2024-03-29 14:47:21

我已经参考了上面附带的SDK文档。在通过NET_DVR_SetDVRMessageCallBack_V31注册回调函数之后,似乎需要调用NET_DVR_SetupAlarmChan_V41API。你知道吗

我觉得你的密码不错。你知道吗

由于API的异步特性,您需要确保程序始终处于侦听/等待模式,以便从回调函数获得结果。你知道吗

相关问题 更多 >