Skip to content

Commit

Permalink
Merge branch 'refactor/优化器件列表获取方式'
Browse files Browse the repository at this point in the history
  • Loading branch information
tianxiaoMCU committed Jan 3, 2024
2 parents b480b4d + 07ae120 commit f3050db
Show file tree
Hide file tree
Showing 9 changed files with 5,287 additions and 1,051 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ build/main_window/base_library.zip
build/main_window/main_window.exe.manifest
*.pkg
*.pyz
*.txt
*.html
dist/rtt2uart_v1.0.0.exe
main_window.spec
Expand Down
6,072 changes: 5,141 additions & 931 deletions JLinkDevicesBuildIn.xml

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,25 @@
![serialcomtool.png](./picture/serialcomtool.png)

## Update the device lists
> Note: Starting with version v2.0.0, there is no need to update ***JLinkDevicesBuildIn.xml*** file manually!
if can't find the device you want, follow the picture below and replace the ***JLinkDevicesBuildIn.xml*** file in the path of this tool.

![exportdevicelist.png](./picture/exportdevicelist.png)

## Package the program with pyinstaller

Open *cmd.exe* in the project path and input follow command `pyinstaller -F -w -i ./swap_horiz_16px.ico main_window.py`
Open *cmd.exe* in the project path and input follow command `pyinstaller --onefile --name rtt2uart --noconsole -i .\swap_horiz_16px.ico .\main_window.py`

## Develop
### Creat UI python class
execute the following command in a terminal
```
pyside6-uic .\rtt2uart.ui -o .\ui_rtt2uart.py
pyside6-uic .\sel_device.ui -o .\ui_sel_device.py
```
### Creat source file python class
execute the following command in a terminal
```
pyside6-rcc .\icons.qrc -o .\rc_icons.py
```
92 changes: 55 additions & 37 deletions main_window.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from pickle import NONE
import sys
from PySide2.QtWidgets import QApplication, QMainWindow, QDialog, QHeaderView, QAbstractItemView, QMessageBox, QSystemTrayIcon, QMenu, QAction
from PySide2.QtCore import QFile, QAbstractTableModel
from PySide2 import QtGui
from PySide2 import QtCore
from PySide2.QtGui import QFont, QIcon
from PySide2.QtNetwork import QLocalSocket, QLocalServer
from PySide6.QtWidgets import QApplication, QMainWindow, QDialog, QHeaderView, QAbstractItemView, QMessageBox, QSystemTrayIcon, QMenu
from PySide6.QtCore import QFile, QAbstractTableModel
from PySide6 import QtGui
from PySide6 import QtCore
from PySide6.QtGui import QFont, QIcon, QAction
from PySide6.QtNetwork import QLocalSocket, QLocalServer
from ui_rtt2uart import Ui_dialog
from ui_sel_device import Ui_Dialog
import rc_icons
Expand All @@ -19,6 +19,7 @@
import logging
import pickle
import os
import subprocess

logging.basicConfig(level=logging.NOTSET,
format='%(asctime)s - [%(levelname)s] (%(filename)s:%(lineno)d) - %(message)s')
Expand Down Expand Up @@ -77,7 +78,6 @@ def __init__(self):
self.devices_list = self.parse_jlink_devices_list_file(filepath)

if len(self.devices_list):

# 从headdata中取出数据,放入到模型中
headdata = ["Manufacturer", "Device", "Core",
"NumCores", "Flash Size", "RAM Size"]
Expand All @@ -90,38 +90,23 @@ def __init__(self):
# font = QFont("Courier New", 9)
# self.ui.tableView.setFont(font)
# set column width to fit contents (set font first!)
self.ui.tableView.resizeColumnsToContents()
self.ui.tableView.resizeRowsToContents()
# Disable auto-resizing
self.ui.tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Fixed)
self.ui.tableView.verticalHeader().setSectionResizeMode(QHeaderView.Fixed)

# Set fixed column widths (adjust the values based on your needs)
self.ui.tableView.setColumnWidth(0, 100) # Manufacturer
self.ui.tableView.setColumnWidth(1, 280) # Device
self.ui.tableView.setColumnWidth(2, 140) # Core
self.ui.tableView.setColumnWidth(3, 70) # NumCores
self.ui.tableView.setColumnWidth(4, 70) # Flash Size
self.ui.tableView.setColumnWidth(5, 70) # RAM Size
self.ui.tableView.setSelectionBehavior(
QAbstractItemView.SelectRows)

self.ui.tableView.clicked.connect(self.reflash_selete_device)

def get_jlink_devices_list_file(self):
'''
lib_jlink = pylink.Library()
path = ctypes_util.find_library(lib_jlink._sdk)
if path is None:
# Couldn't find it the standard way. Fallback to the non-standard
# way of finding the J-Link library. These methods are operating
# system specific.
if lib_jlink._windows or lib_jlink._cygwin:
path = next(lib_jlink.find_library_windows(), None)
elif sys.platform.startswith('linux'):
path = next(lib_jlink.find_library_linux(), None)
elif sys.platform.startswith('darwin'):
path = next(lib_jlink.find_library_darwin(), None)
if path is not None:
path = path.replace(
lib_jlink.get_appropriate_windows_sdk_name()+".dll", "JLinkDevices.xml")
else:
path = ''
else:
path = ''
'''
if os.path.exists(r'JLinkDevicesBuildIn.xml') == True:
return os.path.abspath('JLinkDevicesBuildIn.xml')
else:
Expand Down Expand Up @@ -266,6 +251,39 @@ def __init__(self):
self.ui.radioButton_existing.clicked.connect(
self.existing_session_selete_slot)

try:
self.jlink = pylink.JLink()
except:
logger.error('Find jlink dll failed', exc_info=True)
raise Exception("Find jlink dll failed !")

try:
# 导出器件列表文件
if self.jlink._library._path is not None:
path_env = os.path.dirname(self.jlink._library._path)
env = os.environ

if self.jlink._library._windows or self.jlink._library._cygwin:
jlink_env = {'PATH': path_env}
env.update(jlink_env)

cmd = 'JLink.exe -CommandFile JLinkCommandFile.jlink'

startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE

subprocess.run(cmd, check=True, startupinfo=startupinfo, creationflags=subprocess.CREATE_NEW_CONSOLE)
elif sys.platform.startswith('linux'):
jlink_env = {}
cmd = 'JLinkExe -CommandFile JLinkCommandFile.jlink'
elif sys.platform.startswith('darwin'):
jlink_env = {}
cmd = 'JLinkExe -CommandFile JLinkCommandFile.jlink'

except Exception as e:
logging.error(f'can not export devices xml file, error info: {e}')

def closeEvent(self, e):
if self.rtt2uart is not None and self.start_state == True:
self.rtt2uart.stop()
Expand Down Expand Up @@ -332,7 +350,7 @@ def start(self):
else:
connect_para = None

self.rtt2uart = rtt_to_serial(self.connect_type, connect_para, self.target_device, self.ui.comboBox_Port.currentText(
self.rtt2uart = rtt_to_serial(self.jlink, self.connect_type, connect_para, self.target_device, self.ui.comboBox_Port.currentText(
), self.ui.comboBox_baudrate.currentText(), device_interface, speed_list[self.ui.comboBox_Speed.currentIndex()], self.ui.checkBox_resettarget.isChecked())

self.rtt2uart.start()
Expand Down Expand Up @@ -366,7 +384,7 @@ def start(self):

def target_device_selete(self):
device_ui = DeviceSeleteDialog()
device_ui.exec_()
device_ui.exec()
self.target_device = device_ui.get_target_device()

if self.target_device not in self.settings['device']:
Expand Down Expand Up @@ -443,9 +461,9 @@ def existing_session_selete_slot(self):

try:
window = MainWindow()
window.setWindowTitle("RTT2UART Control Panel V1.5.0")
window.setWindowTitle("RTT2UART Control Panel V2.0.0")
window.show()

sys.exit(app.exec_())
sys.exit(app.exec())
finally:
localServer.close()
34 changes: 17 additions & 17 deletions rc_icons.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
# Resource object code (Python 3)
# Created by: object code
# Created by: The Resource Compiler for Qt version 5.15.1
# Created by: The Resource Compiler for Qt version 6.6.1
# WARNING! All changes made in this file will be lost!

from PySide2 import QtCore
from PySide6 import QtCore

qt_resource_data = b"\
\x00\x00\x00\xf6\
\x00\x00\x00\xf7\
\x00\
\x00\x04~x\x9c\xb5\xd4A\x0e\xc1@\x14\xc6\xf17S\
\x00\x04~x\xda\xb5\xd4A\x0e\xc1@\x14\xc6\xf17S\
\x22\x12\x0b+[\x96.\xd1X \xb8\x888\x06\x11;\
'\xb0\xd1\x8d\x9dZ8\x01\x11+\xd7p\x08\x1b\xa9\x7f\
u\xc8\xa4:Q\xc1k~]\xcc\xcc\xf7f2M*\
\xa2x\xaaU\xe1\xdd\x90QA\xa4&\x22M0\xc4H\
2~\xaf\x82\xfc\xad\xf6\xebW\xdfd\xf3\xe6S\x99\x0a\
|xy\xfbY\xf3e\xcc\xb1B\x11\xda\xa2\xde\xe4\xe3\
\xf53\x5cq\xc6\x06\xa1\xa5\x15\xaf\xeb\x05\xed\xa7O\xf3\
\x87T\xfe\xd1\xc3u\xfe#\xe7>\x85\x89h+\xaa\x1b\
t<2>*v\x8f\xac\xfbc/\xaf\xb4\x18*\x7f\
9\xd0\xfe\xb2\xaf\xdbAW\xb3\xb6\x88\x15\xe6(;\xce\
p\xc7^\xf1\x5c\x0b\xa1e\x833\xae\x98\x99~\x99\xdf\
\xd1\xf4\xfe(o\x97\xc9+h\x8b\xf3\xfc\x8e|Z\xe6\
\xfd\xe5)G\xbf\x5cYW\xfeW\x15E\xdc9&\x90\
\xba\xe1I\xfc\xd3x\xd6\x18;\x5c\x8ch\x82i\x92\xbd\
\x01\xefp\xf4\xe9\
\xdb!\x93\xeaDE\xbc\xe6\xd7\xc5t\xbe7\x93iZ\
\x11\xc5U\xaf\x0b\xf7\x96LJ\x22\x0d\x11i\x83!F\
\xd2\xf1\xa4J\xf2\xb7:n\xdf\xfd\x92-\x9a\xcfdj\
\xf0\xe1\x15\xedg=\xafb\x89\x0d\xca\xd0\x16\xf5!\x1f\
\xcf_\xe0\x8e+v\x08-\x9dx\xde \xe8\xbe|\x9b\
?e\xf2\xcf\x1e\xae\xfd\x9f\xd9\xf7%LE{Q\xfd\
\xa0\xe7\x91\xf1Q\xb3{\xe4\x9d\x1fky\x95\xd5X\xf9\
\xeb\x91\xf6\xd7C\xdd\x0d\xfa\x9a\xb9el\xb0D\xd5\xb1\
\x87\x04k\xc5\xcf:\x08-;\x5cq\xc7\xc2\xf4\xcb}\
\x8f\xa6\xf7Wy\xbbL^A[\x9c\xfbw\xe4\xb3r\
\xcf\xafH9\xfa\x15\xfe>~\xc9~\xaa(\xe2\xcc1\
\x834\x0d/\xf9i\xbcj\x8a\x03nF4\xc3<\xcd\
>\x00\xefp\xf4\xe9\
"

qt_resource_name = b"\
Expand Down
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pylink_square==1.2.0
pyserial==3.5
PySide6==6.6.1
PySide6==6.6.1
PySide6_Addons==6.6.1
PySide6_Essentials==6.6.1
shiboken6==6.6.1
11 changes: 3 additions & 8 deletions rtt2uart.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


class rtt_to_serial():
def __init__(self, connect_inf='USB', connect_para=None, device=None, port=None, baudrate=115200, interface=pylink.enums.JLinkInterfaces.SWD, speed=12000, reset=False):
def __init__(self, jlink, connect_inf='USB', connect_para=None, device=None, port=None, baudrate=115200, interface=pylink.enums.JLinkInterfaces.SWD, speed=12000, reset=False):
# jlink接入方式
self._connect_inf = connect_inf
# jlink接入参数
Expand All @@ -29,16 +29,11 @@ def __init__(self, connect_inf='USB', connect_para=None, device=None, port=None,
self.port = port
self.baudrate = baudrate

self.jlink = jlink

# 线程
self._write_lock = threading.Lock()

if self._connect_inf == 'USB':
try:
self.jlink = pylink.JLink()
except:
logger.error('Find jlink dll failed', exc_info=True)
raise

try:
self.serial = serial.Serial()
except:
Expand Down
75 changes: 32 additions & 43 deletions ui_rtt2uart.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
# -*- coding: utf-8 -*-

################################################################################
# Form generated from reading UI file 'rtt2uart.ui'
## Form generated from reading UI file 'rtt2uart.ui'
##
# Created by: Qt User Interface Compiler version 5.15.2
## Created by: Qt User Interface Compiler version 6.6.1
##
# WARNING! All changes made in this file will be lost when recompiling UI file!
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *

from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QCheckBox, QComboBox, QDialog,
QFrame, QGroupBox, QLabel, QLineEdit,
QPushButton, QRadioButton, QSizePolicy, QWidget)

class Ui_dialog(object):
def setupUi(self, dialog):
Expand All @@ -25,11 +31,10 @@ def setupUi(self, dialog):
self.pushButton_Start.setObjectName(u"pushButton_Start")
self.pushButton_Start.setGeometry(QRect(160, 300, 81, 41))
font = QFont()
font.setFamily(u"\u5fae\u8f6f\u96c5\u9ed1")
font.setFamilies([u"\u5fae\u8f6f\u96c5\u9ed1"])
font.setPointSize(13)
font.setBold(True)
font.setUnderline(False)
font.setWeight(75)
font.setStrikeOut(False)
self.pushButton_Start.setFont(font)
self.pushButton_Start.setCheckable(True)
Expand All @@ -56,8 +61,7 @@ def setupUi(self, dialog):
self.comboBox_Device.setObjectName(u"comboBox_Device")
self.comboBox_Device.setGeometry(QRect(10, 20, 321, 22))
self.pushButton_Selete_Device = QPushButton(self.groupBox_2)
self.pushButton_Selete_Device.setObjectName(
u"pushButton_Selete_Device")
self.pushButton_Selete_Device.setObjectName(u"pushButton_Selete_Device")
self.pushButton_Selete_Device.setGeometry(QRect(340, 20, 31, 23))
self.groupBox_UART = QGroupBox(dialog)
self.groupBox_UART.setObjectName(u"groupBox_UART")
Expand Down Expand Up @@ -113,37 +117,22 @@ def setupUi(self, dialog):
# setupUi

def retranslateUi(self, dialog):
dialog.setWindowTitle(QCoreApplication.translate(
"dialog", u"RTT2UART Control Panel", None))
self.pushButton_Start.setText(
QCoreApplication.translate("dialog", u"Start", None))
self.groupBox.setTitle(QCoreApplication.translate(
"dialog", u"Target Interface And Speed", None))
dialog.setWindowTitle(QCoreApplication.translate("dialog", u"RTT2UART Control Panel", None))
self.pushButton_Start.setText(QCoreApplication.translate("dialog", u"Start", None))
self.groupBox.setTitle(QCoreApplication.translate("dialog", u"Target Interface And Speed", None))
self.comboBox_Speed.setCurrentText("")
self.groupBox_2.setTitle(QCoreApplication.translate(
"dialog", u"Specify Target Device", None))
self.pushButton_Selete_Device.setText(
QCoreApplication.translate("dialog", u"...", None))
self.groupBox_UART.setTitle(
QCoreApplication.translate("dialog", u"UART Config", None))
self.label.setText(QCoreApplication.translate(
"dialog", u"Port:", None))
self.label_2.setText(QCoreApplication.translate(
"dialog", u"Baud rate:", None))
self.pushButton_scan.setText(
QCoreApplication.translate("dialog", u"Scan", None))
self.checkBox_resettarget.setText(
QCoreApplication.translate("dialog", u"Reset target", None))
self.groupBox_3.setTitle(QCoreApplication.translate(
"dialog", u"Connection to J-Link", None))
self.radioButton_usb.setText(
QCoreApplication.translate("dialog", u"USB", None))
self.radioButton_existing.setText(
QCoreApplication.translate("dialog", u"Existing Session", None))
self.radioButton_tcpip.setText(
QCoreApplication.translate("dialog", u"TCP/IP", None))
self.checkBox_serialno.setText(
QCoreApplication.translate("dialog", u"Serial NO", None))
self.checkBox__auto.setText(QCoreApplication.translate(
"dialog", u"Auto Reconnect", None))
self.groupBox_2.setTitle(QCoreApplication.translate("dialog", u"Specify Target Device", None))
self.pushButton_Selete_Device.setText(QCoreApplication.translate("dialog", u"...", None))
self.groupBox_UART.setTitle(QCoreApplication.translate("dialog", u"UART Config", None))
self.label.setText(QCoreApplication.translate("dialog", u"Port:", None))
self.label_2.setText(QCoreApplication.translate("dialog", u"Baud rate:", None))
self.pushButton_scan.setText(QCoreApplication.translate("dialog", u"Scan", None))
self.checkBox_resettarget.setText(QCoreApplication.translate("dialog", u"Reset target", None))
self.groupBox_3.setTitle(QCoreApplication.translate("dialog", u"Connection to J-Link", None))
self.radioButton_usb.setText(QCoreApplication.translate("dialog", u"USB", None))
self.radioButton_existing.setText(QCoreApplication.translate("dialog", u"Existing Session", None))
self.radioButton_tcpip.setText(QCoreApplication.translate("dialog", u"TCP/IP", None))
self.checkBox_serialno.setText(QCoreApplication.translate("dialog", u"Serial NO", None))
self.checkBox__auto.setText(QCoreApplication.translate("dialog", u"Auto Reconnect", None))
# retranslateUi

Loading

0 comments on commit f3050db

Please sign in to comment.