當前位置: 首頁>>代碼示例>>Python>>正文


Python Transport.info方法代碼示例

本文整理匯總了Python中transport.Transport.info方法的典型用法代碼示例。如果您正苦於以下問題:Python Transport.info方法的具體用法?Python Transport.info怎麽用?Python Transport.info使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在transport.Transport的用法示例。


在下文中一共展示了Transport.info方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: MicroNFCBoard

# 需要導入模塊: from transport import Transport [as 別名]
# 或者: from transport.Transport import info [as 別名]
class MicroNFCBoard(object):
    @staticmethod
    def getBoard(number = 0):
        a = INTERFACE[usb_backend].getAllConnectedInterface(VID, PID)
        if((a != None) and (len(a) > number)):
            return MicroNFCBoard(a[number])
        return None
    
    @staticmethod
    def getAllBoards():
        return [MicroNFCBoard(i) for i in INTERFACE[usb_backend].getAllConnectedInterface(VID, PID)]
    
    def __init__(self, intf):
        self._intf = intf
        self._transport = Transport()
        self._id = None
        self._version = None
        self._polling = False
        self._connected = False
        self._ndefMessagePresent = False
        self._ndefRecords = None
        self._ndefRead = False
        
    def open(self):
        self._transport.open(self._intf)
        version, revision, self._id = self._transport.info()
        self._version = (version, revision)
        
    def close(self):
        self._transport.close()
        
    @property
    def id(self):
        return self._id
    
    @property
    def connected(self):
        self._updateStatus()
        return self._connected
    
    @property
    def polling(self):
        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
#.........這裏部分代碼省略.........
開發者ID:thejarle,項目名稱:micronfcboard-python,代碼行數:103,代碼來源:board.py

示例2: MicroNFCBoard

# 需要導入模塊: from transport import Transport [as 別名]
# 或者: from transport.Transport import info [as 別名]
class MicroNFCBoard(object):
    @staticmethod
    def getBoard(number = 0):
        a = INTERFACE[usb_backend].getAllConnectedInterface(VID, PID)
        if((a != None) and (len(a) > number)):
            return MicroNFCBoard(a[number])
        return None
    
    @staticmethod
    def getAllBoards():
        return [MicroNFCBoard(i) for i in INTERFACE[usb_backend].getAllConnectedInterface(VID, PID)]
    
    def __init__(self, intf):
        self._intf = intf
        self._transport = Transport()
        self._id = None
        self._version = None
        self._polling = False
        self._connected = False
        self._type2 = False
        self._type4 = False
        self._p2p = False
        self._initiator = False
        self._ndefPresent = False
        self._ndefRecords = None
        self._ndefRead = False
        self._ndefReadable = False
        self._ndefWriteable = False
        self._ndefBusy = False
        self._ndefSuccess = False
        
    def open(self):
        self._transport.open(self._intf)
        version, revision, self._id = self._transport.info()
        self._version = (version, revision)
        if( self._version < TARGET_FIRMWARE ):
            #self._transport.reset(True)
            raise FirmwareUpgradeRequiredException("Your current firmware (version %d.%d) is outdated; please upgrade it to version %d.%d" % (version, revision, TARGET_FIRMWARE[0], TARGET_FIRMWARE[1]))
        
    def close(self):
        self._transport.close()
        
    @property
    def id(self):
        return self._id
    
    @property
    def connected(self):
        self._updateStatus()
        return self._connected

    @property
    def type2Tag(self):
        self._updateStatus()
        return self._type2 and self._initiator
    
    @property
    def type4Emulator(self):
        self._updateStatus()
        return self._type4 and not self._initiator
    
    @property
    def p2p(self):
        self._updateStatus()
        return self._p2p

    @property
    def polling(self):
        self._updateStatus()
        return self._polling
    
    @property
    def ndefReadable(self):
        self._updateStatus()
        return self._ndefReadable
    
    @property
    def ndefWriteable(self):
        self._updateStatus()
        return self._ndefWriteable
    
    @property
    def ndefPresent(self):
        self._updateStatus()
        return self._ndefPresent
    
    @property
    def ndefBusy(self):
        self._updateStatus()
        return self._ndefBusy
    
    @property
    def ndefSuccess(self):
        self._updateStatus()
        return self._ndefSuccess
    
    @property
    def ndefRecords(self):
        self._updateStatus()
        if self._ndefPresent and not self._ndefRead:
#.........這裏部分代碼省略.........
開發者ID:oliviermartin,項目名稱:micronfcboard-python,代碼行數:103,代碼來源:board.py


注:本文中的transport.Transport.info方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。