@@ -127,6 +127,8 @@ def __init__(self):
127
127
self .saved_command_3 .clicked .connect (self .move_command3_to_text )
128
128
self .saved_command_4 .clicked .connect (self .move_command4_to_text )
129
129
130
+ self .clear_buffer_button .clicked .connect (self .clear_buffer )
131
+
130
132
self .port_comboBox .addItems (PORTS )
131
133
132
134
self .send_data_button .clicked .connect (
@@ -207,16 +209,50 @@ def establish_serial_communication(self):
207
209
length = self .len_comboBox .currentText ()
208
210
parity = self .parity_comboBox .currentText ()
209
211
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
+
210
246
global SERIAL_INFO
211
247
SERIAL_INFO = serial .Serial (port = str (port ),
212
248
baudrate = int (baudrate , base = 10 ),
213
249
timeout = float (timeout ),
214
250
bytesize = int (length , base = 10 ),
215
- parity = serial . PARITY_NONE , #TODO: Fix this
251
+ parity = _parity ,
216
252
stopbits = float (stopbits ),
217
- xonxoff = False ,
218
- rtscts = False ,
219
- dsrdtr = False ,
253
+ xonxoff = _xonxoff ,
254
+ rtscts = _rtscts ,
255
+ dsrdtr = _dsrdtr ,
220
256
)
221
257
if SERIAL_INFO .isOpen () == False :
222
258
SERIAL_INFO .open ()
@@ -256,6 +292,7 @@ def start_loop(self):
256
292
self .worker .finished .connect (self .worker .deleteLater )
257
293
# have thread mark itself for deletion
258
294
self .thread .finished .connect (self .thread .deleteLater )
295
+ # start the thread
259
296
self .thread .start ()
260
297
except RuntimeError :
261
298
self .print_message_on_screen ("Exception in Worker Thread!" )
@@ -264,6 +301,11 @@ def stop_loop(self):
264
301
""" Stop the loop """
265
302
self .worker .working = False
266
303
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 ()
267
309
268
310
def read_data_from_thread (self , serial_data ):
269
311
""" Write the result to the text edit box"""
@@ -281,11 +323,13 @@ def read_data_from_thread(self, serial_data):
281
323
self .port_comboBox .setEnabled (False )
282
324
self .parity_comboBox .setEnabled (False )
283
325
self .bit_comboBox .setEnabled (False )
326
+ self .flow_comboBox .setEnabled (False )
284
327
self .start_button .setEnabled (False )
285
328
286
329
self .options_textEdit .setText ('Data Gathering...' )
287
330
self .status_label .setText ("CONNECTED!" )
288
331
self .status_label .setStyleSheet ('color: green' )
332
+ serial_data = serial_data .replace ('\n ' , '' )
289
333
self .data_textEdit .insertPlainText ("{}" .format (serial_data ))
290
334
291
335
def on_save_txt_button_clicked (self ):
@@ -299,12 +343,15 @@ def on_end_button_clicked(self):
299
343
""" Stop the process """
300
344
is_serial_port_established = False
301
345
self .options_textEdit .setText ('Stopped!' )
346
+ self .status_label .setText ("DISCONNECTED!" )
347
+ self .status_label .setStyleSheet ('color: red' )
302
348
self .timeout_comboBox .setEnabled (True )
303
349
self .baudrate_comboBox .setEnabled (True )
304
350
self .len_comboBox .setEnabled (True )
305
351
self .port_comboBox .setEnabled (True )
306
352
self .parity_comboBox .setEnabled (True )
307
353
self .bit_comboBox .setEnabled (True )
354
+ self .flow_comboBox .setEnabled (True )
308
355
self .start_button .setEnabled (True )
309
356
310
357
def on_send_data_button_clicked (self ):
0 commit comments