Skip to content

Commit

Permalink
Extra /n space problem fix, flow control button activated, parity but…
Browse files Browse the repository at this point in the history
…ton activated, clear cache button added
  • Loading branch information
Mehmet Aksoy committed Jul 25, 2024
1 parent 4685441 commit 64216c9
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 13 deletions.
Binary file modified src/__pycache__/ui_main.cpython-311.pyc
Binary file not shown.
55 changes: 51 additions & 4 deletions src/ui_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def __init__(self):
self.saved_command_3.clicked.connect(self.move_command3_to_text)
self.saved_command_4.clicked.connect(self.move_command4_to_text)

self.clear_buffer_button.clicked.connect(self.clear_buffer)

self.port_comboBox.addItems(PORTS)

self.send_data_button.clicked.connect(
Expand Down Expand Up @@ -207,16 +209,50 @@ def establish_serial_communication(self):
length = self.len_comboBox.currentText()
parity = self.parity_comboBox.currentText()
stopbits = self.bit_comboBox.currentText()
flowControl = self.flow_comboBox.currentText()

if parity == "None":
_parity = serial.PARITY_NONE
elif parity == "Even":
_parity = serial.PARITY_EVEN
elif parity == "Odd":
_parity = serial.PARITY_ODD
elif parity == "Mark":
_parity = serial.PARITY_MARK
elif parity == "Space":
_parity = serial.PARITY_SPACE
else:
self.print_message_on_screen("Parity Error!")

if flowControl == "None":
_xonxoff = False
_rtscts = False
_dsrdtr = False
elif flowControl == "Xon/Xoff":
_xonxoff = True
_rtscts = False
_dsrdtr = False
elif flowControl == "RTS/CTS":
_xonxoff = False
_rtscts = True
_dsrdtr = False
elif flowControl == "DSR/DTR":
_xonxoff = False
_rtscts = False
_dsrdtr = True
else:
self.print_message_on_screen("Flow Control Error!")

global SERIAL_INFO
SERIAL_INFO = serial.Serial(port=str(port),
baudrate=int(baudrate, base=10),
timeout=float(timeout),
bytesize=int(length, base=10),
parity=serial.PARITY_NONE, #TODO: Fix this
parity=_parity,
stopbits=float(stopbits),
xonxoff = False,
rtscts = False,
dsrdtr = False,
xonxoff = _xonxoff,
rtscts = _rtscts,
dsrdtr = _dsrdtr,
)
if SERIAL_INFO.isOpen() == False:
SERIAL_INFO.open()
Expand Down Expand Up @@ -256,6 +292,7 @@ def start_loop(self):
self.worker.finished.connect(self.worker.deleteLater)
# have thread mark itself for deletion
self.thread.finished.connect(self.thread.deleteLater)
# start the thread
self.thread.start()
except RuntimeError:
self.print_message_on_screen("Exception in Worker Thread!")
Expand All @@ -264,6 +301,11 @@ def stop_loop(self):
""" Stop the loop """
self.worker.working = False
self.options_textEdit.setText('Stopped!')

def clear_buffer(self):
""" Clear the buffer """
self.data_textEdit.clear()
self.send_data_text.clear()

def read_data_from_thread(self, serial_data):
""" Write the result to the text edit box"""
Expand All @@ -281,11 +323,13 @@ def read_data_from_thread(self, serial_data):
self.port_comboBox.setEnabled(False)
self.parity_comboBox.setEnabled(False)
self.bit_comboBox.setEnabled(False)
self.flow_comboBox.setEnabled(False)
self.start_button.setEnabled(False)

self.options_textEdit.setText('Data Gathering...')
self.status_label.setText("CONNECTED!")
self.status_label.setStyleSheet('color: green')
serial_data = serial_data.replace('\n', '')
self.data_textEdit.insertPlainText("{}".format(serial_data))

def on_save_txt_button_clicked(self):
Expand All @@ -299,12 +343,15 @@ def on_end_button_clicked(self):
""" Stop the process """
is_serial_port_established = False
self.options_textEdit.setText('Stopped!')
self.status_label.setText("DISCONNECTED!")
self.status_label.setStyleSheet('color: red')
self.timeout_comboBox.setEnabled(True)
self.baudrate_comboBox.setEnabled(True)
self.len_comboBox.setEnabled(True)
self.port_comboBox.setEnabled(True)
self.parity_comboBox.setEnabled(True)
self.bit_comboBox.setEnabled(True)
self.flow_comboBox.setEnabled(True)
self.start_button.setEnabled(True)

def on_send_data_button_clicked(self):
Expand Down
31 changes: 22 additions & 9 deletions ui/main_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@
<widget class="QTextEdit" name="send_data_text">
<property name="geometry">
<rect>
<x>70</x>
<x>60</x>
<y>520</y>
<width>491</width>
<width>501</width>
<height>31</height>
</rect>
</property>
Expand Down Expand Up @@ -294,9 +294,9 @@
<widget class="QLabel" name="label_22">
<property name="geometry">
<rect>
<x>0</x>
<x>10</x>
<y>520</y>
<width>71</width>
<width>41</width>
<height>31</height>
</rect>
</property>
Expand Down Expand Up @@ -537,10 +537,10 @@
</widget>
</item>
<item row="6" column="1">
<widget class="QComboBox" name="bit_comboBox_2">
<widget class="QComboBox" name="flow_comboBox">
<item>
<property name="text">
<string>none</string>
<string>None</string>
</property>
</item>
<item>
Expand Down Expand Up @@ -593,7 +593,7 @@
<rect>
<x>570</x>
<y>510</y>
<width>151</width>
<width>158</width>
<height>41</height>
</rect>
</property>
Expand All @@ -607,7 +607,7 @@
</font>
</property>
<property name="text">
<string>SEND</string>
<string>SEND</string>
</property>
</widget>
</item>
Expand All @@ -620,6 +620,19 @@
</item>
</layout>
</widget>
<widget class="QPushButton" name="clear_buffer_button">
<property name="geometry">
<rect>
<x>830</x>
<y>530</y>
<width>91</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Clear Buffer ⎚</string>
</property>
</widget>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
Expand Down Expand Up @@ -669,7 +682,7 @@ p, li { white-space: pre-wrap; }
<rect>
<x>90</x>
<y>110</y>
<width>281</width>
<width>331</width>
<height>16</height>
</rect>
</property>
Expand Down

0 comments on commit 64216c9

Please sign in to comment.