Python在Windows下操作CH341DLL
#! /usr/bin/env python
#coding=utf-8
import os
import time
from ctypes import * class USBI2C():
ch341 = windll.LoadLibrary("CH341DLL.dll")
def __init__(self, usb_dev = 0, i2c_dev = 0x5c):
self.usb_id = usb_dev
self.dev_addr = i2c_dev
if USBI2C.ch341.CH341OpenDevice(self.usb_id) != -1:
USBI2C.ch341.CH341SetStream(self.usb_id, 0x82)
USBI2C.ch341.CH341CloseDevice(self.usb_id)
else:
print("USB CH341 Open Failed!") def read(self, addr):
if USBI2C.ch341.CH341OpenDevice(self.usb_id) != -1:
obuf = (c_byte * 2)()
ibuf = (c_byte * 1)()
obuf[0] = self.dev_addr
obuf[1] = addr
USBI2C.ch341.CH341StreamI2C(self.usb_id, 2, obuf, 1, ibuf)
USBI2C.ch341.CH341CloseDevice(self.usb_id)
return ibuf[0] & 0xff
else:
print("USB CH341 Open Failed!")
return 0 def write(self, addr, dat):
if USBI2C.ch341.CH341OpenDevice(self.usb_id) != -1:
obuf = (c_byte * 3)()
ibuf = (c_byte * 1)()
obuf[0] = self.dev_addr
obuf[1] = addr
obuf[2] = dat & 0xff
USBI2C.ch341.CH341StreamI2C(self.usb_id, 3, obuf, 0, ibuf)
USBI2C.ch341.CH341CloseDevice(self.usb_id)
else:
print("USB CH341 Open Failed!")
Python在Windows下操作CH341DLL的更多相关文章
- Python调用windows下DLL详解
Python调用windows下DLL详解 - ctypes库的使用 2014年09月05日 16:05:44 阅读数:6942 在python中某些时候需要C做效率上的补充,在实际应用中,需要做部分 ...
- python 在windows下的 虚拟环境
解决 python 环境问题 windows 下安装 pip install virtualenv virtualenv的基本使用 1.1 创建虚拟环境 virtualenv venv 为环境指定Py ...
- python 在windows下监听键盘按键
python 在windows下监听键盘按键 使用到的库 ctypes(通过ctypes来调用Win32API, 主要就是调用钩子函数) 使用的Win32API SetWindowsHookEx(), ...
- Python在windows下的安装与配置
安装python 文件准备: A. python安装文件:我用的是python-3.4.3.amd64.msi: 安装很简单,直接双击点下一步即可: 配置环境变量,在windows系统变量中找到pat ...
- Python 在Windows下安装matplotlib
windows下安装很麻烦,使用easy_install 安装报错 提示缺少freetype 和png 后经多方查询,最终安装成功 以下是安装过程 前提你的Python环境已经搭建好了 1.前提需要 ...
- windows下操作linux虚拟机映射网络驱动器中文件提示chmod权限不足解决方案
为了方便操作,linux虚拟机会通过windows下连接网络驱动器的方式共享自己的文件,对于前端来说,我想把gulp放在windows磁盘,操作虚拟机中的php文件,一来节省虚拟机磁盘大小,二来解决虚 ...
- Python监控Windows下的文件变化
windows下监控文件系统的变化.用python非常方便.实例代码例如以下,非常easy.也不多说了. import os import win32file import win32con ACTI ...
- 【python】 Windows下pip安装包报错:Microsoft Visual C++ 9.0 is required Unable to find vcvarsall.bat
刚在机器上windows环境下装上pip方便以后安装包的时候使用,谁知道第一次使用pip安装asyncio的时候就报错. 在Windows7x64下使用pip安装包的时候提示报错:Microsoft ...
- python在windows下连接mysql数据库
一,安装MySQL-python python 连接mysql数据库需要 Python interface to Mysql包,包名为 MySQL-python ,PyPI上现在到了1.2.5版本.M ...
随机推荐
- 接口调用 POST
/** * 接口调用 POST * @return [type] [description] */ public function portPhone(Request $request) { $pho ...
- thinkphp和ueditor自定义后台处理方法整合
先了解一下ueditor后台请求参数与返回参数格式规范: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 ...
- MVC 设计模式与三层架构
一.JavaEE开发模式 什么是开发模式 模式是在开发过程中总结出的"套路",总结出的一套约定俗成的设计模式 JavaEE模式 model1模式 技术组成 :jsp+javaBea ...
- Contest Reviews(Updating)
现在每天至少一套题又不太想写题解…… 那就开个坑总结下每场的失误和特定题目的技巧吧 2018.8.25[ZROI] T3传送门 T1:找规律找崩了…… 最好不要一上来就钻进大讨论,先想有没有普适规律 ...
- 汇编代码中db,dw,dd的区别
db定义字节类型变量,一个字节数据占1个字节单元,读完一个,偏移量加1 dw定义字类型变量,一个字数据占2个字节单元,读完一个,偏移量加2 dd定义双字类型变量,一个双字数据占4个字节单元,读完一个, ...
- Codeforces Round #361 (Div. 2) A. Mike and Cellphone 水题
A. Mike and Cellphone 题目连接: http://www.codeforces.com/contest/689/problem/A Description While swimmi ...
- Codeforces Round #196 (Div. 2) A. Puzzles 水题
A. Puzzles Time Limit: 2 Sec Memory Limit: 60 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showProblem ...
- Codeforces Round #295 (Div. 2)A - Pangram 水题
A. Pangram time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
- hdu 2251 Dungeon Master bfs
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17555 Accepted: 6835 D ...
- UVALive 4867 Maximum Square 贪心
E - Maximum Square Time Limit:4500MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...