Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Things 3无法从Raspberry Pi3上的rxtx读取_Android_Arduino_Raspberry Pi3_Android Things - Fatal编程技术网

Android Things 3无法从Raspberry Pi3上的rxtx读取

Android Things 3无法从Raspberry Pi3上的rxtx读取,android,arduino,raspberry-pi3,android-things,Android,Arduino,Raspberry Pi3,Android Things,我有一个Arduino配置为在TX端口上继续写东西,它连接到我的Raspberry Pi 3和Android things Developer preview 3(我确信RX/TX电缆配置正确,电压正常) 我尝试了很长一段时间使用Android Things libs的外围设备管理服务读取和写入数据 启动应用程序时出现错误: 04-11 16:26:13.665 163-163/?I/peripheraman:type=1400审核(0.0:44):avc:denied{read write}f

我有一个Arduino配置为在TX端口上继续写东西,它连接到我的Raspberry Pi 3和Android things Developer preview 3(我确信RX/TX电缆配置正确,电压正常)

我尝试了很长一段时间使用Android Things libs的外围设备管理服务读取和写入数据

启动应用程序时出现错误:

04-11 16:26:13.665 163-163/?I/peripheraman:type=1400审核(0.0:44):avc:denied{read write}for name=“ttyam0”dev=“tmpfs”ino=1203 scontext=u:r:peripheraman:s0 tcontext=u:object\r:device:s0 tclass=chr\u file permissive=1

04-11 16:26:13.665 163-163/?I/peripheraldan:type=1400审核(0.0:45):avc:denied{open}for path=“/dev/ttyAMA0”dev=“tmpfs”ino=1203 scontext=u:r:peripheraldman:s0tcontext=u:object\r:device:s0tclass=chr\u file permissive=1

04-11 16:26:13.665 163-163/?I/peripheraldan:type=1400审核(0.0:46):avc:denied{ioctl}for path=“/dev/ttyam0”dev=“tmpfs”ino=1203 ioctlcmd=5401 scontext=u:r:peripheraldan:s0 tcontext=u:object\r:device:s0 tclass=chr\u file permissive=1

我的代码:

public class MainActivity extends Activity {

private final int BUFFER_SIZE = 64;
private UartDevice rxtx;


public void configureUartFrame(UartDevice uart) throws IOException {
    // Configure the UART port
    uart.setBaudrate(9600);
}

public void writeUartData(UartDevice uart, String msg) throws IOException {
    byte[] buffer = msg.getBytes();
    int count = uart.write(buffer, buffer.length);
    Log.d(TAG, "Wrote " + count + " bytes to peripheral");
}

public void readUartBuffer(UartDevice uart) throws IOException {
    byte[] buffer = new byte[BUFFER_SIZE];
    int count;
    while ((count = uart.read(buffer, buffer.length)) > 0) {
        Log.d(TAG, "Read " + count + " bytes from peripheral");
        Log.d("Message", new String(buffer));
    }
}

@Override
protected void onStart() {
    super.onStart();
        try {
            writeUartData(rxtx, "teste");
            readUartBuffer(rxtx);
        } catch (IOException e) {
            e.printStackTrace();
        }
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    PeripheralManagerService manager = new PeripheralManagerService();

    manager.getUartDeviceList();
    List<String> portList = manager.getUartDeviceList();

    if (portList.isEmpty()) {
        Log.i(TAG, "No UART port available on this device:");
    } else {
        Log.i(TAG, "List of RXTX available ports: - " + portList);
    }

    try{
       rxtx = manager.openUartDevice(portList.get(0));
       configureUartFrame(rxtx);
    }catch (IOException e){
        e.printStackTrace();
    }
}}
公共类MainActivity扩展活动{
私有最终整数缓冲区大小=64;
专用UartDevice rxtx;
public void configureUartFrame(UartDevice uart)引发IOException{
//配置UART端口
uart.setBaudrate(9600);
}
public void writeUartData(UartDevice uart,字符串msg)引发IOException{
byte[]buffer=msg.getBytes();
int count=uart.write(buffer,buffer.length);
Log.d(标记,“将“+count+”字节写入外围设备”);
}
public void readUartBuffer(UartDevice uart)引发IOException{
字节[]缓冲区=新字节[缓冲区大小];
整数计数;
而((count=uart.read(buffer,buffer.length))>0){
Log.d(标记,“从外围设备读取”+计数+”字节);
Log.d(“消息”,新字符串(缓冲区));
}
}
@凌驾
受保护的void onStart(){
super.onStart();
试一试{
WriteArtData(rxtx,“测试”);
readUartBuffer(rxtx);
}捕获(IOE异常){
e、 printStackTrace();
}
}
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
外围设备管理器服务管理器=新的外围设备管理器服务();
manager.getUartDeviceList();
List portList=manager.getUartDeviceList();
if(portList.isEmpty()){
i(标记“此设备上没有可用的UART端口:”);
}否则{
Log.i(标签,“RXTX可用端口列表:-”+端口列表);
}
试一试{
rxtx=manager.openUartDevice(portList.get(0));
配置UARTFRAME(rxtx);
}捕获(IOE异常){
e、 printStackTrace();
}
}}

有人知道可能是什么吗?

我在你的代码中没有看到注册了
UartDeviceCallback
的地方。您如何轮询UART以获取新的传入数据?如果没有注册回调,您的应用程序将需要通过
UartDevice.read()
定期轮询UART以获取新的传入字节,而我在您的代码中也没有看到这一点。似乎只有在
onStart()
活动回调中调用过一次


回调是一种更有效的方法,因此我建议添加它。有关更多详细信息,请查看。

如果您发布(复制和粘贴)文本代码和相关错误,而不是一些在几天内最终会死掉的链接,您可以获得更多帮助。只是想:)好吧!我编辑过。THX您是直接连接到RPi3头上的RX/TX引脚(8/10)还是USB-TTL电缆?如果您使用的是本机UART,您是否按照文档正确配置了模式?我在右边的引脚上使用direct RXTX,是的,我已经按照文档进行了配置。很抱歉回答晚了。最有趣的是。。我在这里做了一个测试,将数据从RP3的TX发送到RP3的RX(发送到自身)。。而且效果很好。波特率/数据大小/奇偶校验/停止位在两个程序中都是相同的。我发现了发生的情况,我使用的Intel Arduino 101使用了与Arduino Uno不同的配置。使用Arduino Uno,一切正常。感谢您的回答,最好使用回调来轮询数据。但我真的想知道我上面提到的错误是什么。