Search in sources :

Example 1 with SerialConnection

use of com.neuronrobotics.sdk.serial.SerialConnection in project java-bowler by NeuronRobotics.

the class SerialConnectionPanel method getConnection.

public BowlerAbstractConnection getConnection() {
    try {
        int baud = Integer.parseInt(baudrateTxt.getText());
        if (baud < 0) {
            throw new NumberFormatException();
        }
        String port = connectionCbo.getSelectedItem().toString();
        connection = new SerialConnection(port, baud);
        Log.info("Using port:" + port + "\n");
    } catch (NumberFormatException e) {
        JOptionPane.showMessageDialog(null, "Invalid baudrate given. Please review the list of valid baudrates.", "Invalid Baudrate", JOptionPane.ERROR_MESSAGE);
    } catch (Exception e) {
    } finally {
        setVisible(false);
    }
    return connection;
}
Also used : SerialConnection(com.neuronrobotics.sdk.serial.SerialConnection) MissingNativeLibraryException(com.neuronrobotics.sdk.common.MissingNativeLibraryException)

Example 2 with SerialConnection

use of com.neuronrobotics.sdk.serial.SerialConnection in project java-bowler by NeuronRobotics.

the class SimpleConnection method main.

/**
 * @param args
 */
public static void main(String[] args) {
    SerialConnection s = null;
    System.out.println("Connecting and disconnecting");
    // Windows
    // s=new SerialConnection("COM5");
    // OSX
    // s=new SerialConnection("/dev/tty.usbmodemfd13411");
    // Linux
    s = new SerialConnection("/dev/DyIO.74F726800079");
    GenericDevice dyio = new GenericDevice(s);
    // Log.enableDebugPrint(true);
    dyio.connect();
    double avg = 0;
    long start = System.currentTimeMillis();
    int i;
    for (i = 0; i < 500; i++) {
        dyio.ping();
        double ms = System.currentTimeMillis() - start;
        avg += ms;
        start = System.currentTimeMillis();
    }
    System.out.println("Average cycle time for ping: " + (avg / i) + " ms");
    dyio.disconnect();
    System.exit(0);
// while(true);
}
Also used : GenericDevice(com.neuronrobotics.sdk.genericdevice.GenericDevice) SerialConnection(com.neuronrobotics.sdk.serial.SerialConnection)

Aggregations

SerialConnection (com.neuronrobotics.sdk.serial.SerialConnection)2 MissingNativeLibraryException (com.neuronrobotics.sdk.common.MissingNativeLibraryException)1 GenericDevice (com.neuronrobotics.sdk.genericdevice.GenericDevice)1