Skip to content

kayrlas/SerialComPython

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SerialComPython

GitHub issues GitHub forks GitHub stars GitHub license Twitter

Serial Communication Python Class. CUI and GUI both are available.

Strong Points

  • Using a thread, TX and RX both are available at the same time.
  • Execute serial.close() and disconnect safely.

serialcompy (Python Code)

Serial Communication Python Class.

Imports

  • time: Standard library
  • threading: Standard library
  • serial (pySerial): Third-Party library (pip install pyserial)

API

SerialCom (class)              // Args: baudrate, timeout, writemode
├── devices (variable)         // comports list  
├── device (variable)          // selected comport  
├── serial (variable)          // serial.Serial instance  
├── writemode (variable)       // boolean serial write accept  
├── find_comports (method)     // Find comports and save to `self.devices`  
├── select_comport (method)    // Select a comport from list  
├── register_comport (method)  // Save a comport to `self.serial.port`  
├── open_comports (method)     // Open the comport  
├── close_comports (method)    // Close ther comport  
├── serial_write (method)      // Write strings to comport  
├── start_serialwrite (method) // Start `serial_write` in another thread  
├── serial_read (method)       // Read strings from comport  
├── start_serialcom (method)   // Start serial communication  
├── start_serialcom_option (method) // Start serial communication (using option args)  
├── get_found_devices (method)      // Return `self.devices`  
├── get_selected_device (method)    // Return `self.device`  
└── get_write_available (method)    // Return `self.writemode`

main_gui (Python Code)

  1. Startup window.
    Window Start

  2. Select a comport from the combobox. If you connect a device after the startup, push "Reload" button and check the combobox again.
    Window Select

  3. After input a baudrate, push "Open" button. If the "Baudrate" entry is empty, the rate is 9600 bps by default or the last bps you open the port.
    Window Open

  4. Input string to "Text" entry and push "Send" button. "TX" listbox is a sending history and "RX" listbox is a receiving history. Pushing "TX Export" button or "RX Export" button, you can save these histories as a text file.
    Window Send

  5. To disconnect, push "Close" button.
    Window Close

main_cui (Python Code)

  1. Select a comport.
  2. Input "yes", "y" or "no", "n".
  3. Serial communication starts.
  4. To disconnect, input Ctrl+C.
    CUI Start

SerialCom (Arduino Code)

  • 9600 bps serial communication
  • Once get a string, send it.