建立B/T Beaglebone黑色(REVC,DEB)和Arduino的巨型
问题描述:
我试图建立一个Beaglebone黑色和Arduino的巨型之间的串行通信,但我有问题得到这个工作,特别是在小猎犬的串行通信侧。响应建立B/T Beaglebone黑色(REVC,DEB)和Arduino的巨型
Traceback (most recent call last): File "/var/lib/cloud9/IBID 2.0 /data stream test (1).py", line 35, in <module> sensorValue += ser.read('UART1') #add more for more pins File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 449, in read buf = os.read(self.fd, size-len(read)) TypeError: unsupported operand type(s) for -: 'str' and 'int'
在试图运行这段代码:我不断收到此错误信息
import Adafruit_BBIO.UART as UART
import serial
UART.setup('UART1')
name = raw_input('name your file: ')
final_name = os.path.join(/sequence of files and folders/, name + '.txt')
data = open(name + '.txt', 'a+')
ser = serial.Serial(port = "/dev/ttyO1", baudrate=9600, timeout = 1000)
sensorValue = 0
header = 'Sensor 1 output'
data.write(str(header))
data.write(str('\n'))
while True:
ser.open()
sensorValue += ser.read('UART1')
data.write(sensorValue)
我使用的是云9 IDE到Beaglebone程序来接收输入数据从一个连接到Arduino的传感器(通过逻辑转换器)。错误代码让我感到神秘,至少可以说。它提供的链接不会引导我在IDE中找到任何内容(找不到文件)。我还没有与str
型能找到多少[关于如何解决此错误。]
答
在此行中
sensorValue += ser.read('UART1')
您呼叫serial.Serial.read(大小= 1)作为论据。该方法需要int
。