예제 #1
0
    def Pack(cmd, *data):
        if isinstance(cmd, int):
            iCmd = cmd
        elif isinstance(cmd, bytes):
            if len(cmd) == 1:
                iCmd = cmd[0]
            else:
                raise Exception('If cmd is bytes, its len must be one!')
        elif isinstance(cmd, str):
            if len(cmd) == 2 and func.ishexstr(cmd):
                iCmd = func.hexstr2buf(cmd)[0]
            else:
                raise Exception('cmd format err!')
        else:
            raise Exception('cmd format err!')

        baData = Reader.GetInputBytes(*data)

        datalen = len(baData)
        ba = bytearray(datalen + 5)
        ba[0] = 0xAA
        ba[1] = datalen + 2
        ba[2] = iCmd
        for i in range(datalen):
            ba[3 + i] = baData[i]
        ba[3 + datalen] = func.bcc(bytes(ba[1:3 + datalen]))
        ba[4 + datalen] = 0xCC
        return func.buf2hexstr(ba)
예제 #2
0
 def on_pb_CosCmd(self):
     coscmd = self.ui.le_CosCmd.text()
     if not func.ishexstr(coscmd):
         self.showTip('COS cmd fmt err! [%s]' % coscmd)
         return
     self.Log('CpuCmd ' + coscmd)
     r = self.reader.CpuCmd(coscmd)
     if r:
         self.ui.le_CosRetCode.setText(r[1])
         if r[2]:
             self.ui.le_CosRetData.setText(r[2])
     self.Log(r, 1)
예제 #3
0
 def cosCmd(self, coscmd):
     self.Log('CpuCmd ' + coscmd)
     if not func.ishexstr(coscmd):
         self.Log('COS cmd fmt err! [%s]' % coscmd)
         return (False, None, None)
     r = self.reader.CpuCmd(coscmd)
     # if r:
     #     self.ui.le_CosRetCode.setText(r[1])
     #     if r[2]:
     #         self.ui.le_CosRetData.setText(r[2])
     self.Log(r, 1)
     return r
예제 #4
0
 def on_pb_WriteBlock(self):
     blocknostr = self.ui.cob_BlockNo.currentText()
     blockno = int(blocknostr, 10)
     data = self.ui.le_WriteBlock.text()
     if len(data) != 32 or not func.ishexstr(data):
         # QMessageBox.information(self, 'Caution', 'Write block data fmt err!' + ' [' + data + ']', QMessageBox.Ok)
         self.showTip('Write block data fmt err!' + ' [' + data + ']')
         return
     if blockno in range(3, 64, 4):
         reply = QMessageBox.information(self, 'Caution',
                                         'Sure to write key block?',
                                         QMessageBox.Yes | QMessageBox.No)
         if QMessageBox.No == reply:
             return
     self.Log('WriteBlock ' + blocknostr + ' ' + data)
     r = self.reader.WriteBlock(blockno, data)
     self.Log(r, 1)
예제 #5
0
 def GetInputBytes(*data):
     if data == None:
         return bytes()
     baData = bytes()
     for d in data:
         if d == None:
             pass
         elif isinstance(d, int):
             baData += bytes(chr(d), 'ISO8859-1')
         elif isinstance(d, bytes):
             baData += d
         elif isinstance(d, str):
             if func.ishexstr(d):
                 baData += func.hexstr2buf(d)
             else:
                 raise Exception('data format err!')
         else:
             raise Exception('data format err! curr type of data is ' +
                             str(type(d)) + '.')
     return baData