標籤:type tst rom [1] lib turn sel closed color
1 #! /usr/bin/env python 2 #coding=utf-8 3 import os 4 import time 5 from ctypes import * 6 7 class CH341(): 8 def __init__(self, dev = 0xb8): 9 self.dev_addr = dev10 11 def read(self, addr):12 ch341 = windll.LoadLibrary("CH341DLL.dll")13 ch341.CH341OpenDevice(0)14 ch341.CH341SetStream(0, 0x82)15 obuf = (c_byte * 2)()16 ibuf = (c_byte * 1)()17 obuf[0] = self.dev_addr18 obuf[1] = addr19 ch341.CH341StreamI2C(0, 2, obuf, 1, ibuf)20 ch341.CH341CloseDevice(0)21 return ibuf[0] & 0xff22 23 def write(self, addr, dat):24 ch341 = windll.LoadLibrary("CH341DLL.dll")25 ch341.CH341OpenDevice(0)26 ch341.CH341SetStream(0, 0x82)27 obuf = (c_byte * 3)()28 ibuf = (c_byte * 1)()29 obuf[0] = self.dev_addr30 obuf[1] = addr31 obuf[2] = dat & 0xff32 ch341.CH341StreamI2C(0, 3, obuf, 0, ibuf)33 ch341.CH341CloseDevice(0)
Python在Windows下操作CH341DLL