Coder Social home page Coder Social logo

serialcompython's Introduction

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.

serialcompython's People

Contributors

kayrlas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

serialcompython's Issues

Add Exception Raise

serial.SerialException sometimes occurs when opening a comport. Users must control this exception, but you catch and hide it in SerialComPython. So, please add an exception class and raise it.

_inp_yn = input("Open %s ? [Yes/No] >> " % self.serial.port).lower()
if _inp_yn in ["y", "yes"]: # YES
print("Opening...")
try:
self.serial.open()
except SerialException:
print("%s was disconnected while you input [Yes/No]" % self.serial.port)
return False
else:
return True
elif _inp_yn in ["n", "no"]: # NO
print("Canceled")
return False
else: # Other than [Yes/No]
print("Oops, you didn't enter [Yes/No]. Please try again.")
return False

TX thread starts before rx received

image

When trying to send data to my microcontroller, sometimes i get the rx first and then it asks me to send another data, but sometimes when i send data, it asks for TX before getting the response and printing the RX and then it stucks,
is it a problem with my microcontroller code?

seems not compatible with python 3.8

AppData\Local\Programs\Python\Python38\lib\tkinter\ttk.py", line 717, in current
return self.tk.call(self._w, "current", newindex)
_tkinter.TclError: Index 0 out of range

could you pls run your code in pthon 3.8? thanks in advance.
onegaisimasu

Hi There!
what i wanted to create was a serial tool with real-time graph in it.
shall we create it together?
I am just new to python, might need your help.
[email protected]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.