# ct **Repository Path**: he-binhua/ct ## Basic Information - **Project Name**: ct - **Description**: 哈哈哈哈哈哈哈哈哈哈哈哈哈哈 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-02-17 - **Last Updated**: 2025-01-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Hantek6022API (Version 0.0.2) ![Reference Oscillator Trace](https://raw.githubusercontent.com/rpcope1/Hantek6022API/master/HT6022BEBuiltInOscillator.png) Hantek 6022BE Python API for Windows and Linux. This is a API for Python via ctypes for Hantek's SDK for the ultra-cheap, reasonably usable (and hackable) 6022BE DSO, with a libusb implementation via libusb1 for Linux. I was tired of using the silly Chinese software that came with this DSO, so I decided to write an API so I could run the scope through Python. The scope can be accessed by instantiating an oscilloscope object with the correct scopeid (always 0 for one scope attached). Things like voltage divisions and sampling rates can be set by the appropriate methods. As I finish developing this, I will include documentation. Each method has some documentation as to what it does currently though, and hopefully variable names are clear enough to give you some idea what they are for. (Also, the provided DLLs that access the scope belong to Hantek, not me. They are provided simply for ease of access and are probably NOT covered by the GPL!) ## Neat things you can do While this scope isn't quite as poweful as your many-thousand dollar Tektronix or even your run of the mill Rigol 1102E, with a little bit of programming, it's capable of doing interesting things. User -johoe on reddit was able to use [this library and scope to launch a successful side-channel attack on his TREZOR bitcoin device, and extract the device's private keys](http://www.reddit.com/r/TREZOR/comments/31z7hc/extracting_the_private_key_from_a_trezor_with_a/#) ; yes side-channel attacks aren't just for NSA spooks and crusty academics anymore, even you can do it in your home with this inexpensive USB scope. :) If you have you have your own examples or have seen this library used, please let me know so I can add the examples here. ## Now with Linux support If you're on Linux, you're also in luck, as I've provided some reverse engineered binding for libusb to operate this little device. You may wish to first add 60-hantek-6022-usb.rules to your udev rules, via # sudo cp 60-hantek-6022-usb.rules /lib/udev/rules.d/ sudo cp 60-openhantek.rules /etc/udev/rules.d/ After you've done this, the scope should automatically come up with the correct permissions to be accessed without a root user. You need to compile the custom firmware. Install `sdcc` for this. Then run `make` in the directory `HantekFirmware/custom`: git submodule update --init sudo apt-get install sdcc cd PyHT6022/HantekFirmware/custom make With the device plugged in, run the example_linux_flashfirmware.py example, python examples/example_linux_flashfirmware.py to bootstrap the scope for use. You can then write your own programs, or look at the current channel 1 scope trace via python examples/example_linux_scopevis.py ## TODO 1. Clean up library, apply good formatting. 2. Clean up unit tests. 3. Add more examples. One excellent ultimate goal for this would to make it play nice with cheap ARM SBCs like the Raspberry Pi, such that this could be used as a quick and dirty DAQ for many interesting systems. For additional (interesting) details, the inquisitive reader should read: http://www.eevblog.com/forum/testgear/hantek-6022be-20mhz-usb-dso/ UPDATE: If you're interested in contributing and updating this repo, I'd be glad to have help maintaining it. I do accept pull requests. ## 安装python依赖 pip install -r requirements.txt ## 使用QT修改文件后重新生成对应的py文件 可以使用pycharm的External Tools工具帮助开发 配置完成后右击文件选择对应的工具即可 ### 用QtDesigner打开ui文件 ![img.png](file/image/imgDesigner.png) ### 将ui文件转换为python文件 pyuic5 -o ui_$FileNameWithoutExtension$.py $FileName$ ![img.png](file/image/imgUIC.png) ### 将qrc文件转换为python文件 pyrcc5 $FileName$ -o $FileNameWithoutExtension$_rc.py ![img_1.png](file/image/imgRcc.png) ### 直接用xml方式编辑ui文件 setting->Editor->File Types->Xml 添加*.ui ![img.png](file/image/imgFileTypes.png) ## 利用QtDesigner ### 布局组件 GridLayout、QBoxLayout(Vertical、Horizontal) layout**Margin 控制layout内边距(为什么不叫padding?) layoutStretch 控制组件占比的权重 布局中需要将组件分布在两端自适应时(比如一个靠左一个靠右)可以额外添加空组件实现(不知道有没有更好的办法) 将空组件占比设为1,其他设为0。按钮会占用整个空间,而label看不出多余的空间 ### QSS css的衍生,首先需要了解[qss选择器](https://blog.csdn.net/u012870892/article/details/81612407) 1. 尽量选择作用范围小的选择器,关键组件尽量用id选择器 2. 用Stretch控制权重会导致width、height属性失效,可以考虑min-height、max-height等 3. 分割线可以使用border-top或border-bottom属性实现。QLabel组件只有border-top和border属性有效(不知道为什么) ## 代码规范 - 遵循统一的命名规则,驼峰命名、变量名望文知义 - 尽可能减少编译器的警告和报错,命名问题、代码重复、多余的操作、代码有明显的优化空间 - python类成员作用域:注意静态变量、私有变量、静态方法、类方法的使用 根据迪米特法则(最少知道原则),尽可能限制变量的作用域(能用私有变量尽量不要写成公有) ### 代码复用 - Qt:能复用的组件封装起来,放到components目录下 - **python装饰器**(代理模式):类似于java中的aop注解 原理:利用python动态语言的优势,把要调用的函数或类进行替换 ```python from time import time # 实现一个函数计时功能 def timer(func): # timer函数对func函数进行包装,使得我们调用func函数时实际上调用的是内部的_wrapper函数 def _wrapper(*args, **kwargs): beg = time() res = func(*args, **kwargs) print('用时:{}秒'.format(time() - beg)) return res return _wrapper @timer def rangeSum(n): s = 0 for i in range(n): s += i return s print(rangeSum(10_000_000)) ``` 装饰器本质上是一个函数,这里调用rangeSum(10_000_000)相当于调用timer(rangeSum)(10_000_000) 项目中的utils目录用来放一些经常使用的函数,如uitls.Singleton.Singleton和uitls.DBHelper.Transactional