0

The following section is the manual provided by them.

Definition

NeptuneCamHandle ntcOpen(_char_t* pstrDevID, NeptuneCamHandle* phCamHandle,ENeptuneDevAccess eAccessFlag=NEPTUNE_DEV_ACCESS_EXCLUSIVE)

Parameters

  • [IN] pstrDevID : ID string of a camera
  • [OUT] phCamHandle : camera handle
  • [IN, Optional] AccessFlag : control mode

Example

_uint32_t nCameras = ntcGetCameraCount();
if ( nCameras > 0 )
{
 pCamInfo = new NEPTUNE_CAM_INFO[nCameras];
 ntcGetCameraInfo(pCamInfo, nCameras);
}
NeptuneCamHandle hCamHandle;
// if unicast
ntcOpen(pCamInfo[0].strCamID, &hCamHandle);
// if multicast
ntcOpen(pCamInfo[0].strCamID, &hCamHandle, NEPTUNE_DEV_ACCESS_CONTROL);

This is how I use it in my code:

class _NEPTUNE_CAM_INFO_(Structure):
    pass


_NEPTUNE_CAM_INFO_._fields_ = [
    ('strVendor', c_char * 512),
    ('strModel', c_char * 512),
    ('strSerial', c_char * 512),
    ('strUserID', c_char * 512),
    ('strIP', c_char * 512),
    ('strMAC', c_char * 32),
    ('strSubnet', c_char * 512),
    ('strGateway', c_char * 512),
    ('strCamID', c_char * 512),
]
NEPTUNE_CAM_INFO = _NEPTUNE_CAM_INFO_


class IMICamera:

    def __init__(self):
        self._handle = c_void_p()  # 记录当前连接设备的句柄
        self.handle = pointer(self._handle)  # 创建句柄指针
        self.IMI_ntcInit()

    def IMI_ntcInit(self):
        IMICamCtrldll.ntcGetCameraCount.restype = c_int
        return IMICamCtrldll.ntcInit()
        # return MvCamCtrldll.ntcInit()

    def IMI_ntcGetCameraCount(self, count):
        IMICamCtrldll.ntcGetCameraCount.argtype = (c_void_p,)
        IMICamCtrldll.ntcGetCameraCount.restype = c_int
        return IMICamCtrldll.ntcGetCameraCount(byref(count))

    def IMI_ntcGetCameraInfo(self, pInfo, count):
        IMICamCtrldll.ntcGetCameraInfo.argtype = (c_void_p, c_void_p)
        IMICamCtrldll.ntcGetCameraInfo.restype = c_int
        return IMICamCtrldll.ntcGetCameraInfo(byref(pInfo), count)

    def IMI_ntcOpen(self, pstrDevID):
        IMICamCtrldll.ntcOpen.argtype = (c_char, c_void_p)
        IMICamCtrldll.ntcOpen.restype = c_int
        return IMICamCtrldll.ntcOpen(pstrDevID, byref(self.handle))
if __name__ == '__main__':
    mv = IMICamera()
    count = c_uint()
    res = mv.IMI_ntcGetCameraCount(count)
    if res != 0:
        print('IMI_ntcGetCameraCount', res)
    pInfo = (NEPTUNE_CAM_INFO * count.value)()
    res = mv.IMI_ntcGetCameraInfo(pInfo, count)
    if res != 0:
        print('IMI_ntcGetCameraInfo', res)
    strCamID = pInfo[1].strCamID
    pid = (c_char * 512)()
    for i in range(len(strCamID)):
        pid[i] = strCamID[i]

    pid2 = ctypes.create_string_buffer(512)
    pid2.value = strCamID

    pid3 = c_char_p(b'00:09:7e:02:80:88')
    res = mv.IMI_ntcOpen(pid3)

I try many type parameters,as you can see in my code. After I run my code, the result is always get error_code -203,it means NEPTUNE_ERR_InvalidParameter.

How can i fix this? What have I done wrong? Thanks!

huang lin
  • 1
  • 1
  • In your example `ntcGetCameraCount` doesn't seem to take any argument, you defined it with one in python. The second parameter to `ntcGetCameraInfo` should be a `ctypes.c_uint32` according to your example. `ntcOpen`takes 3 arguments but you defined it only with 2. Check what is the underlying type of `ENeptuneDevAccess` and add it to your python function prototype. – Neitsa Dec 18 '19 at 08:24
  • Does this answer your question? [C function called from Python via ctypes returns incorrect value](https://stackoverflow.com/questions/58610333/c-function-called-from-python-via-ctypes-returns-incorrect-value). It's a *argtype**s***. – CristiFati Dec 18 '19 at 10:33

0 Answers0