Reputation: 8004
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
Upvotes: 1
Views: 16698
Reputation: 114068
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*
Upvotes: 4
Reputation: 51
use isOpen()
in place of open()
s=serial.Serial("/dev/ttyS0")
s.isOpen()
Upvotes: 5