diff --git a/car/__init__.py b/car/__init__.py
index 4be82f0..bb159da 100644
--- a/car/__init__.py
+++ b/car/__init__.py
@@ -1,3 +1,4 @@
from .motion import motion, track
from .util import *
-#from .guiConnector import *
\ No newline at end of file
+#from .guiConnector import *
+from .canListener import canFrameAppender
\ No newline at end of file
diff --git a/car/canListener.py b/car/canListener.py
new file mode 100644
index 0000000..bbd79c8
--- /dev/null
+++ b/car/canListener.py
@@ -0,0 +1,13 @@
+from can import Listener
+from PyQt5.QtCore import pyqtSignal, QObject
+
+class canFrameAppender(Listener, QObject):
+
+ frameReceived = pyqtSignal(str)
+
+ def __init__(self,appendFunction):
+ super().__init__()
+ self.frameReceived.connect(appendFunction)
+
+ def on_message_received(self,msg):
+ self.frameReceived.emit("ID: {}\tDLC: {}\t{}".format(msg.arbitration_id,msg.dlc,msg.data.hex()))
diff --git a/gui/mainWindow.py b/gui/mainWindow.py
index 28b920c..2643599 100644
--- a/gui/mainWindow.py
+++ b/gui/mainWindow.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
-# Form implementation generated from reading ui file 'mainWindow.ui'
+# Form implementation generated from reading ui file 'gui\mainWindow.ui'
#
# Created by: PyQt5 UI code generator 5.13.0
#
@@ -13,13 +13,13 @@
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
- MainWindow.resize(714, 433)
+ MainWindow.resize(1020, 433)
MainWindow.setLocale(QtCore.QLocale(QtCore.QLocale.English, QtCore.QLocale.UnitedKingdom))
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setLocale(QtCore.QLocale(QtCore.QLocale.English, QtCore.QLocale.UnitedKingdom))
self.centralwidget.setObjectName("centralwidget")
self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
- self.tabWidget.setGeometry(QtCore.QRect(10, 10, 671, 341))
+ self.tabWidget.setGeometry(QtCore.QRect(10, 10, 971, 341))
self.tabWidget.setToolTipDuration(0)
self.tabWidget.setObjectName("tabWidget")
self.Connection = QtWidgets.QWidget()
@@ -37,9 +37,16 @@ def setupUi(self, MainWindow):
self.connectPort.setGeometry(QtCore.QRect(10, 270, 211, 23))
self.connectPort.setCheckable(True)
self.connectPort.setObjectName("connectPort")
- self.plainTextEdit = QtWidgets.QPlainTextEdit(self.Connection)
- self.plainTextEdit.setGeometry(QtCore.QRect(243, 20, 411, 291))
- self.plainTextEdit.setObjectName("plainTextEdit")
+ self.canInterfaceTypes = QtWidgets.QComboBox(self.serialSettings)
+ self.canInterfaceTypes.setGeometry(QtCore.QRect(10, 80, 211, 22))
+ self.canInterfaceTypes.setObjectName("canInterfaceTypes")
+ self.canInterfaceTypes.addItem("")
+ self.canInterfaceTypes.setItemText(0, "slcan")
+ self.canInterfaceTypes.addItem("")
+ self.canInterfaceTypes.setItemText(1, "serial")
+ self.canReceived = QtWidgets.QPlainTextEdit(self.Connection)
+ self.canReceived.setGeometry(QtCore.QRect(243, 20, 711, 291))
+ self.canReceived.setObjectName("canReceived")
self.tabWidget.addTab(self.Connection, "")
self.Simulation = QtWidgets.QWidget()
self.Simulation.setObjectName("Simulation")
@@ -105,7 +112,7 @@ def setupUi(self, MainWindow):
self.tabWidget.addTab(self.Settings, "")
MainWindow.setCentralWidget(self.centralwidget)
self.menuBar = QtWidgets.QMenuBar(MainWindow)
- self.menuBar.setGeometry(QtCore.QRect(0, 0, 714, 21))
+ self.menuBar.setGeometry(QtCore.QRect(0, 0, 1020, 21))
self.menuBar.setObjectName("menuBar")
self.menuMain = QtWidgets.QMenu(self.menuBar)
self.menuMain.setObjectName("menuMain")
diff --git a/gui/mainWindow.ui b/gui/mainWindow.ui
index d2deba5..8fee483 100644
--- a/gui/mainWindow.ui
+++ b/gui/mainWindow.ui
@@ -6,7 +6,7 @@
0
0
- 714
+ 1020
433
@@ -25,7 +25,7 @@
10
10
- 671
+ 971
341
@@ -90,13 +90,33 @@
true
+
+
+
+ 10
+ 80
+ 211
+ 22
+
+
+ -
+
+ slcan
+
+
+ -
+
+ serial
+
+
+
-
+
243
20
- 411
+ 711
291
@@ -247,7 +267,7 @@
0
0
- 714
+ 1020
21
diff --git a/lang/carSim_pl_PL.qm b/lang/carSim_pl_PL.qm
index 78c457f..9d35135 100644
Binary files a/lang/carSim_pl_PL.qm and b/lang/carSim_pl_PL.qm differ
diff --git a/lang/carSim_pl_PL.ts b/lang/carSim_pl_PL.ts
index aedec40..f4f237d 100644
--- a/lang/carSim_pl_PL.ts
+++ b/lang/carSim_pl_PL.ts
@@ -42,27 +42,27 @@ p, li { white-space: pre-wrap; }
Dialog
-
+
Błąd
-
+
Zapisz plik ustawień
-
+
Pliki konfiguracyjne (*.json)
-
+
Wszystkie pliki (*.*)
-
+
Otwórz plik ustawień
@@ -75,62 +75,62 @@ p, li { white-space: pre-wrap; }
Symulator
-
+
Symulacja
-
+
Położenie
-
+
Paliwo
-
+
Prędkość
-
+
Czas
-
+
Wykonaj krok &symulacji!
-
+
Silnik
-
+
Główne
-
+
O aplikacji
-
+
Zamknij
-
+
Wczytaj ustawienia
-
+
Zapisz ustawienia
@@ -150,14 +150,24 @@ p, li { white-space: pre-wrap; }
Odśwież
-
+
Ustawienia
-
+
Język
+
+
+
+ Połącz
+
+
+
+
+ Rozłącz
+
diff --git a/main.py b/main.py
index 17350ab..541ee01 100644
--- a/main.py
+++ b/main.py
@@ -90,19 +90,33 @@ def on_actionImport_Settings_triggered(self):
def on_refreshAvailablePorts_clicked(self):
ports = serial.tools.list_ports.comports()
for port, desc, hwid in sorted(ports):
- self.availablePorts.addItem("{}: {}".format(port, desc))
+ self.availablePorts.addItem(desc,port)
+
+
@pyqtSlot(bool)
def on_connectPort_clicked(self, state):
if state:
- self.connectPort.setText(_translate("Main Window", "Disconnect"))
- self.__canbus = can.interface.Bus(bustype='slcan', channel="COM3")
- tx_msg = can.Message(arbitration_id=0x01, data=[
- 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88])
- self.__canbus.send(tx_msg)
+ try:
+ self.__canbus = can.interface.Bus(bustype=self.canInterfaceTypes.currentText(), channel=self.availablePorts.currentData())
+ tx_msg = can.Message(arbitration_id=0x01, data=[
+ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88], is_extended_id=False)
+ self.__canbus.send(tx_msg)
+ self.__canbusNotifier=can.Notifier(self.__canbus,[car.canFrameAppender(self.canReceived.appendPlainText)])
+ except Exception as e:
+ self.connectPort.setChecked(False)
+ QtWidgets.QMessageBox.critical(self, _translate("Dialog", "Error"), str(e))
+ else:
+ self.connectPort.setText(_translate("MainWindow", "Disconnect"))
+ self.canInterfaceTypes.setEnabled(False)
+ self.availablePorts.setEnabled(False)
+
else:
- self.connectPort.setText(_translate("Main Window", "Connect"))
+ self.connectPort.setText(_translate("MainWindow", "Connect"))
+ self.__canbusNotifier.stop()
self.__canbus.shutdown()
+ self.canInterfaceTypes.setEnabled(True)
+ self.availablePorts.setEnabled(True)
if __name__ == "__main__":