Example #1
0
    def run(self):

        try:
            self._port = tl_open_port(self._port_name)
        except Exception:
            self.textSignal.emit("串口 " + self._port_name +
                                 " 打开失败,请检查串口是否被占用!!!")
            self.stateSignal.emit(1)
            return

        self.stateSignal.emit(0)
        self.textSignal.emit("打开串口成功!!!")

        self._port.setRTS(False)
        self._port.setDTR(False)

        while (True):
            if self._stop:
                break

            result = uart_read(self._port)
            if (len(result) > 1):
                self.textSignal.emit(result)
            time.sleep(0.1)

        self._port.close()
        self._port = None

        self.stateSignal.emit(1)
    def run(self):

        try:
            _port = tl_open_port(self._port_name)
        except Exception:
            self.textSignal.emit("串口 " + self._port_name +
                                 " 打开失败,请检查串口是否被占用!!!")
            self.pressbarSignal.emit(200)
            return

        self.pressbarSignal.emit(1000)
        self.textSignal.emit("打开串口成功!!!")

        if self.action == "reset":  #复位模组,进入运行模式
            _port.setRTS(True)
            _port.setDTR(False)

            time.sleep(0.1)

            _port.setRTS(False)

            self.textSignal.emit("模组已复位!!!")
            self.pressbarSignal.emit(100)
            _port.close()
            return

        if not connect_chip(_port):  #连接芯片,进入烧录模式
            self.textSignal.emit("连接芯片失败!!!")
            self.pressbarSignal.emit(200)
            _port.close()
            return
        self.textSignal.emit("连接芯片成功!")

        if self.action == "burn":  #烧录固件

            self.textSignal.emit("尝试提高波特率...")

            if change_baud(_port):
                self.textSignal.emit("提高波特率成功!!!")

            self.textSignal.emit("擦除固件 ... ... ")

            if not telink_flash_erase(_port, 0x4000, 44):
                self.textSignal.emit("擦除固件失败!!!")
                self.pressbarSignal.emit(200)
                _port.close()
                return
            self.textSignal.emit("擦除固件成功!")

            self.textSignal.emit("烧录固件 :" + self.args.file_name)

            fo = open(self.args.file_name, "rb")
            firmware_addr = 0
            firmware_size = os.path.getsize(self.args.file_name)
            percent = 0

            if (firmware_size >= 192 * 1024):  # 固件大于192KB,说明是合并好的固件,要跳过Boot
                fo.seek(16 * 1024, 0)
                firmware_addr = 16 * 1024

            while True:
                data = fo.read(256)
                if len(data) < 1: break

                if not telink_flash_write(_port, firmware_addr, data):
                    self.textSignal.emit("烧录固件失败!!!")
                    self.pressbarSignal.emit(200)
                    break

                firmware_addr += len(data)

                percent = (int)(firmware_addr * 100 / firmware_size)
                self.pressbarSignal.emit(percent)  # 跟新进度条

            if percent == 100: self.textSignal.emit("烧录固件完成!")
            fo.close()

        elif self.action == "burn_triad":  #烧录三元组

            self.textSignal.emit("擦除三元组 ... ... ")

            if not telink_flash_erase(_port, 0x78000, 1):
                self.textSignal.emit("擦除三元组失败!!!")
                self.pressbarSignal.emit(200)
                _port.close()
                return
            self.textSignal.emit("擦除三元组成功!")

            self.textSignal.emit("烧录三元组 :" + str(self.args.triad))

            if telink_flash_write(_port, 0x78000, self.args.triad):
                self.textSignal.emit("烧录三元组成功!")
                self.pressbarSignal.emit(100)
            else:
                self.textSignal.emit("烧录三元组失败!!!")
                self.pressbarSignal.emit(200)

        elif self.action == "erase":  #擦除Flash

            self.textSignal.emit("擦除Flash: 从 " + hex(self.args.addr) + " 擦除 " +
                                 str(self.args.len_t) + " 扇区... ... ")

            if telink_flash_erase(_port, self.args.addr, self.args.len_t):
                self.textSignal.emit("擦除成功!")
                self.pressbarSignal.emit(100)
            else:
                self.textSignal.emit("擦除失败!!!")
                self.pressbarSignal.emit(200)

        _port.close()
Example #3
0
    def run(self):

        try:
            _port = tl_open_port(self._port_name)
        except Exception:
            self.textSignal.emit("串口 " + self._port_name +
                                 " 打开失败,请检查串口是否被占用!!!")
            self.pressbarSignal.emit(200)
            return

        self.pressbarSignal.emit(1000)
        self.textSignal.emit("打开串口成功!!!")

        if self.action == "reset":  #复位模组,进入运行模式
            _port.setRTS(True)
            _port.setDTR(False)

            time.sleep(0.1)

            _port.setRTS(False)

            self.textSignal.emit("模组已复位!!!")
            self.pressbarSignal.emit(100)
            _port.close()
            return

        if not connect_chip(_port):  #连接芯片,进入烧录模式
            self.textSignal.emit("连接芯片失败!!!")
            self.pressbarSignal.emit(200)
            _port.close()
            return
        self.textSignal.emit("连接芯片成功!")

        info = get_chip_info(_port)  #获取芯片信息
        if len(info) != 5:
            self.textSignal.emit("获取芯片信息失败!!!")
            self.pressbarSignal.emit(200)
            _port.close()
            return

        jedecid = hex((info[0] << 16) | (info[1] << 8) | info[2])
        fsize = str((1 << info[2]) >> 10) + " KBytes"
        chip = hex(info[3] * 256 + info[4])

        self.textSignal.emit("Chip Type:" + chip + "  Flash ID:" + jedecid +
                             "  Size:" + fsize)

        if self.action == "burn":  #烧录固件

            self.textSignal.emit("擦除固件 ... ... ")

            if not telink_flash_erase(_port, 0, 48):
                self.textSignal.emit("擦除固件失败!!!")
                self.pressbarSignal.emit(200)
                _port.close()
                return
            self.textSignal.emit("擦除固件成功!")

            self.textSignal.emit("烧录固件 :" + self.args.file_name)

            fo = open(self.args.file_name, "rb")
            firmware_addr = 0
            firmware_size = os.path.getsize(self.args.file_name)
            percent = 0

            if (firmware_size >= 192 * 1024):  # 固件大于192KB,说明是合并好的固件,要跳过Boot
                fo.seek(16 * 1024, 0)
                firmware_addr = 16 * 1024

            while True:
                data = fo.read(256)
                if len(data) < 1: break

                if not telink_flash_write(_port, firmware_addr, data):
                    self.textSignal.emit("烧录固件失败!!!")
                    self.pressbarSignal.emit(200)
                    break

                firmware_addr += len(data)

                percent = (int)(firmware_addr * 100 / firmware_size)
                self.pressbarSignal.emit(percent)  # 跟新进度条

            if percent == 100: self.textSignal.emit("烧录固件完成!")
            fo.close()

        elif self.action == "burn_triad":  #烧录三元组

            self.textSignal.emit("擦除三元组 ... ... ")

            if not telink_flash_erase(_port, 0x78000, 1):
                self.textSignal.emit("擦除三元组失败!!!")
                self.pressbarSignal.emit(200)
                _port.close()
                return
            self.textSignal.emit("擦除三元组成功!")

            self.textSignal.emit("烧录三元组 :" + str(self.args.triad))

            if telink_flash_write(_port, 0x78000, self.args.triad):
                self.textSignal.emit("烧录三元组成功!")
                self.pressbarSignal.emit(100)
            else:
                self.textSignal.emit("烧录三元组失败!!!")
                self.pressbarSignal.emit(200)

        elif self.action == "erase":  #擦除Flash

            self.textSignal.emit("擦除Flash: 从 " + hex(self.args.addr) + " 擦除 " +
                                 str(self.args.len_t) + " 扇区... ... ")

            if telink_flash_erase(_port, self.args.addr, self.args.len_t):
                self.textSignal.emit("擦除成功!")
                self.pressbarSignal.emit(100)
            else:
                self.textSignal.emit("擦除失败!!!")
                self.pressbarSignal.emit(200)

        _port.close()