Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8155487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:41:00+00:00 2026-06-06T16:41:00+00:00

I am currently having a problem with the pySerial module in Python. My problem

  • 0

I am currently having a problem with the pySerial module in Python. My problem relates to connecting and disconnecting to a device. I can successfully connect to my device and communicate with it for as long as I want to, and disconnect from it whenever I desire. However, I am unable to reconnect to the device once the connection has been severed.

Here is the wrapper class that my program uses to interface with the serial port:

import serial, tkMessageBox

class Controller:
""" Wrapper class for managing the serial connection with the MS-2000. """
    def __init__(self, settings):
        self.ser = None
        self.settings = settings

    def connect(self):
        """ Connect or disconnect to MS-2000. Return connection status."""
        try:
            if self.ser == None:
                self.ser = serial.Serial(self.settings['PORT'],
                                         self.settings['BAUDRATE'])
                print "Successfully connected to port %r." % self.ser.port
                return True
            else:
                if self.ser.isOpen():
                    self.ser.close()
                    print "Disconnected."
                    return False
                else:
                    self.ser.open()
                    print "Connected."
                    return True
        except serial.SerialException, e:
            return False

    def isConnected(self):
        '''Is the computer connected with the MS-2000?'''
        try:
            return self.ser.isOpen()
        except:
            return False

    def write(self, command):
        """ Sends command to MS-2000, appending a carraige return. """
        try:
            self.ser.write(command + '\r')
        except Exception, e:
            tkMessageBox.showerror('Serial connection error',
                                   'Error sending message "%s" to MS-2000:\n%s' %
                               (command, e))

    def read(self, chars):
        """ Reads specified number of characters from the serial port. """
        return self.ser.read(chars)

Does anybody know the reason why this problem exists and what I could try to do to fix it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:41:02+00:00Added an answer on June 6, 2026 at 4:41 pm

    You aren’t releasing the serial port when you are finished. Use ser.close() to close the port before exiting your program, otherwise the port will stay locked indefinitely. I would suggest adding a method called disconnect() in your class for this.

    If you are on Windows, to remedy the situation during testing, start Task Manager and kill any python.exe or pythonw.exe processes that may be locking the serial port.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently having a CSS problem and I hope someone can help me
Hi I am currently having a problem with parsing an Xml string without any
I am currently having a problem with a UITableView, and more precisely with a
I'm currently having a problem with some Socket stuff. The output that I want
I am currently having unnecessary trouble trying to test out RubyMine. My biggest problem
I'm currently having a of problem with my Phonegap application on Playbook. It consists
I am currently having a problem selecting a certain item from a mySQL database.
I'm currently having a problem with what seems like the Timer_Tick event interfering with
I am currently having the problem that I have a (partial) program that is
I am currently having a problem with multiple div's toggling at the same time.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.