我有一個Arduino配置爲繼續在TX端口上編寫東西,即通過Android Things Developer preview 3連接到我的Raspberry Pi 3(我相信RX/TX電纜配置正確,電壓正常)。Android Things 3無法從Raspberry PI 3上的rxtx讀取
我想了很長時間來使用Android Things庫的PeripheralManagerService讀取數據和寫入數據。
有一個錯誤,當我啓動的應用程序:
04-11 16:26:13.665 163-163 /? I/peripheralman:type = 1400 audit(0.0:44):avc:denied {read write} for name =「ttyAMA0」dev =「tmpfs」ino = 1203 scontext = u:r:peripheralman:s0 tcontext = u:object_r:設備:s0 tclass = chr_file permissive = 1
04-11 16:26:13.665 163-163 /? I/peripheralman:type = 1400 audit(0.0:45):avc:denied {open} for path =「/ dev/ttyAMA0」dev =「tmpfs」ino = 1203 scontext = u:r:peripheralman:s0 tcontext = u: object_r:device:s0 tclass = chr_file permissive = 1
04-11 16:26:13.665 163-163 /? I/peripheralman:type = 1400 audit(0.0:46):avc:denied {ioctl} for path =「/ dev/ttyAMA0」dev =「tmpfs」ino = 1203 ioctlcmd = 5401 scontext = u:r:peripheralman:s0 tcontext = U:object_r:設備:S0 = tclass許可chr_file = 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();
}
}}
有人知道會是什麼?
如果您發佈(複製並粘貼)文本代碼和相關錯誤,而不是幾天內最終會死的鏈接,您可以獲得更多幫助。只是一個想法:) –
好吧!我編輯過。 thx – Stould
您是直接連接到RPi3接頭上的RX/TX引腳(8/10),還是這是USB-TTL電纜? 如果您使用的是本地UART,您是否按照文檔正確配置了模式? https://developer.android.com/things/hardware/raspberrypi.html#configuring_the_uart_mode – Devunwired