Пример #1
0
    def _clean_response(self, r):
    #        print len(r)
        handshake = r[:4]

        #print handshake,handshake=='a'+DLE+'0'+STX
        if handshake == 'a' + DLE + '0' + STX:

            chksum = computeBCC(r[4:-1])

            #print 'a={} b={} c={} d={}'.format(chksum, ord(r[-1]), chr(chksum),chr(chksum) == r[-1])
            if chr(chksum) == r[-1]:
                return r[8:-2]
Пример #2
0
    def _clean_response(self, r):
    #        print len(r)
        handshake = r[:4]

        #print handshake,handshake=='a'+DLE+'0'+STX
        if handshake == 'a' + DLE + '0' + STX:

            chksum = computeBCC(r[4:-1])

            #print 'a={} b={} c={} d={}'.format(chksum, ord(r[-1]), chr(chksum),chr(chksum) == r[-1])
            if chr(chksum) == r[-1]:
                return r[8:-2]
Пример #3
0
    def _build_command(self, start_addr, values):

        if isinstance(start_addr, int):
            start_addr = '{:04X}'.format(start_addr)

        if isinstance(values, int):
            values = (values,)
            #            values = ('{:04X}'.format(values),)

        values = list(map('{:04X}'.format, values))

        cmd = start_addr + ''.join(values)
        cmd += ETX
        BCC = computeBCC(cmd)

        cmd = STX + cmd + chr(BCC)

        return cmd
Пример #4
0
    def _build_command(self, start_addr, values):

        if isinstance(start_addr, int):
            start_addr = '{:04X}'.format(start_addr)

        if isinstance(values, int):
            values = (values,)
            #            values = ('{:04X}'.format(values),)

        values = map('{:04X}'.format, values)

        cmd = start_addr + ''.join(values)
        cmd += ETX
        BCC = computeBCC(cmd)

        cmd = STX + cmd + chr(BCC)

        return cmd