Skip to content

Commit

Permalink
2024.01 Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehmet Cagri Aksoy committed Feb 11, 2024
1 parent fec8cb5 commit 1876e23
Show file tree
Hide file tree
Showing 8 changed files with 631 additions and 391 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

![AFCOM Icon](https://github.com/mcagriaksoy/Serial-Communication-GUI-Program/blob/master/img/icon.png)

The AFCOM (aka Serial communication GUI program) tool is a software application that allows users to send and receive data via the serial port (COM port) of their computer.
Expand Down Expand Up @@ -39,7 +38,7 @@ Then the project can be run with:
pip install -r requirements.txt
```

![Project](https://github.com/mcagriaksoy/Serial-Communication-GUI-Program/blob/master/img/screenshot.jpg)
![Project SS](https://github.com/mcagriaksoy/Serial-Communication-GUI-Program/blob/master/img/ss.png)

If you encounter any problems while using the COM port tool, try these solutions:

Expand Down
Binary file removed img/screenshot.jpg
Binary file not shown.
Binary file added img/ss.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/Output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The AFCOM (aka Serial communication GUI program) tool is a software application that allows users to send and receive data via the serial port (COM port) of their computer. The tool can be used for various purposes, such as testing, debugging, or communicating with other devices that use the serial protocol.
Binary file modified src/__pycache__/ui_main.cpython-310.pyc
Binary file not shown.
Binary file modified src/__pycache__/ui_main.cpython-311.pyc
Binary file not shown.
105 changes: 90 additions & 15 deletions src/ui_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

try:
from PyQt6.QtCore import QObject, QThread, pyqtSignal, pyqtSlot
from PyQt6.QtWidgets import QApplication, QMainWindow, QMessageBox
from PyQt6.QtWidgets import QApplication, QMainWindow, QMessageBox, QInputDialog

if (PROGRAM_TYPE_DEBUG):
from PyQt6.uic import loadUi
Expand All @@ -39,6 +39,8 @@
SERIAL_INFO = serial.Serial()
PORTS = []

is_serial_port_established = False


def get_serial_port():
""" Lists serial port names
Expand Down Expand Up @@ -113,8 +115,83 @@ def __init__(self):

self.thread = None
self.worker = None

self.start_button.clicked.connect(self.start_loop)
self.comboBox_3.addItems(PORTS)
self.refresh_button.clicked.connect(self.refresh_port)

self.command_edit_1.clicked.connect(self.command1)
self.command_edit_2.clicked.connect(self.command2)
self.command_edit_3.clicked.connect(self.command3)
self.command_edit_4.clicked.connect(self.command4)

self.saved_command_1.clicked.connect(self.move_command1_to_text)
self.saved_command_2.clicked.connect(self.move_command2_to_text)
self.saved_command_3.clicked.connect(self.move_command3_to_text)
self.saved_command_4.clicked.connect(self.move_command4_to_text)

self.comboBox_6.addItems(PORTS)

self.send_data_button.clicked.connect(
self.on_send_data_button_clicked)

self.end_button.clicked.connect(self.on_end_button_clicked)

def command1(self):
""" Open the text input popup to save command for button 1 """
self.command_edit(1)

def command2(self):
""" Open the text input popup to save command for button 2 """
self.command_edit(2)

def command3(self):
""" Open the text input popup to save command for button 3 """
self.command_edit(3)

def command4(self):
""" Open the text input popup to save command for button 4 """
self.command_edit(4)

def command_edit(self, button_number):
""" Open the text input popup to save command """
# Create a text input popup
text, ok = QInputDialog.getText(
self, 'Set your command', 'Please enter the command that you want to save:')
if ok:
if button_number == 1:
self.saved_command_1.setText(str(text))
elif button_number == 2:
self.saved_command_2.setText(str(text))
elif button_number == 3:
self.saved_command_3.setText(str(text))
elif button_number == 4:
self.saved_command_4.setText(str(text))

def move_command1_to_text(self):
""" Move the saved command to the text box """
self.textEdit_5.setText(self.saved_command_1.text())
self.on_send_data_button_clicked()

def move_command2_to_text(self):
""" Move the saved command to the text box """
self.textEdit_5.setText(self.saved_command_2.text())
self.on_send_data_button_clicked()

def move_command3_to_text(self):
""" Move the saved command to the text box """
self.textEdit_5.setText(self.saved_command_3.text())
self.on_send_data_button_clicked()

def move_command4_to_text(self):
""" Move the saved command to the text box """
self.textEdit_5.setText(self.saved_command_4.text())
self.on_send_data_button_clicked()

def refresh_port(self):
""" Refresh the serial port list """
PORTS = get_serial_port()
self.comboBox_6.clear()
self.comboBox_6.addItems(PORTS)

def print_message_on_screen(self, text):
""" Print the message on the screen """
Expand Down Expand Up @@ -156,6 +233,9 @@ def start_loop(self):
except SerialException:
self.print_message_on_screen(
"Exception occured while trying establish serial communication!")
return

is_serial_port_established = True

try:
self.worker = Worker() # a new worker to perform those tasks
Expand Down Expand Up @@ -198,22 +278,13 @@ def read_data_from_thread(self, serial_data):
self.comboBox_3.setEnabled(False)
self.comboBox_4.setEnabled(False)
self.comboBox_5.setEnabled(False)
self.save_button.setEnabled(False)
self.start_button.setEnabled(False)

self.textEdit.setText('Data Gathering...')
self.label_5.setText("CONNECTED!")
self.label_5.setStyleSheet('color: green')
self.textEdit_3.insertPlainText("{}".format(serial_data))

# Save the settings
def on_save_button_clicked(self):
""" Save the settings """
if self.x != 0:
self.textEdit.setText('Settings Saved!')
else:
self.textEdit.setText('Please enter port and speed!')

def on_save_txt_button_clicked(self):
""" Save the values to the TXT file"""
with open('Output.txt', 'w', encoding='utf-8') as f:
Expand All @@ -223,21 +294,25 @@ def on_save_txt_button_clicked(self):

def on_end_button_clicked(self):
""" Stop the process """
is_serial_port_established = False
self.textEdit.setText('Stopped!')
self.comboBox.setEnabled(True)
self.comboBox_1.setEnabled(True)
self.comboBox_2.setEnabled(True)
self.comboBox_3.setEnabled(True)
self.comboBox_4.setEnabled(True)
self.comboBox_5.setEnabled(True)
self.save_button.setEnabled(True)
self.start_button.setEnabled(True)

def on_send_data_button_clicked(self):
""" Send data to serial port """
mytext = self.textEdit_2.toPlainText()
print(mytext.encode())
SERIAL_INFO.write(mytext.encode())
if (is_serial_port_established):
mytext = self.textEdit_2.toPlainText()
print(mytext.encode())
SERIAL_INFO.write(mytext.encode())
else:
self.print_message_on_screen(
"Serial Port is not established yet! Please establish the serial port first!")


def start_ui_design():
Expand Down
Loading

0 comments on commit 1876e23

Please sign in to comment.