资源简介
1、ctypes 使用DLL中的函数,比如登陆函数
2、用ctypes构造一块对齐内存的buffer。然后传递给dll函数使用。
3、构造大华CONFIG API所需的JSON。
4、对json中的汉字和数据结构做相应调整。
5、详细的或扩展的使用,需要参考大华SDK文档。此包定义了6行文本,但是都处于同一位置。
6、因为用了json传递配置,某些摄像头是不支持的,可以参考此文档,使用其他DLL函数实现。但是json才是最好用的吧。
7、也在C ,VC中调试了。但是VC在文字叠加时压包居然报错。
8、我的用意在于,从动态资源接口生成字符串。比如收音机什么。目前有厂家提供字符叠加器,也是相似原理。
9、代码较乱,欢迎交流。

代码片段和文件信息
#! 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(30003)
i=c_int(13)
ipcamID=c_long()
ipcamID= Objdll.CLIENT_Login(b“10.71.12.62“37777b“admin“b“admin“0 byref(i))
print (“出错代码“i)
print( ‘handle‘ipcamID)
#i成功返回0,否则是错误码,比如密码错1 文档中有说明 成功返回一个大数,是handle. 失败则是0
#这个buf的内存函数很关键,有了它才有了后面的一切。对于python 调用来说。需要传递一个合适的引用。可读可写。注释被我切换代码时干掉了。
buf=ctypes_alloc_aligned(32*10244096)
CMD_STR=b“VideoWidget“ # b“Channeltitle“ #
re =Objdll.CLIENT_GetNewDevConfig(ipcamIDCMD_STR0byref(buf)32*1024byref(i)5000)
print (“取参数:“rei)
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‘‘条目测试 ‘) .e
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4282 2017-09-18 08:18 wjcipcamerasdk4.py
文件 8814676 2017-06-22 14:29 dhnetsdk.dll_win64
文件 8814676 2017-06-22 14:29 dhnetsdk.dll
----------- --------- ---------- ----- ----
17633634 3
相关资源
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论