Search in sources :

Example 1 with UARTChannel

use of com.neuronrobotics.sdk.dyio.peripherals.UARTChannel in project java-bowler by NeuronRobotics.

the class USARTTest method main.

public static void main(String[] args) throws InterruptedException {
    DyIO dyio = new DyIO();
    if (!ConnectionDialog.getBowlerDevice(dyio)) {
        System.exit(0);
    }
    // Instantiate the UARTPassThroughChannel
    UARTChannel uart = new UARTChannel(dyio);
    // Configure the DyIO's output UART to use 115200 baud
    uart.setUARTBaudrate(115200);
    // Create a test string and send it to the serial port
    String s = new String("abcdefghijklmnopqrstuvwxyz");
    ByteList stream = new ByteList(s.getBytes());
    try {
        System.out.println("Sending: " + stream.asString());
        uart.sendBytes(stream);
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }
    Thread.sleep(1000);
    // Wait for data to arrive
    while (!uart.inStreamDataReady()) {
        Thread.sleep(10);
    }
    // Print out the data we got back
    try {
        System.out.println("Got input: " + new ByteList(uart.getBytes()).asString());
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
    // Cleanup and exit
    dyio.disconnect();
    System.exit(0);
}
Also used : UARTChannel(com.neuronrobotics.sdk.dyio.peripherals.UARTChannel) ByteList(com.neuronrobotics.sdk.common.ByteList) DyIO(com.neuronrobotics.sdk.dyio.DyIO) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

ByteList (com.neuronrobotics.sdk.common.ByteList)1 DyIO (com.neuronrobotics.sdk.dyio.DyIO)1 UARTChannel (com.neuronrobotics.sdk.dyio.peripherals.UARTChannel)1 IOException (java.io.IOException)1