コード例 #1
0
    def readpkt(self, timeout=0):
        """ blocks until it reads an RSP packet, and returns it's
            data"""
        c = None
        discards = []
        if timeout > 0:
            start = time.time()
        while (c != '$'):
            if c: discards.append(c)
            c = self.port.read()
            if timeout > 0 and start + timeout < time.time():
                return
        if len(discards) > 0 and self.verbose: print 'discards', discards
        res = [c]

        while True:
            res.append(self.port.read())
            if res[-1] == '#' and res[-2] != "'":
                res.append(self.port.read())
                res.append(self.port.read())
                try:
                    res = unpack(''.join(res))
                except:
                    self.port.write('-')
                    res = []
                    continue
                self.port.write('+')
                #print "read", res
                return res
コード例 #2
0
ファイル: rsp.py プロジェクト: stef/pyrsp
    def readpkt(self, timeout=0):
        """ blocks until it reads an RSP packet, and returns it's
            data"""
        c = b""
        discards = []
        if timeout > 0:
            start = time.time()
        while (c != b'$'):
            if c: discards.append(s(c))
            c = self.port.read()
            if timeout > 0 and start + timeout < time.time():
                return
        if len(discards) > 0 and self.verbose: print('discards %s' % discards)
        res = c

        while True:
            res += self.port.read()
            if res[-1:] == b'#':
                res += self.port.read() + self.port.read()
                if self.ack:
                    try:
                        res = unpack(res)
                    except:
                        self.port.write(b'-')
                        res = b''
                        continue
                    self.port.write(b'+')
                else:
                    # Do not even check packages in NoAck mode.
                    # If a user relies on the connection robustness then we
                    # should provide as fast operation as we can.
                    res = res[1:-3]
                #print("read %s" % res)
                return res
コード例 #3
0
ファイル: rsp.py プロジェクト: chaosAD/pyrsp
    def readpkt(self, timeout=0):
        """ blocks until it reads an RSP packet, and returns it's
            data"""
        c=None
        discards=[]
        if timeout>0:
            start = time.time()
        while(c!='$'):
            if c: discards.append(c)
            c=self.port.read()
            if timeout>0 and start+timeout < time.time():
                return
        if len(discards)>0: print 'discards', discards
        res=[c]

        while True:
            res.append(self.port.read())
            if res[-1]=='#' and res[-2]!="'":
                res.append(self.port.read())
                res.append(self.port.read())
                try:
                    res=unpack(''.join(res))
                except:
                    self.port.write('-')
                    res=[]
                    continue
                self.port.write('+')
                #print "read", res
                return res
コード例 #4
0
ファイル: rsp.py プロジェクト: stef/pyrsp
    def readpkt(self, timeout=0):
        """ blocks until it reads an RSP packet, and returns it's
            data"""
        c=b""
        discards=[]
        if timeout>0:
            start = time.time()
        while(c!=b'$'):
            if c: discards.append(s(c))
            c=self.port.read()
            if timeout>0 and start+timeout < time.time():
                return
        if len(discards)>0 and self.verbose: print('discards %s' % discards)
        res=c

        while True:
            res += self.port.read()
            if res[-1:]==b'#':
                res += self.port.read() + self.port.read()
                if self.ack:
                    try:
                        res = unpack(res)
                    except:
                        self.port.write(b'-')
                        res = b''
                        continue
                    self.port.write(b'+')
                else:
                    # Do not even check packages in NoAck mode.
                    # If a user relies on the connection robustness then we
                    # should provide as fast operation as we can.
                    res = res[1:-3]
                #print("read %s" % res)
                return res