Skip to content

Commit

Permalink
Fix clicking apply setting failed on wiz5xx < 1.0.8 #36
Browse files Browse the repository at this point in the history
  • Loading branch information
simryang committed May 8, 2024
1 parent 88f454d commit c45bc60
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
31 changes: 26 additions & 5 deletions WIZMakeCMD.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from packaging.version import Version

"""
Make Serial command
Expand Down Expand Up @@ -62,7 +63,8 @@

# 2022.05.10
# WIZ5XXSR-RP added commands
cmd_wiz5xxsr_added = ['SO', 'UF','PO']
# 전역에서 "PO" 삭제 #36
cmd_wiz5xxsr_added = ['SO', 'UF']

# WIZ5XXSR-RP_E-SAVE commands
#cmd_wiz5xxsr_esave = ['U3', 'U4', 'U5', 'U6', 'U7', 'U8', 'U9']
Expand All @@ -80,17 +82,34 @@
cmd_wiz510ssl = cmd_security_base + cmd_wiz510ssl_added
cmd_wiz5xxsr = cmd_security_base + cmd_wiz5xxsr_added


def version_compare(version1, version2):
# @TODO:@BUG 아래 경우 1을 반환해야 하는데 -1을 반환함
# >>> version_compare("1.10.8.1.9", "1.2.8")
# version_compare: obj1 = ['1', '10', '8', '1', '9'] , obj2 = ['1', '2', '8'] , obj1 > obj2 = 0 obj1 < obj2 = 1
# -1
def version_compare_old(version1: str, version2: str):
"""버전을 비교해서 앞이 크면 1 뒤가 크면 -1 같으면 0을 반환
Args:
version1 (str): 첫번째 버전
version2 (str): 두번째 버전
"""
def normalize(v):
# return [x for x in re.sub(r'(\.0+)*$','',v).split('.')]
return [x for x in re.sub(r"(\.0+\.[dev])*$", "", v).split(".")]

obj1 = normalize(version1)
obj2 = normalize(version2)
print("version_compare: obj1 =", obj1, ", obj2 =", obj2, ", obj1 > obj2 =", int(obj1 > obj2), "obj1 < obj2 =", int(obj1 < obj2))
return (obj1 > obj2) - (obj1 < obj2)
# if return value < 0: version2 upper than version1

# 이슈 수정 중 함수 버그 발견해서 수정함 #36
def version_compare(version1: str, version2: str):
"""버전을 비교해서 앞이 크면 1 뒤가 크면 -1 같으면 0을 반환
Args:
version1 (str): 첫번째 버전
version2 (str): 두번째 버전
"""
return 0 if version1 == version2 else -1 if Version(version1) < Version(version2) else 1


class WIZMakeCMD:
def __init__(self):
Expand Down Expand Up @@ -141,7 +160,9 @@ def search(self, mac_addr, idcode, devname, version):
for cmd in cmd_wiz510ssl:
cmd_list.append([cmd, ""])
elif 'WIZ5XXSR' in devname:
for cmd in cmd_wiz5xxsr:
# 버전이 1.0.8 이상인 경우에만 "PO" 추가 #36
temp_cmd_wiz5xxsr = (cmd_wiz5xxsr + ["PO"]) if version_compare("1.0.8", version) <= 0 else cmd_wiz5xxsr
for cmd in temp_cmd_wiz5xxsr:
cmd_list.append([cmd, ""])
# Commands for E-SAVE
#if 'E-SAVE' in devname:
Expand Down
19 changes: 17 additions & 2 deletions main_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from PyQt5.QtWidgets import QApplication, QMainWindow, QLineEdit, QMessageBox, QTableWidgetItem, QFileDialog, QMenu, QAction, QProgressBar, QInputDialog
import ifaddr

VERSION = 'V1.5.5'
VERSION = 'V1.5.5.1' # github 이슈 #36 수정


def resource_path(relative_path):
Expand Down Expand Up @@ -499,6 +499,16 @@ def gpio_check(self):

# Object config for some Devices or F/W version
def object_config_for_device(self):
# WIZ5XX 가 아니면 modbus 는 사용 불가 #36
print(f"model={self.curr_dev},ver={self.curr_ver},version compare={version_compare(self.curr_ver, '1.0.8')}")
if 'WIZ5XX' not in self.curr_dev:
self.modbus_protocol.setEnabled(False)
# WIZ5XX 도 v1.0.8 미만은 사용 불가 #36
elif version_compare(self.curr_ver, '1.0.8') < 0:
self.modbus_protocol.setEnabled(False)
# WIZ5XX v1.0.8 이상은 modbus 사용 가능 #36
else:
self.modbus_protocol.setEnabled(True)
if 'WIZ750' in self.curr_dev:
if version_compare('1.2.0', self.curr_ver) <= 0:
# setcmd['TR'] = self.tcp_timeout.text()
Expand Down Expand Up @@ -1620,7 +1630,9 @@ def get_object_value(self):
setcmd['PR'] = str(self.ch1_parity.currentIndex())
setcmd['SB'] = str(self.ch1_stopbit.currentIndex())
setcmd['FL'] = str(self.ch1_flow.currentIndex())
if 'WIZ5XXSR' in self.curr_dev:
# 문맥으로 보면 modbus_protocol.isEnabled() 로 처리하는게 맞지만 항상 False 가 나와서 모델&버전 비교로 대체 #36
if 'WIZ5XXSR' in self.curr_dev and version_compare("1.0.8", self.curr_ver) <= 0:
print(f"set PO valid, self.curr_dev={self.curr_dev}, self.curr_ver={self.curr_ver}")
setcmd['PO'] = str(self.modbus_protocol.currentIndex())
setcmd['PT'] = self.ch1_pack_time.text()
setcmd['PS'] = self.ch1_pack_size.text()
Expand Down Expand Up @@ -1876,6 +1888,9 @@ def get_setting_result(self, resp_len):
def selected_devinfo(self):
# 선택된 장치 정보 get
for currentItem in self.list_device.selectedItems():
_dev_name = currentItem.text()
# currentItem = <class 'PyQt5.QtWidgets.QTableWidgetItem'>
# 현재 0번 열은 맥주소이고 1번 열은 장치명
if currentItem.column() == 0:
self.curr_mac = currentItem.text()
self.curr_ver = self.dev_data[self.curr_mac][1]
Expand Down

0 comments on commit c45bc60

Please sign in to comment.