2016-03-21 113 views
1

我正在使用Arduino Nano与ODROID(单板计算机安装的Ubuntu 14.04)进行串行通信。 Arduino的代码:python-serial OSError:[Errno 11]资源暂时不可用

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 

然后,我有这个问题后打印一些值,我知道这个问题目前可能没有数据可用。但我怎样才能找出这个问题。谢谢你的帮助。

+1

请提供整个堆栈跟踪 –

+0

hi @ Mr.E,我正在更新堆栈跟踪,请给我一些建议。谢谢 – crazymumu

回答

0

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

有它说的问题是由树莓派串行端口,用于默认使用时您尝试使用它自己的目的,其冲突的系统控制台造成一个

要禁用控制台的序列号,您必须编辑文件/etc/inittab并注释行T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100(您可以在行开头注释该行,例如在python中)。你必须重新启动ODROID,它应该工作

我建议你阅读我关联的答案,因为它解释了一些关于如何替换串行端口访问命令行(它建议使用SSH)和另一件事是Raspberry PI(并假设ODROID的工作原理类似)在启动时通过串口发送一条消息,Arduino将收到该消息。您可以删除该消息和它的解释有

希望这有助于你

1

您收到此错误,因为您的串行设备正在使用的操作系统本身。你应该停止使用这个设备。

串行盖蒂现在是一个服务,你应该停止和/或禁止它:

sudo systemctl stop [email protected] 
sudo systemctl disable [email protected] 

注意我的原生串行设备ID是ttyAMA0。

永久禁用串行服务,使用 sudo systemctl mask [email protected] 在这种情况下,即使重新启动,串行服务也不会启动。

相关问题