我正试图运行一个脚本,一个同学已经写并演示给我看。所以我知道代码是正确的,这只是和我们的机器配置的不同有关。代码如下:
#!/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')
我想我需要换一个我要开的港口,但我试过其他一些没有运气的港口。有人知道发生了什么吗?
顺便说一下,我使用的是Python2.7.4
用
isOpen()
代替open()
我猜你需要像
s.port="/dev/ttys0"
这样的东西。。。数字端口用于“COM10”样式的windows端口,这些端口没有到文件系统的映射。如果您这样做,您的串行端口应该列出
ls /dev/tty*
相关问题 更多 >
编程相关推荐