본문 바로가기

넥시온 업로드 프로토콜 v1.2는 v1.1 프로토콜의 개선된 버전으로, 수정되지 않은 파일의 일부를 건너뛰어 넥시온/TJC 디스플레이에 TFT 파일을 더 빠르게 업로드 할 수 있습니다. 이는 사진과 글꼴과 같은 리소스가 변경되지 않은 경우 건너뛰게 됨을 의미합니다.

 

자세한 내용은 아래 글에서 볼 수 있습니다. 공식적인 것인지는 잘 모르겠네요.

nxt-doc/Upload Protocol v1.2.md at main · UNUF/nxt-doc · GitHub\

 

GitHub - UNUF/nxt-doc: Documentation around Nextion Stuff. HMI files, TFT files, ZI files, ...

Documentation around Nextion Stuff. HMI files, TFT files, ZI files, ... - GitHub - UNUF/nxt-doc: Documentation around Nextion Stuff. HMI files, TFT files, ZI files, ...

github.com

우리 빙신(Bing Chatbot) 께서 아래와 같이 번역해 주시고, 

v1.1: whmi-wri FILE_SIZE,BAUD_RATE,DONT_CARE 명령을 전송하여 업로드
v1.2: whmi-wris FILE_SIZE,BAUD_RATE,1
세 번째 인수는 그냥 1 주세요.

파일의 첫 번째 4096 바이트 블록을 전송한 후에 디바이스가 일반적인 0x05 응답 대신 다운로드가 계속될 주소를 지정합니다. 응답은 0x08로 시작하고 4바이트 정수 (리틀 엔디안/최하위 바이트 먼저)가 뒤따릅니다. 이 정수가 0과 같으면 스킵 없이 업로드가 계속됩니다. 그렇지 않으면 지정된 오프셋에서 계속됩니다. 예를 들어 08 00 00 11 00은 오프셋 0x110000에서 계속해야 함을 의미합니다. 오프셋은 파일 시작 부분에 상대적이며 현재 위치가 아닙니다.

완벽한 Nextion HMI 제어하는 파이썬 코드의 끝판왕은 여기 있었네요.

https://github.com/MMMZZZZ/Nexus/blob/master/Nexus.py

 

GitHub - MMMZZZZ/Nexus: Nextion Upload Script

Nextion Upload Script. Contribute to MMMZZZZ/Nexus development by creating an account on GitHub.

github.com

코드를 간단하게 수정해서 공개합니다. 필요한 사람들 쓰세요.

코드는 테스트 전용입니다. 사용상 에러에 대한 책임은 없습니다. ㅋㅋ 무책임 버전이니 필요하신 분만 참고하세요.

import os
import serial
import time

ser = serial.Serial("COM8", 9600, timeout=1)

while True:
    a = f"DRAKJHSUYDGBNCJHGJKSHBDN"
    print(a)
    ser.write(a.encode())
    ser.write(b"\xff\xff\xff")
    a = f"connect"
    print(a)
    ser.write(a.encode())
    ser.write(b"\xff\xff\xff")
    ser.write(b"\xff\xff")
    a = f"connect"
    print(a)
    ser.write(a.encode())
    ser.write(b"\xff\xff\xff")
    response = b""
    while response[-3:] != b"\xff\xff\xff":
        response += ser.read(1)
    print(response)
    if response[:5] == b"comok":
        break

while True:
    file_name = "testfw.tft"
    file_size = os.path.getsize(file_name)
    print(f"File size: {file_size} bytes")
    while True:
        a = f"whmi-wris {file_size},921600,0"
        ser.write(a.encode())
        ser.write(b"\xff\xff\xff")
        ser.close()
        ser = serial.Serial("COM8", 921600, timeout=1)
        time.sleep(0.5)
        ack = ser.read(1)
        if ack != b"\x05":
            print(f"Error: did not receive 0x05, received {ack.hex()}")
            ser.close()
            ser = serial.Serial("COM8", 9600, timeout=1)
        else:
            break

    with open(file_name, "rb") as f:
        while True:
            data = f.read(4096)
            if not data:
                break
            ser.write(data)
            print(".")
            time.sleep(0.2)
            ack = ser.read(1)
            if ack != b"\x05":
                if ack != b"\x08":
                    print(f"Error: did not receive 0x05, received {ack.hex()}")
                else:
                    print(f"received {ack.hex()}")
                    time.sleep(0.5)
                    offset = ser.read(4)
                    print(offset)
                    # import struct
                    # # byte_array = b'\x00\x00\x11\x00'
                    # integer_value = struct.unpack("<I", offset)[0]
                    integer_value = int.from_bytes(offset, "little")
                    print(integer_value)
                    f.seek(integer_value)

    print("complete.")
    break

같은 파일로 테스트 하니깐, 쓩 그냥 완료해 버리네. 

일부 파일 중복을 체크해서 좀 더 빠르게 업데이트 하긴 하나 보다.

655360 만큼 스킵 Nextion update v1.2 log

 그나저나 공식 매뉴얼에는 왜 없을까?

B로그0간

개발 관련 글과 유용한 정보를 공유하는 공간입니다.