当前位置: 首页>>代码示例>>Python>>正文


Python SMBus.write_quick方法代码示例

本文整理汇总了Python中smbus.SMBus.write_quick方法的典型用法代码示例。如果您正苦于以下问题:Python SMBus.write_quick方法的具体用法?Python SMBus.write_quick怎么用?Python SMBus.write_quick使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在smbus.SMBus的用法示例。


在下文中一共展示了SMBus.write_quick方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Scan

# 需要导入模块: from smbus import SMBus [as 别名]
# 或者: from smbus.SMBus import write_quick [as 别名]
class Scan(Base):
    def __init__(self):
        self.found = []

    def setup(self):
        self.bus = SMBus(1)
        return self

    def run(self):
        for i in range(1,127):
            # rez = self.bus.read_byte(i)
            try:
                rez = self.bus.write_quick(i)
                self.found.append(i)
                print "%s -> %s" % (i,rez) 
            except IOError:
                pass
    def command(self,line):
        if re.search('^rescan$', line):
            self.run()
            if len(self.found) > 0:
                self.commander.default_address = self.found[0]
            return True
        elif re.search('^list$', line):
            for a in self.found:
                print a
            return True

    def help(self):
        return "rescan # rescan for i2c"
开发者ID:awgrover,项目名称:LaureDrogoul_seesaw,代码行数:32,代码来源:i2c_test.py

示例2: __init__

# 需要导入模块: from smbus import SMBus [as 别名]
# 或者: from smbus.SMBus import write_quick [as 别名]
class WeatherStation:
  def __init__(self, dataFile='/dev/null'):
    self.dataFile = dataFile
    self.fetched = False

    # Initialise the BMP085 and use STANDARD mode (default value)
    # self.bmp = BMP085(0x77, debug=True)
    self.bmp = BMP085(0x77)
    
    # To specify a different operating mode, uncomment one of the following:
    # self.bmp = BMP085(0x77, 0)  # ULTRALOWPOWER Mode
    # self.bmp = BMP085(0x77, 1)  # STANDARD Mode
    # self.bmp = BMP085(0x77, 2)  # HIRES Mode
    # self.bmp = BMP085(0x77, 3)  # ULTRAHIRES Mode

    # Initilize HIH-6130.
    bus = GFDITools.guessBus()
    self.HIH6130 = SMBus(bus=bus)

    # Temporary storage array for HIH6130 data
    self.blockData = [0, 0, 0, 0]


  def fetchData(self):
    # Fetch temp & pressure data from BMP
    self.temp = self.bmp.readTemperature()
    self.pressure = self.bmp.readPressure() / 100.0
    # Altitude seems buggy, so we're skipping it for now.
    # altitude = self.bmp.readAltitude()

    # Tell HIH-6130 we want temperature and humidity data.
    self.HIH6130.write_quick(0x27)
    # Wait for it.
    time.sleep(0.050)
    # Read the data we requested.
    blockData = self.HIH6130.read_i2c_block_data(0x27, 0)
    # Process the data.
    self.status = (blockData[0] & 0xc0) >> 6
    self.humidity = (((blockData[0] & 0x3f) << 8) + blockData[1]) * 100.0 / 16383.0
    self.tempC = ((blockData[2] << 6) + ((blockData[3] & 0xfc) >> 2)) * 165.0 / 16383.0 - 40.0
    # tempF = tempC*9.0/5.0 + 32.0

    # Make a note that there is now data to be had.
    self.fetched = True


  def printData(self):
    # print data to screen
    # print "Data:       ", "%02x "*len(d)%tuple(d)
    # print "Status:     ", status
    if self.fetched:
      print "Humidity:   %.2f" % self.humidity, "%RH"
      print "Temperature:    %.2f C" % self.tempC
      print "Barometric Pressure:    %.2f hPa" % self.pressure
      print "Temperature:    %.2f C" % self.temp
    else:
      print "No data has been fetched."
      return -1


  def recordData(self):
    if self.fetched:
      if not os.path.exists(self.dataFile):
        with open(self.dataFile, 'w') as csvfile:
          datawriter = csv.writer(
            csvfile,
            quotechar=',',
            quoting=csv.QUOTE_MINIMAL
          )
          datawriter.writerow([
            'Date',
            'Temp(C)',
            'Pressure(hPa)',
            'Humidity(%RH)'
          ])

      with open(self.dataFile, 'a+') as csvfile:
        datawriter = csv.writer(csvfile, quotechar=',', quoting=csv.QUOTE_MINIMAL)
        datawriter.writerow([datetime.datetime.now(), self.tempC, self.pressure, self.humidity])
    else:
      print "No data has been fetched."
      return -1
开发者ID:gfdi,项目名称:gfdiPiTools,代码行数:84,代码来源:WeatherStation.py


注:本文中的smbus.SMBus.write_quick方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。