Mat*_*zke 1 python serial-port pyserial
我试图运行一个同学写的脚本并向我演示.所以我知道代码是正确的,它只与我们的机器配置方式有所不同.这是代码:
#!/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()
Run Code Online (Sandbox Code Playgroud)
一切都运行到最后一行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')
Run Code Online (Sandbox Code Playgroud)
我的猜测是我需要改变我正在打开的端口,但我已经尝试过其他一些没有运气的东西.有人对发生的事情有任何想法吗?
顺便说一句,我使用的是Python 2.7.4
小智 5
用来isOpen()代替open()
s=serial.Serial("/dev/ttyS0")
s.isOpen()
Run Code Online (Sandbox Code Playgroud)