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
-
What os are you using ?jramirez– jramirez2013年10月29日 22:11:04 +00:00Commented Oct 29, 2013 at 22:11
-
Linux, I just changed 'cls' to be 'clear' instead.. Is there anything else?Matt Hintzke– Matt Hintzke2013年10月29日 22:17:37 +00:00Commented Oct 29, 2013 at 22:17
2 Answers 2
use isOpen() in place of open()
s=serial.Serial("/dev/ttyS0")
s.isOpen()
1 Comment
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*
4 Comments
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'