本文整理汇总了Python中quick2wire.i2c.reading函数的典型用法代码示例。如果您正苦于以下问题:Python reading函数的具体用法?Python reading怎么用?Python reading使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了reading函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getFullLuminosity
def getFullLuminosity(self):
self.enable()
self.wait()
with i2c.I2CMaster(self.i2cbus) as bus:
read_results = bus.transaction(
i2c.writing_bytes(address, self.COMMAND_BIT | self.WORD_BIT | self.REGISTER_CHAN1_LOW ),
i2c.reading(address, 2),
i2c.writing_bytes(address, self.COMMAND_BIT | self.WORD_BIT | self.REGISTER_CHAN0_LOW ),
i2c.reading(address, 2)
)
self.disable()
full = read_results[0][1]
# print("---- full: %#08x" % full)
full = full << 8
full += read_results[0][0]
# print("---- full: %#08x" % full)
full = full << 8
full += read_results[1][1]
# print("---- full: %#08x" % full)
full = full << 8
full += read_results[1][0]
# print("---- full: %#08x" % full)
return full
示例2: readAlarmTime
def readAlarmTime(month, year):
#---------
# minute
#--------
minute, minute2 = bus.transaction( i2c.writing_bytes(rtc_address1, 0x09),
i2c.reading(rtc_address1,2))[0]
timeminute1 = ((minute >> 4) & 0x07)
timeminute2 = (minute & 0x0F)
#------
# hour
#------
hour, hour2 = bus.transaction( i2c.writing_bytes(rtc_address1, 0x0A),
i2c.reading(rtc_address1,2))[0]
timehour1 = ((hour >> 4) & 0x03)
timehour2 = (hour & 0x0F)
#------
# Day
#-----
day, day2 = bus.transaction( i2c.writing_bytes(rtc_address1, 0x0B),
i2c.reading(rtc_address1,2))[0]
timeday1 = ((day >> 4) & 0x05)
timeday2 = (day & 0x0F)
alminute = int(str(timeminute1)+str(timeminute2))
alhour = int(str(timehour1)+str(timehour2))
alday = int(str(timeday1)+str(timeday2))
weekday,dayname = weekDay(year,month,alday)
return alminute, alhour, alday, weekday, dayname
示例3: getDate
def getDate():
# get date and return value
#get day
day, day2 = bus.transaction(
i2c.writing_bytes(rtc_address1, 0x05),
i2c.reading(rtc_address1,2))[0]
timeday1 = ((day >> 4) & 0x03)
timeday2 = (day & 0x0F)
#get month
month, month2 = bus.transaction(
i2c.writing_bytes(rtc_address1, 0x07),
i2c.reading(rtc_address1,2))[0]
timemonth1 = ((month >> 4) & 0x01)
timemonth2 = (month & 0x0F)
#get year
year, year2 = bus.transaction(
i2c.writing_bytes(rtc_address1, 0x08),
i2c.reading(rtc_address1,2))[0]
timeyear1 = ((year >> 4))
timeyear2 = (year & 0x0F)
return str(timeday1) + str(timeday2) + "/" + str(timemonth1) + str(timemonth2) + "/" + str(timeyear1) + str(timeyear2)
示例4: getadcreading
def getadcreading(address, channel, gain, res):
channel = channel - 1
adcConfig = MCP342X_START | MCP342X_CHANNEL_1 | MCP342X_CONTINUOUS
adcConfig |= channel << 5 | res << 2 | gain
#print("adcConfig")
#print(adcConfig)
varDivisior = 1 << (gain + 2*res)
bus.transaction(i2c.writing_bytes(address, adcConfig))
time.sleep(0.05)
if (res ==3):
h, m, l ,s = bus.transaction(i2c.reading(address,4))[0]
time.sleep(0.05)
h, m, l, s = bus.transaction(i2c.reading(address,4))[0]
t = ((h & 0b00000001) << 16) | (m << 8) | l
else:
h, m, l = bus.transaction(i2c.reading(address,3))[0]
time.sleep(0.05)
h, m, l = bus.transaction(i2c.reading(address,3))[0]
t = (h << 8) | m
if (h > 128):
t = ~(0x020000 - t)
# remove / 1000 to return value in milivolts
return ((t/varDivisior) * 2.4705882) / 1000
示例5: getadcreading
def getadcreading(address, adcConfig, res):
bus.transaction(i2c.writing_bytes(address, adcConfig))
if res == 0:
h, m, l, s = bus.transaction(i2c.reading(address, 4))[0]
while s & 128:
h, m, l, s = bus.transaction(i2c.reading(address, 4))[0]
# shift bits to product result
t = ((h & 0b00000001) << 16) | (m << 8) | l
# check if positive or negative number and invert if needed
if h > 128:
t = ~(0x020000 - t)
return t / 64000
else:
m, l, s = bus.transaction(i2c.reading(address, 3))[0]
while s & 128:
m, l, s = bus.transaction(i2c.reading(address, 3))[0]
# shift bits to product result
t = (m << 8) | l
# check if positive or negative number and invert if needed
if m > 128:
t = ~(0x02000 - t)
if res == 4:
return t / 16000
if res == 8:
return t / 4000
if res == 12:
return t / 1000
示例6: read_raw
def read_raw(self, channel):
if channel != self._last_channel_read:
self.master.transaction(writing_bytes(self.address, self._control_flags|channel),
reading(self.address, 2))
self._last_channel_read = channel
results = self.master.transaction(
reading(self.address, 2))
return results[0][-1]
示例7: getadcreading
def getadcreading(address):
h, l ,s = bus.transaction(i2c.reading(address,3))[0]
while (s & 128):
h, l, s = bus.transaction(i2c.reading(address,3))[0]
# shift bits to product result
t = (h << 8) | l
# check if positive or negative number and invert if needed
if (h > 128):
t = ~(0x020000 - t)
return t * varMultiplier
示例8: read_data
def read_data(port_expand_addr, port):
with q2w_i2c.I2CMaster() as bus:
if port == 'A':
return bus.transaction(
q2w_i2c.writing_bytes(port_expand_addr, GPIOA),
q2w_i2c.reading(port_expand_addr, 1))[0][0]
elif port == 'B':
return bus.transaction(
q2w_i2c.writing_bytes(port_expand_addr, GPIOB),
q2w_i2c.reading(port_expand_addr, 1))[0][0]
示例9: getadcreading
def getadcreading(address):
h, m, l, s = bus.transaction(i2c.reading(address, 4))[0]
while s & 128:
h, m, l, s = bus.transaction(i2c.reading(address, 4))[0]
# shift bits to product result
t = ((h & 0b00000001) << 16) | (m << 8) | l
# check if positive or negative number and invert if needed
if h > 128:
t = ~(0x020000 - t)
return t * varMultiplier
示例10: getadcreading
def getadcreading(address, channel):
bus.transaction(i2c.writing_bytes(address, channel))
time.sleep(0.001)
h, l, r = bus.transaction(i2c.reading(address,3))[0]
time.sleep(0.001)
h, l, r = bus.transaction(i2c.reading(address,3))[0]
t = (h << 8 | l)
if (t >= 32768):
t = 65536 -t
v = (t * 0.000154 )
if (v < 5.5):
return v
return 0.00
示例11: __readADC
def __readADC(self):
command = 0x00
#Read D1
self.bus.transaction(i2c.writing_bytes(self.address, 0x48))
time.sleep(0.01)
values = self.bus.transaction(i2c.writing_bytes(self.address, command), i2c.reading(self.address, 3))
self.D[1] = (values[0][0] << 16) | (values[0][1] << 8) | (values[0][2])
self.logger.debug("CMD(" + "{0:#04x}".format(command) + ") -> D1 = " + str(self.D[1]))
# Read D2
self.bus.transaction(i2c.writing_bytes(self.address, 0x58))
time.sleep(0.01)
values = self.bus.transaction(i2c.writing_bytes(self.address, command), i2c.reading(self.address, 3))
self.D[2] = (values[0][0] << 16) | (values[0][1] << 8) | (values[0][2])
self.logger.debug("CMD(" + "{0:#04x}".format(command) + ") -> D2 = " + str(self.D[2]))
示例12: get_resolutions
def get_resolutions(self):
user_reg = self.bus.transaction(
i2c.writing_bytes(self.ADDR, self.CMD_READ_USER_REG),
i2c.reading(self.ADDR, 1),
)
user_reg_int = int.from_bytes(user_reg[0], byteorder="big")
return self.RESOLUTIONS[user_reg_int >> 6, user_reg_int & 0x1]
示例13: select_mifare
def select_mifare(self):
with I2CMaster() as master:
# select mifare card
# <len> <cmd>
master.transaction(writing_bytes(ADDRESS, 1, CMD_SELECT_MIFARE))
time.sleep(WR_RD_DELAY)
# read the response
responses = master.transaction(reading(ADDRESS, 15))
response = responses[0]
# <len> <cmd> <status> <UUID> <type>
len = response[0]
cmd = response[1]
status = response[2]
if (status != 0x00):
self.uid = None
self.type = None
return False
# uid length varies on type, and type is after uuid
uid = response[3:len]
type = response[len]
self.type = type
self.uid = uid
return True
示例14: read_response
def read_response(self):
"""Wait, then read for a response from the PN532."""
logging.debug("readResponse...")
response = [b'\x00\x00\x00\x00\x00\x00\x00']
while True:
try:
logging.debug("readResponse..............Reading.")
sleep(DEFAULT_DELAY)
response = self.PN532.transaction(
reading(self.address, 255))
logging.debug(response)
logging.debug("readResponse..............Read.")
except Exception:
pass
else:
try:
frame = Pn532Frame.from_response(response)
# Acknowledge Data frames coming from the PN532
if frame.get_frame_type() == PN532_FRAME_TYPE_DATA:
self.send_command(Pn532Frame(
frame_type=PN532_FRAME_TYPE_ACK))
except Exception as ex:
logging.debug(ex)
logging.debug(ex.args)
pass
else:
return frame
示例15: getReady
def getReady(self):
readyFlag = 0
i = False
attempt = 0
results=[]
standbyFlag = 0
sys.stdout.flush()
time.sleep(0.1)
print("Getting ready ", end ="")
while (i==False):
results = self.bus.transaction(
reading(self.add, 5)
)
readyFlag = 1 if (results[0][0]&0x80)==128 else 0
standbyFlag = 1 if (results[0][3]&0x40)!=319 else 0
sys.stdout.flush()
time.sleep(0.1)
print(".", end = "")
i=standbyFlag*readyFlag
attempt+=1
if(attempt>20):
break
time.sleep(0.2)
if(i==True):
print("Ready! (",attempt,")")
return True
# print("Raw output ", results[0])
else:
self.i2c.read_byte(self.add)
print("Not ready! (", attempt, ")")
return False