我正在尝试运行一个同学编写并向我演示的脚本。所以我知道代码是正确的,它只是与我们的机器配置方式不同有关。这是代码:
#!/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()
一切都运行到最后一行 s.open 那里给我错误:
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')
我的猜测是我需要更改我打开的端口,但我已经尝试了一些其他端口,但运气不好。有人知道发生了什么事吗?
顺便说一句,我正在使用 Python 2.7.4
请您参考如下方法:
使用 isOpen() 代替 open()
s=serial.Serial("/dev/ttyS0")
s.isOpen()
