資源簡介
1、ctypes 使用DLL中的函數(shù),比如登陸函數(shù)
2、用ctypes構(gòu)造一塊對齊內(nèi)存的buffer。然后傳遞給dll函數(shù)使用。
3、構(gòu)造大華CONFIG API所需的JSON。
4、對json中的漢字和數(shù)據(jù)結(jié)構(gòu)做相應(yīng)調(diào)整。
5、詳細(xì)的或擴(kuò)展的使用,需要參考大華SDK文檔。此包定義了6行文本,但是都處于同一位置。
6、因?yàn)橛昧薺son傳遞配置,某些攝像頭是不支持的,可以參考此文檔,使用其他DLL函數(shù)實(shí)現(xiàn)。但是json才是最好用的吧。
7、也在C ,VC中調(diào)試了。但是VC在文字疊加時(shí)壓包居然報(bào)錯。
8、我的用意在于,從動態(tài)資源接口生成字符串。比如收音機(jī)什么。目前有廠家提供字符疊加器,也是相似原理。
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);??#如果沒有這句就不能登錄.?這個(gè)函數(shù)是湊合注冊和定義的..參數(shù)是按照文檔要求的
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?文檔中有說明?成功返回一個(gè)大數(shù),是handle.?失敗則是0
?
#這個(gè)buf的內(nèi)存函數(shù)很關(guān)鍵,有了它才有了后面的一切。對于python?調(diào)用來說。需要傳遞一個(gè)合適的引用??勺x可寫。注釋被我切換代碼時(shí)干掉了。
buf=ctypes_alloc_aligned(32*10244096)
CMD_STR=b“VideoWidget“?#?b“Channeltitle“??#
re?=Objdll.CLIENT_GetNewDevConfig(ipcamIDCMD_STR0byref(buf)32*1024byref(i)5000)
?
print?(“取參數(shù):“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’這樣四個(gè)字節(jié)的樣子。而dll接口要求中文是三字節(jié)。測試發(fā)現(xiàn),發(fā)現(xiàn)這樣可以。
?????#json?可以指定參數(shù)。那時(shí)就簡單了。目前這是顯示中文的笨方法。
????????param=json.dumps(param)?.replace(‘eTrue‘‘條目測試?‘)?.e
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????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
評論
共有 條評論