1 Star 0 Fork 0

cking616/OpteeQ_tool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
IOpteeQ.py 3.15 KB
一键复制 编辑 原始数据 按行查看 历史
Cking616 提交于 2021-01-05 10:43 . 初版提交
from ctypes import*
import time
import warnings
from copy import deepcopy
from math import isinf, isnan
class OpteeQDevName(Structure):
_fields_ = [("Name", c_ubyte * 40)]
class OpteeQDevPath(Structure):
_fields_ = [("Name", c_ubyte * 256)]
class OpteeQDevlist(Structure):
_fields_ = [("Dev", OpteeQDevPath * 8)]
class OpteeQChStatus(Structure):
_fields_ = [("ch_status", c_ulong * 8)]
class OpteeQDevice:
def __init__(self, lib_name_):
self.running = False
self.is_link = False
self.has_err = False
self._opteeq_lib = windll.LoadLibrary(lib_name_)
if self._opteeq_lib == 0:
self.has_err = True
self.is_no_lib = True
self.is_no_dev = True
return
else:
self.is_no_lib = False
_ret = self._opteeq_lib.OpteeQ_AddNetDevice( "192.168.0.100", 8000)
_dev_list = OpteeQDevlist()
_dev_cout = self._opteeq_lib.OpteeQ_GetDeviceList(pointer(_dev_list))
if _dev_cout == 0:
self.is_no_dev = True
self.has_err = True
return
else:
self.dev_path = _dev_list.Dev[0]
self.is_no_dev = False
def connect(self):
if self.is_no_dev:
return False
_ret = self._opteeq_lib.OpteeQ_Connect(pointer(self.dev_path))
if _ret:
devName = OpteeQDevName()
self._opteeq_lib.OpteeQ_GetDeviceName(pointer(self.dev_path), pointer(devName))
self.dev_name = devName
self.is_link = True
return True
else:
return False
def run_programmer(self, proj_name, time_out):
if self.running:
return False,None
if not self.is_link:
return False,None
_proj_name = proj_name.encode('utf-8')
_ret = self._opteeq_lib.OpteeQ_Run(pointer(self.dev_path), pointer(_proj_name) , 200, 0xFF, 0, 0)
if _ret:
self.running = True
ch_status = OpteeQChStatus()
while True:
_ret = self._opteeq_lib.OpteeQ_Ask(pointer(self.dev_path), pointer(ch_status))
if _ret:
_status = []
for _s in ch_status:
_status.append(_s)
return True,_status
else:
_err_code = self._opteeq_lib.OpteeQ_GetError(pointer(self.dev_path), 0)
if _err_code > 0x100:
return False,_err_code
else:
return False,None
def disconnect(self):
if not self.is_link:
return True
self._opteeq_lib.OpteeQ_Disconnect(pointer(self.dev_path))
def has_error(self):
return self.has_err
if __name__ == "__main__":
import time
opteeq_device = OpteeQDevice("./OpteeQ_Dll.dll")
if opteeq_device.has_error():
print("没有连接OpteeQ设备")
input("输入任意值结束")
quit(1)
if not opteeq_device.connect():
print("连接失败")
input("输入任意值结束")
quit(1)
opteeq_device.disconnect()
input("输入任意值结束")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cking616/optee-q_tool.git
git@gitee.com:cking616/optee-q_tool.git
cking616
optee-q_tool
OpteeQ_tool
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385