Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create driver throws exception on open() #17

Closed
PaulBouchier opened this issue Jul 22, 2014 · 2 comments
Closed

Create driver throws exception on open() #17

PaulBouchier opened this issue Jul 22, 2014 · 2 comments

Comments

@PaulBouchier
Copy link
Contributor

The open() of /dev/ttyUSB0 fails for reasons that are hard to understand. The error message (from a modified msg in create_driver.py that prints Exception.message in the log) is:
[ERROR] [WallTime: 1405999978.886373] Failed to open port /dev/ttyUSB0, Error: Port is already open.. Please make sure the Create cable is plugged into the computer.

The relevant code in create_driver.py is:
class SerialCommandInterface(object):
def init(self, tty, baudrate):
self.ser = serial.Serial(tty, baudrate=baudrate, timeout=SERIAL_TIMEOUT)
self.ser.open()

The exception is thrown by self.ser.open(). If I comment out self.ser.open() the open is successful and robot initialization proceeds.

The pySerial API doc says:

class serial.Serial
init(lots of params)
The port is immediately opened on object creation, when a port is given. It is not opened when port is None and a successive call to open() will be needed.

turtlebot_node passes in port. Thus it appears self.ser.open() is not needed, and various internet posts report that open() on an already-open serial port will throw an exception, though the API doc doesn't say that. But this driver code hasn't changed since before fuerte, so why would it suddenly break? Did something change between python 2.7.3 (in 12.04/Fuerte) and python 2.7.6 (in Trusty/Indigo) related to calling open() on already open ports? Or is something in my environment misconfigured?
Any suggestions?

@PaulBouchier
Copy link
Contributor Author

Problem understood.

From http://sourceforge.net/p/pyserial/code/HEAD/tree/tags/release2_7/CHANGES.txt:

Version 2.6 2011-11-02

Bugfixes:

  • [Bug 3093882] calling open() on an already open port now raises an exception

On Ubuntu 14.04:
less /usr/lib/python2.7/less /usr/lib/python2.7/dist-packages/serial/init.py shows:
VERSION = '2.6'

On the working Ubuntu 12.04 system, the same command shows VERSION = '2.5'

The actual code which throws the exception is in serialposix.py:
def open(self):
"""Open port with current settings. This may throw a SerialException
if the port cannot be opened."""
if self._port is None:
raise SerialException("Port must be configured before it can be used.")
if self._isOpen:
raise SerialException("Port is already open.")

I confirmed by opening a port in python manually that it does throw that exception.

So the root cause is the API changed between pySerial 2.5 used on Ubuntu 12.04 and pySerial 2.6 used on Ubuntu 14.04. The solution is the open() statement has to be removed in Indigo. I'll submit a pull request for the github official turtlebot repo in a little while, which will fix some other breaks in the turtlebot build, but someone should fix the yujinrobot repo.

jihoonl added a commit that referenced this issue Jul 23, 2014
Fix issue #17: open() throws exception.
@kentsommer
Copy link

Fixed with this merge: #18

:bowtie:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants