Estou tentando escrever um programa simples para se comunicar entre o RPi e um celular bluetooth. Fui com este tutorial: tutorial do Bluetooth Python para RPi e foi capaz de conectar-se ao telefone e eles delimitaram corretamente. Então eu escrevi este script python:
#! /usr/bin/python
import serial
from protocol import *
from MotorControllerP import *
def startBluetoothServer():
bluetoothSerial = serial.Serial("/dev/rfcomm1",baudrate=9600)
print("Bluetooth connected")
try:
while 1:
data = bluetoothSerial.readLine()
if not data: break
data = data.decode()
print("Data received: "+data)
if data[:3] == Client.INIT_HEY:
print("Initiallizing connection")
bluetoothSerial.write((Server.INIT_OK+"\n").enc$
print("Connection initiallized")
elif data[:3] == Client.KTHXBYE:
bluetoothSerial.write(Server.CLOSE.encode())
exitAndClean()
elif data[:3] == Client.CUSTOM_MOVE:
data = str(data)
formattedData = data.split(",")
direction = formattedData[1]
left = formattedData[2]
right = formattedData[3]
response = customSpeed(direction,left,right)
print(direction+","+left+","+right)
bluetoothSerial.write((str(response)+"\n").enco$
else:
print("Command not understood: "+data)
bluetoothSerial.write(Server.CLOSE.encode())
except KeyboardInterrupt:
print("Rage Quit")
except:
print("Error happened:",sys.exc_info())
finally:
exitAndClean()
O código deve ler um comando do dispositivo BT e enviá-lo para um controlador de Motor. Mas eu recebo este erro:
Traceback (most recent call last):
File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "/home/pi/Desktop/Car/RPiCar/BluetoothServer.py", line 7, in startBluetoothServer
bluetoothSerial = serial.Serial("/dev/rfcomm1",baudrate=9600)
File "/usr/lib/python2.7/dist-packages/serial/serialutil.py", line 260, in __init__
self.open()
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 280, in open
self._reconfigurePort()
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 409, in _reconfigurePort
termios.tcsetattr(self.fd, TERMIOS.TCSANOW, [iflag, oflag, cflag, lflag, ispeed, ospeed, cc])
error: (5, 'Input/output error')
Alguma ideia?
você recebe a mesma mensagem se a executar com "sudo"?
—
rob
Essa é a mensagem quando eu executá-lo com sudo
—
Javi