我試圖使用Android的東西開發者預覽版5.下一個皮頭進行交流溝通是按照官方Android我已經創建了首部通信類事情文檔:問題與Android的東西開發者預覽版5(RPI3)UART頭
public class UartComm {
private static final String UART_DEVICE_NAME = "UART1";
private UartDevice mDevice;
private void configureUartFrame(UartDevice uart) throws IOException {
// Configure the UART port
uart.setBaudrate(115200);
}
public void onCreate() {
try {
PeripheralManagerService manager = new PeripheralManagerService();
List<String> deviceList = manager.getUartDeviceList();
if (deviceList.isEmpty()) {
Log.i(TAG, "No UART port available on this device.");
} else {
Log.i(TAG, "List of available devices: " + deviceList);
}
mDevice = manager.openUartDevice(UART_DEVICE_NAME);
configureUartFrame(mDevice);
mDevice.registerUartDeviceCallback(mUartCallback);
} catch (Exception e) {
Log.w(TAG, "Unable to access UART device", e);
}
}
public void readUartBuffer(UartDevice uart) throws IOException {
// Maximum amount of data to read at one time
final int maxCount = 40;
byte[] buffer = new byte[maxCount];
uart.read(buffer, maxCount);
String data = new String(buffer, "UTF-8");
Log.d(TAG, data);
}
private UartDeviceCallback mUartCallback = new UartDeviceCallback() {
@Override
public boolean onUartDeviceDataAvailable(UartDevice uart) {
// Read available data from the UART device
try {
readUartBuffer(uart);
} catch (IOException e) {
Log.w(TAG, "Unable to access UART device", e);
}
// Continue listening for more interrupts
return true;
}
@Override
public void onUartDeviceError(UartDevice uart, int error) {
Log.w(TAG, uart + ": Error event " + error);
}
};
}
在我的MainActivity我做UartComm device = new UartComm()
創建UartComm的實例,並在繼續調用device.onCreate()
我還修改了/boot/cmdline.txt
和刪除控制檯= serial0,115200與控制檯取代了它= tty0,我有阿爾斯o嘗試在不添加console = tty0的情況下刪除控制檯行。在/boot/config.txt
我也刪除enable_uart=1
和core-freq=400
也加入dtoverlay=pi3-miniuart-bt
我也試圖通過做dtoverlay=pi3-disable-bt
無濟於事完全移除藍牙支持。
我已經測試了報頭的工作原理以及在Rapsbian,其中I交換的/ dev/ttyAMA0和/ dev/ttyS0來正確配置且工作正常。我能夠在Raspbian上運行screen
命令,默認波特率爲115200,並能夠獲得所需的信息。
我想在做事情的Android開發者預覽版5的相同,並且具有在迷你UART ttyS0形式藍牙跑了ttyAMA0頭運行。我期望的結果是通過UART0訪問頭文件。
具有相同的功能一箇舊的USB串口設備的工作原理,但我寧願UART設備在物理上Pi的頂部,所以這不是一個選項。
您想標記一種語言嗎?這可能會吸引正確的答案。 – Yunnosch
剛剛標記了Java –