Python在Windows下操作CH341DLL

來源:互聯網
上載者:User

標籤: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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.