Skip to content

Commit 64216c9

Browse files
author
Mehmet Aksoy
committed
Extra /n space problem fix, flow control button activated, parity button activated, clear cache button added
1 parent 4685441 commit 64216c9

File tree

3 files changed

+73
-13
lines changed

3 files changed

+73
-13
lines changed
1.73 KB
Binary file not shown.

src/ui_main.py

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ def __init__(self):
127127
self.saved_command_3.clicked.connect(self.move_command3_to_text)
128128
self.saved_command_4.clicked.connect(self.move_command4_to_text)
129129

130+
self.clear_buffer_button.clicked.connect(self.clear_buffer)
131+
130132
self.port_comboBox.addItems(PORTS)
131133

132134
self.send_data_button.clicked.connect(
@@ -207,16 +209,50 @@ def establish_serial_communication(self):
207209
length = self.len_comboBox.currentText()
208210
parity = self.parity_comboBox.currentText()
209211
stopbits = self.bit_comboBox.currentText()
212+
flowControl = self.flow_comboBox.currentText()
213+
214+
if parity == "None":
215+
_parity = serial.PARITY_NONE
216+
elif parity == "Even":
217+
_parity = serial.PARITY_EVEN
218+
elif parity == "Odd":
219+
_parity = serial.PARITY_ODD
220+
elif parity == "Mark":
221+
_parity = serial.PARITY_MARK
222+
elif parity == "Space":
223+
_parity = serial.PARITY_SPACE
224+
else:
225+
self.print_message_on_screen("Parity Error!")
226+
227+
if flowControl == "None":
228+
_xonxoff = False
229+
_rtscts = False
230+
_dsrdtr = False
231+
elif flowControl == "Xon/Xoff":
232+
_xonxoff = True
233+
_rtscts = False
234+
_dsrdtr = False
235+
elif flowControl == "RTS/CTS":
236+
_xonxoff = False
237+
_rtscts = True
238+
_dsrdtr = False
239+
elif flowControl == "DSR/DTR":
240+
_xonxoff = False
241+
_rtscts = False
242+
_dsrdtr = True
243+
else:
244+
self.print_message_on_screen("Flow Control Error!")
245+
210246
global SERIAL_INFO
211247
SERIAL_INFO = serial.Serial(port=str(port),
212248
baudrate=int(baudrate, base=10),
213249
timeout=float(timeout),
214250
bytesize=int(length, base=10),
215-
parity=serial.PARITY_NONE, #TODO: Fix this
251+
parity=_parity,
216252
stopbits=float(stopbits),
217-
xonxoff = False,
218-
rtscts = False,
219-
dsrdtr = False,
253+
xonxoff = _xonxoff,
254+
rtscts = _rtscts,
255+
dsrdtr = _dsrdtr,
220256
)
221257
if SERIAL_INFO.isOpen() == False:
222258
SERIAL_INFO.open()
@@ -256,6 +292,7 @@ def start_loop(self):
256292
self.worker.finished.connect(self.worker.deleteLater)
257293
# have thread mark itself for deletion
258294
self.thread.finished.connect(self.thread.deleteLater)
295+
# start the thread
259296
self.thread.start()
260297
except RuntimeError:
261298
self.print_message_on_screen("Exception in Worker Thread!")
@@ -264,6 +301,11 @@ def stop_loop(self):
264301
""" Stop the loop """
265302
self.worker.working = False
266303
self.options_textEdit.setText('Stopped!')
304+
305+
def clear_buffer(self):
306+
""" Clear the buffer """
307+
self.data_textEdit.clear()
308+
self.send_data_text.clear()
267309

268310
def read_data_from_thread(self, serial_data):
269311
""" Write the result to the text edit box"""
@@ -281,11 +323,13 @@ def read_data_from_thread(self, serial_data):
281323
self.port_comboBox.setEnabled(False)
282324
self.parity_comboBox.setEnabled(False)
283325
self.bit_comboBox.setEnabled(False)
326+
self.flow_comboBox.setEnabled(False)
284327
self.start_button.setEnabled(False)
285328

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

291335
def on_save_txt_button_clicked(self):
@@ -299,12 +343,15 @@ def on_end_button_clicked(self):
299343
""" Stop the process """
300344
is_serial_port_established = False
301345
self.options_textEdit.setText('Stopped!')
346+
self.status_label.setText("DISCONNECTED!")
347+
self.status_label.setStyleSheet('color: red')
302348
self.timeout_comboBox.setEnabled(True)
303349
self.baudrate_comboBox.setEnabled(True)
304350
self.len_comboBox.setEnabled(True)
305351
self.port_comboBox.setEnabled(True)
306352
self.parity_comboBox.setEnabled(True)
307353
self.bit_comboBox.setEnabled(True)
354+
self.flow_comboBox.setEnabled(True)
308355
self.start_button.setEnabled(True)
309356

310357
def on_send_data_button_clicked(self):

ui/main_window.ui

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,9 @@
239239
<widget class="QTextEdit" name="send_data_text">
240240
<property name="geometry">
241241
<rect>
242-
<x>70</x>
242+
<x>60</x>
243243
<y>520</y>
244-
<width>491</width>
244+
<width>501</width>
245245
<height>31</height>
246246
</rect>
247247
</property>
@@ -294,9 +294,9 @@
294294
<widget class="QLabel" name="label_22">
295295
<property name="geometry">
296296
<rect>
297-
<x>0</x>
297+
<x>10</x>
298298
<y>520</y>
299-
<width>71</width>
299+
<width>41</width>
300300
<height>31</height>
301301
</rect>
302302
</property>
@@ -537,10 +537,10 @@
537537
</widget>
538538
</item>
539539
<item row="6" column="1">
540-
<widget class="QComboBox" name="bit_comboBox_2">
540+
<widget class="QComboBox" name="flow_comboBox">
541541
<item>
542542
<property name="text">
543-
<string>none</string>
543+
<string>None</string>
544544
</property>
545545
</item>
546546
<item>
@@ -593,7 +593,7 @@
593593
<rect>
594594
<x>570</x>
595595
<y>510</y>
596-
<width>151</width>
596+
<width>158</width>
597597
<height>41</height>
598598
</rect>
599599
</property>
@@ -607,7 +607,7 @@
607607
</font>
608608
</property>
609609
<property name="text">
610-
<string>SEND</string>
610+
<string>SEND</string>
611611
</property>
612612
</widget>
613613
</item>
@@ -620,6 +620,19 @@
620620
</item>
621621
</layout>
622622
</widget>
623+
<widget class="QPushButton" name="clear_buffer_button">
624+
<property name="geometry">
625+
<rect>
626+
<x>830</x>
627+
<y>530</y>
628+
<width>91</width>
629+
<height>23</height>
630+
</rect>
631+
</property>
632+
<property name="text">
633+
<string>Clear Buffer ⎚</string>
634+
</property>
635+
</widget>
623636
</widget>
624637
<widget class="QWidget" name="tab_2">
625638
<attribute name="title">
@@ -669,7 +682,7 @@ p, li { white-space: pre-wrap; }
669682
<rect>
670683
<x>90</x>
671684
<y>110</y>
672-
<width>281</width>
685+
<width>331</width>
673686
<height>16</height>
674687
</rect>
675688
</property>

0 commit comments

Comments
 (0)