【问题标题】:Establishing Serial Communication b/t Beaglebone Black (RevC, Deb) and Arduino Mega建立串行通信 b/t Beaglebone Black (RevC, Deb) 和 Arduino Mega
【发布时间】:2016-03-14 20:25:40
【问题描述】:

我正在尝试在 Beaglebone Black 和 Arduino Mega 之间建立串行通信,但我无法使其正常工作,尤其是在 Beagle 方面。我不断收到此错误消息:

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)

我正在使用 cloud 9 IDE 对 Beaglebone 进行编程,以接收来自连接到 Arduino 的传感器的传入数据(通过逻辑转换器)。至少可以说,错误代码让我感到困惑。它提供的链接并没有将我带到 IDE 中的任何内容(未找到文件)。我找不到太多 [关于如何解决此错误的信息。]

【问题讨论】:

    标签: python arduino cloud9-ide beagleboneblack


    【解决方案1】:

    在这条线上

    sensorValue += ser.read('UART1')
    

    您正在调用 serial.Serial.read(size=1) 类型 str 作为参数。该方法采用int

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-10
      • 2020-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-10
      • 2016-04-19
      • 1970-01-01
      相关资源
      最近更新 更多