https://blog.csdn.net/inch2006/article/details/79930414
https://www.cnblogs.com/gaowengang/p/7919219.html
https://blog.csdn.net/inch2006/article/details/79908384?utm_source=blogxgwz6
https://blog.csdn.net/Stay_Alive_L/article/details/82857346
参考以上这些文章。
接下来先说说注意的东西,最后上代码。
- 因为用到python32开发,所以用anconda来装32位pyhton3.x,以免弄乱自己的环境
查看conda当前工作平台(可以看是否32位还是64位) conda info 如果需要更改位python32位那么执行 set CONDA_FORCE_32BIT=1 创建环境 conda create -n python32 python=3.6 查看已经安装的虚拟环境: conda info -e 删除环境 conda remove -n python32 --all 激活环境 activate python32
- 参考anaconda创建并激活python32,如果不能翻墙那么参考这个修改源,
- anaconda的python32环境里面安装环境:eg: pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas
- python是解释器,不要用conda install来安装东西,非常不稳定,在python32里面的pip来装,所以首先要激活后采用:
1.conda env list 2.activate python32 3.pip list
- 而且要用python -m pip install 来安装东西,不要用pip install 因为pip对应的python版本不知道(当然不出问题还是直接pip install方便)
- long long *是指针,32位,两个指针就是64位,可以直接一个longlong 直接64位来取代(long long *,long long *)前提是这两个longlong指针参数在开发文档说了没有用
- 记得用dir来看dll.某函数,可以看到里面有上面功能,eg:argtypes和restype是定义传入传出的(argtypes是要求数组的形式)
- 直接看dll工作库的头文件 = 直接看开发文档里面的函数参数
Python3的字符串的编码语言用的是unicode编码,由于Python的字符串类型是str,在内存中以Unicode表示,一个字符对应若干字节,如果要在网络上传输,或保存在磁盘上就需要把str变成以字节为单位的bytes
字符对象(给人看)-->编码-->字节对象(给电脑看)-->解码-->字符对象(给人看)
python的str->encode(或者b'')->变Bytes---网络传输(返回的是bytes 类型的utf-8编码的数据)--->decode--> 变回python的Str
参见:https://blog.csdn.net/inch2006/article/details/79930414
附上一张ctype类型转换图(参考他):
全部源码:
from ctypes import *
import ctypes
# class SimpStruct(Structure):
# _fields_ = [("nNo", c_int),
# ("fVirus", c_float),
# ("szBuffer", c_wchar)]#“”中的命名可以自己指定
path = 'C:\\Users\\86198\\Desktop\\Y_SDK19.9.3\\Y_SDK\\C++demo\\Demo\\Demo\\Release\\YQNetCom.dll'
#----------以下四种加载DLL方式皆可—————————
# pDLL = WinDLL("./myTest.dll")
pDll = windll.LoadLibrary(path) # 开发文档的_CALL_STD告诉我,要用windll才能加载dll
# pDll = cdll.LoadLibrary("./myTest.dll")
# pDll = CDLL(path) #加载工作库
# pDll.create_pic.restype = ctypes.c_ulong
# print(dir(pDll.check_time))
# pDll.add_pic_unit.restype = ctypes.c_ulong
pDll.check_time.argtypes = [ctypes.c_char_p,ctypes.c_int32,ctypes.c_wchar_p,ctypes.c_wchar_p]
print(pDll.check_time.argtypes)
print(dir(pDll.check_time))
pDll.check_time.restype = ctypes.c_int32
print(pDll.check_time.restype)
pDll.init_sdk.restype = ctypes.c_int32
pDll.create_playlist.argtypes = [ctypes.c_int32, ctypes.c_int32, ctypes.c_int32]
pDll.create_playlist.restype = ctypes.c_ulong
pDll.create_program.argtypes = [ctypes.c_wchar_p, ctypes.c_wchar_p]
pDll.create_program.restype = ctypes.c_ulong
pDll.create_pic.restype = ctypes.c_ulong
pDll.add_pic_unit.argtypes = [ctypes.c_ulong, ctypes.c_int32, ctypes.c_int32, ctypes.c_int32, c_wchar_p]
pDll.add_pic_unit.restype = ctypes.c_int32
pDll.add_pic.argtypes = [ctypes.c_ulong, ctypes.c_ulong, ctypes.c_int32, ctypes.c_int32, ctypes.c_int32, ctypes.c_int32, ctypes.c_int32]
pDll.add_pic.restype = ctypes.c_int32
pDll.add_program_in_playlist.argtypes = [ctypes.c_ulong, ctypes.c_ulong, ctypes.c_int32, ctypes.c_int32, ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_wchar_p, c_int32]
pDll.add_program_in_playlist.restype = ctypes.c_int32
pDll.send_program.argtypes = [ctypes.c_char_p, ctypes.c_ushort, ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_ulong, ctypes.c_int32,c_longlong]
pDll.send_program.restype = ctypes.c_int32
pDll.delete_playlist.argtypes = [ctypes.c_ulong]
pDll.delete_playlist.restype = ctypes.c_int32
pDll.release_sdk.restype = ctypes.c_int32
'''
视频分区
'''
pDll.create_pic.restype = ctypes.c_ulong
pDll.add_video_unit.argtypes = [ctypes.c_ulong, ctypes.c_int32, ctypes.c_int32, ctypes.c_int32, ctypes.c_int32, ctypes.c_wchar_p]
pDll.add_video_unit.restype = ctypes.c_int32
pDll.add_video.argtypes = [ctypes.c_ulong, ctypes.c_ulong, ctypes.c_int32, ctypes.c_int32 ,ctypes.c_int32, ctypes.c_int32 ,ctypes.c_int32 ,ctypes.c_int32, ctypes.c_int32, ctypes.c_wchar_p]
pDll.add_video.restype = ctypes.c_int32
# 节目调⽤
put = pDll.init_sdk()
# # 初始化动态库
playlist = pDll.create_playlist(576,320,10072) # 创建节⽬清单
program = pDll.create_program('program_0','0x00000000') # 创建节⽬(节目名,透明度和RGB) ,FF代表不透明,00代表全透明
# pic = pDll.create_pic() # 创建图⽂分区
#
# print(ctypes.c_ulong(pic))
# re = pDll.add_pic_unit(pic,1,2,1,'E:\\project\\pycharm_project\\Guangben\\GUI_1(new_interface)\\LED_model\\0.jpg') # 图⽂分区添加显示图片(记得特技一栏2代表YQ软件里面得特效:静止显示)
# re1 = pDll.add_pic(program,pic,0,0,576,320,50)
# re2 = pDll.check_time(b'192.168.12.2',80,'guest','guest')
# print("re2:",re2)
pic = pDll.create_video()
re = pDll.add_video_unit(pic,80,1,0,60,'E:\\project\\pycharm_project\\Guangben\\GUI_1(new_interface)\\LED_model\\test_video.mp4') # 图⽂分区添加显示图片
re1 = pDll.add_video(program,pic,0,0,576,320,0,0,0,'')
# 视频
put5 = pDll.add_program_in_playlist(playlist,program,1,1,'2020-07-08','2020-09-10','08:30:00','18:30:00',1111111) # 节⽬添加到节⽬单
put6 = pDll.send_program(b'192.168.12.2',80,'guest','guest','C:\\Users\\86198\\Desktop\\led_video_tmp',playlist,0,0) # 发送节⽬单
put7 = pDll.delete_playlist(playlist) # 销毁节⽬单
put8 = pDll.release_sdk() # 释放动态库函数
print(put)
print(playlist)
print(program)
print(pic)
# print(re)
# print(re1)
# print(put5)
# print(put6)
# print(put7)
# print(put8)
记得,如果传入的类型是空但是传进去之后说你少了4byte,或者8byte,试着将其填充,换一个长度一样的类型,因为只要占满它即可,反正这个数据也没用。
后面的东西有空再加上并修改文章吧,第一次做软件开发,真的见识了,还有很多自己是不懂的,继续努力吧。
补充:有时候莫名其妙,能ping通控制卡,但是发送出去没反应。check_time返回始终是-1。此时检查地址有没有问题,然后用YQ软件试一下,还是不行,就去电脑直连接收卡,用ledshowtv,发现可以,那有可能是控制卡到接收卡这里有问题,此时换控制卡,直接淘宝买,不要去定制买,又贵又慢。也有可能是控制卡IP有问题,有冲突,解决流程如下:
去官网下载最新的YQ播放器软件->自己电脑选择自动IP,不要设置手动IP,否则控制卡IP改不了->YQ软件设置屏参(密码888)->寻机->寻机ok后->设置屏参->控制器IP修改为我们想要的IP->然后测试发张图片没问题就ok了。