5

I'm having problem executing the following code:

import serial

ser = serial.Serial(
    port='/dev/tty.FireFly-16CB-SPP',
    baudrate=115200,
    #parity=serial.PARITY_ODD,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS
)

ser.open()
ser.isOpen()

This worked yesterday, and I don't know what I changed. Now I get the following error message:

    Traceback (most recent call last):
  File "main.py", line 32, in <module>
    bytesize=serial.EIGHTBITS
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/serial/serialutil.py", line 260, in __init__
    self.open()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/serial/serialposix.py", line 280, in open
    self._reconfigurePort()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/serial/serialposix.py", line 409, in _reconfigurePort
    termios.tcsetattr(self.fd, TERMIOS.TCSANOW, [iflag, oflag, cflag, lflag, ispeed, ospeed, cc])
termios.error: (22, 'Invalid argument')

I'm a complete beginner to Python, and can't decipher the error message above. I've tried reinstalling Pyserial, but that didn't fix the error. What is wrong?

user685206
  • 91
  • 1
  • 2
  • 3

6 Answers6

3

I had the same issue, though I was using a 5 port USB hub with 3 different USBs all plugged into it, and it turned out the hub wasn't providing enough power. Once I got an externally powered USB (one that wasn't just pulling off the line from my computer's port) it worked just fine.

clifgray
  • 4,313
  • 11
  • 67
  • 116
  • Same here. Errors on a hub, plugged directly into the back of the Mac problem went away. The port name changed too. – marxy Aug 28 '22 at 07:46
  • Similar problem with a USB hub, unplugging and replugging into the same hub helped. – 101 Jan 16 '23 at 23:10
0

I had this problem on OSX, and the problem ended up being the baud rate was not supported. Changed the baud rate to something more common and it worked!

zingle-dingle
  • 1,681
  • 16
  • 16
0

Is the port still there? I meen /dev/tty.FireFly-16CB-SPP. It could have a new name today...

Daren Thomas
  • 67,947
  • 40
  • 154
  • 200
0

Try this :

ser = serial.Serial('/dev/tty.FireFly-16CB-SPP',115200)
print "port is open" if ser.isOpen() else "port is closed"

you dont have to call open() unless you changed the configuration of the port manually eg:

ser = serial.Serial()
ser.baudrate = 19200
ser.port = 0
ser.open()

and don't forget to cles the port when you are done with it

P2bM
  • 1,038
  • 6
  • 9
0

Reinstalled Python and downgraded to 2.6 which solved everything.

user685206
  • 91
  • 1
  • 2
  • 3
0

I have the same problem.

Just run the miniterm.py from pySerial examples (http://sourceforge.net/projects/pyserial/develop) .

It ran fine from shell: python miniterm -p ttyUSB0 -D but when tried to load it into Eclipse. and run debug from there. it gave me:

pydev debugger: starting
Traceback (most recent call last):
  File "/eclipse/plugins/org.python.pydev.debug_2.0.0.2011040403/pysrc/pydevd.py", line 1134, in <module>
    debugger.run(setup['file'], None, None)
  File "/eclipse/plugins/org.python.pydev.debug_2.0.0.2011040403/pysrc/pydevd.py", line 918, in run
    pydev_imports.execfile(file, globals, locals) #execute the script
  File "/root/workspace/pyserial/src/examples/miniterm.py", line 120, in <module>
    console.setup()
  File "/root/workspace/pyserial/src/examples/miniterm.py", line 101, in setup
    self.old = termios.tcgetattr(self.fd)
termios.error: (22, 'Invalid argument')
mac
  • 42,153
  • 26
  • 121
  • 131