2017-08-16 22 views
1

我試圖使用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=1core-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的頂部,所以這不是一個選項。

+0

您想標記一種語言嗎?這可能會吸引正確的答案。 – Yunnosch

+0

剛剛標記了Java –

回答

1

可能是錯的,但不應該:

private static final String UART_DEVICE_NAME = "UART1";

是UART0即

private static final String UART_DEVICE_NAME = "UART0";

我在這裏做一個UART例如https://github.com/blundell/androidthings-uart/blob/master/app/src/main/java/com/blundell/tut/MainActivity.java(明顯不同的硬件),但它連接到覆盆子pi引腳以如下方式相同:

enter image description here

+0

感謝您將變量更改爲UART0後的回覆我收到此錯誤: 無法訪問UART設備 com.google.android.things.pio.PioException:android.os.ServiceSpecificException:BCM14未能應用所需的引腳多路複用器:無效的參數(代碼22) –

+0

另外我看到你使用的是UART0,你是否有任何修改/boot/config.txt或/boot/cmdline.txt以使其工作? –

+0

是的,我按照官方文檔中的解釋對它進行了編輯。但是現在如果你使用新的AndroidThings'0.5.0',你不必使用Pin Multiplexing:https://developer.android.com/things/hardware/raspberrypi-mode-matrix.html – Blundell