1

I am attempting to run a script that a classmate has written and demonstrated to me. So I know the code is correct, it just has to do with the difference in how our machines are configured. Here is the code:

#!/usr/bin/python
#import statements
import serial
import os
import time
#global constants
control_byte = '\n'
ACL_1_X_addr = ord('X')
ACL_1_Y_addr = ord('Y')
ACL_1_Z_addr = ord('Z')
GYRO_1_X_addr = ord('I')
GYRO_1_Y_addr = ord('J')
GYRO_1_Z_addr = ord('K')
#clear the screen
os.system('clear')
#initialize the serial port
s = serial.Serial()
s.port = 10
s.baudrate = 56818
s.open()

Everything runs up to the last line s.open where it gives me the error:

Traceback (most recent call last):
 File "serial_reader.py", line 25, in <module>
 s.open()
 File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 282, in open
 self._reconfigurePort()
 File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 311, in _reconfigurePort
 raise SerialException("Could not configure port: %s" % msg)
serial.serialutil.SerialException: Could not configure port: (5, 'Input/output error')

My guess is I need to change the port I am opening, but I have tried a few others without and luck. Anybody have any ideas of what is happening?

Btw, I am using Python 2.7.4

Micke
2,3295 gold badges34 silver badges48 bronze badges
asked Oct 29, 2013 at 22:07
2
  • What os are you using ? Commented Oct 29, 2013 at 22:11
  • Linux, I just changed 'cls' to be 'clear' instead.. Is there anything else? Commented Oct 29, 2013 at 22:17

2 Answers 2

5

use isOpen() in place of open()

s=serial.Serial("/dev/ttyS0")
s.isOpen()
MattDMo
103k21 gold badges251 silver badges239 bronze badges
answered Jan 1, 2014 at 19:52
Sign up to request clarification or add additional context in comments.

1 Comment

Worked for me. I am using a virtual com port.
4

I'm guessing you need something like s.port="/dev/ttys0" ... the numeric port is for "COM10" style windows ports that don't have a mapping into the file system.

Your serial ports should list if you do ls /dev/tty*

AaronHS
1,36213 silver badges30 bronze badges
answered Oct 29, 2013 at 22:12

4 Comments

also, I am unsure what of the tty* ports I can use.. There are tons of them so what ones are reserved and which are free?
every time I try to open that way, it says the port is already open
then maybe its already open? or thats not the right port? how many do you have in that list? only one thing can have a given port open at a time
in the command line try this dmesg | grep tty it will list all of your serial port. If you are using a serial to usb adapter it will look something like this `ttyUSB0'

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.