本文整理匯總了Python中transport.Transport.nfcGetRecordData方法的典型用法代碼示例。如果您正苦於以下問題:Python Transport.nfcGetRecordData方法的具體用法?Python Transport.nfcGetRecordData怎麽用?Python Transport.nfcGetRecordData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類transport.Transport
的用法示例。
在下文中一共展示了Transport.nfcGetRecordData方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: MicroNFCBoard
# 需要導入模塊: from transport import Transport [as 別名]
# 或者: from transport.Transport import nfcGetRecordData [as 別名]
#.........這裏部分代碼省略.........
self._updateStatus()
return self._polling
@property
def ndefMessagePresent(self):
self._updateStatus()
return self._ndefMessagePresent
@property
def ndefRecords(self):
self._updateStatus()
if self._ndefMessagePresent and not self._ndefRead:
self._ndefRecords = self._getNdefMessageRecords()
self._ndefRecordsRead = True
return self._ndefRecords
@property
def version(self):
return self._version
def getNfcInfo(self):
return self._transport.nfcGetInfo()
def reset(self):
self._transport.reset(False)
def startPolling(self):
self._transport.nfcPoll(True)
def stopPolling(self):
self._transport.nfcPoll(True)
def setLeds(self, led1, led2):
self._transport.leds(led1, led2)
def _updateStatus(self):
status = self._transport.status()
self._polling = (status & STATUS_POLLING) != 0
self._connected = (status & STATUS_CONNECTED) != 0
self._ndefMessagePresent = (status & STATUS_NDEF_PRESENT) != 0
if not self._ndefMessagePresent:
self._ndefRecordsRead = False
def _getNdefRecords(self, start, count):
records = []
for recordNumber in range(start, start+count):
#Get records info
recordType, recordInfo = self._transport.nfcGetRecordInfo(recordNumber)
funcs = { 0 : self._parseUnknownRecord,
1 : self._parseURIRecord,
2 : self._parseTextRecord,
3 : self._parseSmartPosterRecord,
4 : self._parseMIMERecord,
}
record = funcs[recordType](recordNumber, recordInfo)
if record != None:
records += [record]
return records
def _getNdefMessageRecords(self):
#Get message count
recordsCount = self._transport.nfcGetMessageInfo()
return self._getNdefRecords(0, recordsCount)
def _parseUnknownRecord(self, recordNumber, recordInfo):
return None
def _parseURIRecord(self, recordNumber, recordInfo):
uriLength = recordInfo[0]
uri = unicode(self._getRecordData(recordNumber, 0, uriLength).tostring(), "utf-8")
return URIRecord(uri)
def _parseTextRecord(self, recordNumber, recordInfo):
encoding = TEXT_ENCODING[recordInfo[0]]
languageCodeLength = recordInfo[1]
textLength = recordInfo[2]
languageCode = unicode(self._getRecordData(recordNumber, 0, languageCodeLength).tostring(), "utf-8")
text = unicode(self._getRecordData(recordNumber, 1, textLength).tostring(), encoding)
return TextRecord(text, languageCode)
def _parseSmartPosterRecord(self, recordNumber, recordInfo):
recordsStart = recordInfo[0]
recordsCount = recordInfo[1]
records = self._getNdefRecords(recordsStart, recordsCount)
return SmartPosterRecord(records)
def _parseMIMERecord(self, recordNumber, recordInfo):
mimeTypeLength = recordInfo[0]
dataLength = recordInfo[1]
mimeType = unicode(self._getRecordData(recordNumber, 0, mimeTypeLength).tostring(), "utf-8")
data = self._getRecordData(recordNumber, 1, dataLength)
return MIMERecord(mimeType, data)
def _getRecordData(self, recordNumber, item, itemLength):
buf = array("B")
while len(buf) < itemLength:
chunkLength = min(CHUNK_SIZE, itemLength - len(buf))
buf += self._transport.nfcGetRecordData(recordNumber, item, len(buf), chunkLength)
return buf
示例2: MicroNFCBoard
# 需要導入模塊: from transport import Transport [as 別名]
# 或者: from transport.Transport import nfcGetRecordData [as 別名]
#.........這裏部分代碼省略.........
uriPrefix = recordInfo[0]
uriLength = recordInfo[1]
uri = unicode(self._decodePrefix(uriPrefix).tostring() + self._getRecordData(recordNumber, 0, uriLength).tostring(), "utf-8")
return URIRecord(uri)
def _parseTextRecord(self, recordNumber, recordInfo):
encoding = TEXT_ENCODING[recordInfo[0]]
languageCodeLength = recordInfo[1]
textLength = recordInfo[2]
languageCode = unicode(self._getRecordData(recordNumber, 0, languageCodeLength).tostring(), "utf-8")
text = unicode(self._getRecordData(recordNumber, 1, textLength).tostring(), encoding)
return TextRecord(text, languageCode, encoding)
def _parseSmartPosterRecord(self, recordNumber, recordInfo):
recordsStart = recordInfo[0]
recordsCount = recordInfo[1]
records = self._getNdefRecords(recordsStart, recordsCount)
return SmartPosterRecord(records)
def _parseMIMERecord(self, recordNumber, recordInfo):
mimeTypeLength = recordInfo[0]
dataLength = recordInfo[1]
mimeType = unicode(self._getRecordData(recordNumber, 0, mimeTypeLength).tostring(), "utf-8")
data = self._getRecordData(recordNumber, 1, dataLength)
return MIMERecord(mimeType, data)
def _decodePrefix(self, prefix):
return self._transport.nfcDecodePrefix(prefix)
def _getRecordData(self, recordNumber, item, itemLength):
buf = array("B")
while len(buf) < itemLength:
chunkLength = min(CHUNK_SIZE, itemLength - len(buf))
buf += self._transport.nfcGetRecordData(recordNumber, item, len(buf), chunkLength)
return buf
def _setNdefRecords(self, records):
self._transport.nfcPrepareMessage(True, False)
recordNumber = 0
spRecordNumber = len(records) #Smart poster records after main records
for record in records:
spRecordNumber = self._addNdefRecord(recordNumber, record, spRecordNumber)
recordNumber += 1
self._transport.nfcSetMessageInfo(recordNumber)
self._transport.nfcPrepareMessage(False, True)
recordNumber = 0
spRecordNumber = len(records)
for record in records:
spRecordNumber = self._setNdefRecord(recordNumber, record, spRecordNumber)
recordNumber += 1
#self._transport.nfcSetMessageInfo(recordNumber)
def _addNdefRecord(self, recordNumber, record, recordsStart, spAllowed = True):
funcs = { URIRecord : self._generateURIRecord,
TextRecord : self._generateTextRecord,
SmartPosterRecord : self._generateSmartPosterRecord,
MIMERecord : self._generateMIMERecord,
}
if( not spAllowed and type(record) == SmartPosterRecord ):
raise SmartPosterNestingException()
return funcs[type(record)](recordNumber, record, recordsStart)
def _generateURIRecord(self, recordNumber, record, spRecordNumber):
#Try to get prefix