LTC2943_1.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:RaspberryPiBarcodeScanner 作者: briandorey 项目源码 文件源码
def get_smbus(self):
        # detect i2C port number and assign to i2c_bus
        i2c_bus = 0
        for line in open('/proc/cpuinfo').readlines():
            m = re.match('(.*?)\s*:\s*(.*)', line)
            if m:
                (name, value) = (m.group(1), m.group(2))
                if name == "Revision":
                    if value[-4:] in ('0002', '0003'):
                        i2c_bus = 0
                    else:
                        i2c_bus = 1
                    break
        try:        
            return smbus.SMBus(i2c_bus)
        except IOError:
                print ("Could not open the i2c bus.")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号