代码拉取完成,页面将自动刷新
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("输入任意值结束")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。