基本信息
源码名称:python3 大华IP摄像头使用 SDK DLL 添加动态文字叠加
源码大小:3.80M
文件格式:.rar
开发语言:Python
更新时间:2019-04-03
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍


#! usr/bin/python
#coding=utf-8
from ctypes.wintypes import DWORD
from ctypes import  *
import time
import ctypes 
import ctypes.util
import json
Objdll = WinDLL("d:/python/dhnetsdk.dll")
 
def  DisConnectFunc(  lLoginID, a,  nDVRPort, dwUser):

	printf("Device disconn, IP=%s                       \n");
class msginf(Structure):
    _fields_ = [
                ('bEnable', c_bool),
                ('dwPosition', DWORD * 6),
                ('szStrings', c_char_p *6  )
		]
def ctypes_alloc_aligned(size, alignment):  
    buf_size = size   (alignment - 1)  
    #?bytearray??  
    raw_memory = bytearray(buf_size)  
    #?raw_memory?ctypes  
    ctypes_raw_type = (ctypes.c_char * buf_size)  
    ctypes_raw_memory = ctypes_raw_type.from_buffer(raw_memory)  
    #?ctypesaddressof???  
    raw_address = ctypes.addressof(ctypes_raw_memory)  
    offset = raw_address % alignment  
    #????ó??  
    offset_to_aligned = (alignment - offset) % alignment  
    ctypes_aligned_type = (ctypes.c_char * (buf_size - offset_to_aligned))  
    #????ctype  
    ctypes_aligned_memory = ctypes_aligned_type.from_buffer(raw_memory, offset_to_aligned)  
    return ctypes_aligned_memory

libc = ctypes.CDLL(ctypes.util.find_library('c'))  
#?4k?  	
CMPFUNC = CFUNCTYPE(c_int64, POINTER(c_char),c_int64, DWORD)
CMPFUNC = CFUNCTYPE(c_int64, POINTER(c_char),c_int64, DWORD)
_callback = CMPFUNC( DisConnectFunc)
Objdll.CLIENT_Init(_callback, 0);  #如果没有这句就不能登录. 这个函数,是凑合注册和定义的..参数是按照文档要求的
Objdll.CLIENT_SetAutoReconnect(_callback, 0);

#// 豸????
#CLIENT_NET_API void CALL_METHOD CLIENT_SetConnectTime(int nWaitTime, int nTryTimes);
Objdll.CLIENT_SetConnectTime(3000,3)

 
i=c_int(13)
ipcamID=c_long()
ipcamID= Objdll.CLIENT_Login(b"10.71.12.62",37777,b"admin",b"admin",0, byref(i))
print ("出错代码",i)
print( 'handle',ipcamID)
#i成功返回0,否则是错误码,比如密码错1 文档中有说明,, 成功返回一个大数,是handle. ,失败则是0

 
#这个buf的内存函数很关键,有了它才有了后面的一切。对于python ,调用来说。需要传递一个合适的引用。可读可写。注释被我切换代码时干掉了。
buf=ctypes_alloc_aligned(32*1024,4096)
CMD_STR=b"VideoWidget" # b"ChannelTitle"  #
re =Objdll.CLIENT_GetNewDevConfig(ipcamID,CMD_STR,0,byref(buf),32*1024,byref(i),5000)
 
print ("取参数:",re,i)
ff=open("d:/python/json12.py","w ")
ss=buf.value.strip().decode()


if re and ss:

        oo=json.loads(ss)
        print("\r\n返回长度:", len(ss))
        if len(ss)<200:
           print(ss,"\r\n\r\n",oo,"\r\n\r\n")
    
        ff.write(ss "\r\n")
        ff.close()
        print (oo["params"]["table"]['CustomTitle'] )
        Custom= oo["params"]["table"]['CustomTitle']
        Custom[0]["PreviewBlend"]=  True #   Custom[0]["EncodeBlend"] 
         
        Custom[0]["EncodeBlend"]=    True #  Custom[0]["PreviewBlend"]
        Custom[0]["Text"]= "eTrue"  #这里是占位符了。
        param=Custom [0]

     #   做为utf-8字符,json模块打包会改称 ‘\uec98\uef88’这样四个字节的样子。而dll接口要求中文是三字节。测试发现,发现这样可以。
     #json 可以指定参数。那时就简单了。目前这是显示中文的笨方法。
        param=json.dumps(param) .replace('eTrue','条目测试 ') .encode()

        param=(param   b',' )*5 param  #由于结尾如果多出一个‘’,‘’。摄像头不支持。所以,这样制作了6个相同的字符。做测试用。
        
        param =b'{"CustomTitle": ['   param   b'] }'  #它要在参数只有这一项。 所以改写其他参数可以参考这样实现。bytes类型的。
     #   print( param)
     #   update=json.dumps({"Name":oo["params"]  })
     #   update=json.dumps({"Name" :r'\xe6\x89\x93\xe5\xbc\x80' })
        
      #  update["table"]["CustomTitle"][0]["Text"]="654321"
        re =Objdll.CLIENT_SetNewDevConfig(ipcamID,CMD_STR,0,param, 32*1024,byref(i),i,5000)
        print ("设置参数",re,i)

print(Objdll.CLIENT_GetLastError())
Objdll.CLIENT_Logout(ipcamID)
Objdll.CLIENT_Cleanup()
a=str(input("-:"))