python-serial OSError : [Errno 11] Resource temporarily unavailable

标签 python ubuntu arduino pyserial serial-communication

我正在使用Arduino Nano与ODROID(安装Ubuntu 14.04的单板计算机)进行串行通信。 Arduino代码:

void setup() {
   Serial.begin(9600); // set the baud rate
   Serial.println("Ready"); // print "Ready" once
}
void loop() {
  char inByte = ' ';
  if(Serial.available()){ // only send data back if data has been sent
    char inByte = Serial.read(); // read the incoming data
  Serial.println(inByte); 
}
  delay(100); // delay for 1/10 of a second
}   

ODROID 中的 Python 代码:

#!/usr/bin/env python

from time import sleep
import serial
ser = serial.Serial('/dev/LIDAR', 9600, timeout=1) # Establish the connection on a specific port

sleep(1)
print "Arduino is initialized"

counter = 32 # Below 32 everything in ASCII is gibberish

while True:
    if (ser.inWaiting()>0):
      counter +=1
      ser.write(str(chr(counter))) # Convert the decimal number to ASCII then send it to the Arduino
      print ser.readline() # Read the newest output from the Arduino
      sleep(.1) # Delay for one tenth of a second
      if counter == 255:
          counter = 32

ser.close  

回溯(最近的最后一个):

File "./serial_test1.py", line 16, in <module>        
    print ser.readline() # Read the newest output from the Arduino       
File "/usr/lib/python2.7/dis-package/serial/serialposix.py", line 43, in read   
    buf = os.read(self.fd, size-len(read))     
OSError: [Errno 11]Resource temporarily unavailable 

然后我在打印一些值后遇到了这个问题,我知道这个问题可能当前没有可用的数据。但我怎样才能弄清楚这个问题。感谢您的帮助。

最佳答案

我不知道这是否适用于 ODROID,但我发现了一篇关于 similar problem with Raspberry PI 的帖子。在那篇文章中,答案之一 redirected to this link

那里说问题是由 Raspberry Pi 串行端口引起的,默认情况下使用系统控制台,当您尝试将其用于自己的目的时会发生冲突

要禁用控制台的串行端口,您必须编辑文件 /etc/inittab 并注释行 T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100 code> (在行首用 # 对其进行注释,就像在 python 中一样)。您必须重新启动 ODROID,它应该可以工作

我建议你阅读我链接的答案,因为它更多地解释了如何替代串行端口来访问命令行(建议使用 ssh),另一件事是 Raspberry PI(并假设 ODROID 的工作原理类似) )在启动时通过串行端口发送一条消息,该消息将由 Arduino 接收。您可以删除该消息,那里有解释

希望这对你有帮助

关于python-serial OSError : [Errno 11] Resource temporarily unavailable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36133620/

相关文章:

ubuntu - MonoDevelop 在 Ubuntu 上使用 FlatPak : Debugger operation failed

python - 在从传感器读取数据而不打印从传感器读取的数据时,While 循环无法立即工作?

arduino - SIM900 GSM/GPRS 未获得正确的 AT+CREG?回答

python - 创建具有相对频率的直方图

python - 使用 Tkinter 进行点击绘图

python - 解析Python文件中的所有方法和类

ubuntu - 尽管我实际上使用的是 Oracle JDK,但为什么 Android Studio 不断发出有关 OpenJDK 的警告?

c++ - 将编译版本复制到另一台主机时出现 GCC 编译错误

mysql - 非常简单的 Arduino 更新 SQL 条目

python - 使用 MALLOC_MMAP_THRESHOLD_ 和 MALLOC_MMAP_MAX_ 减少内存碎片