Search in sources :

Example 1 with MissingNativeLibraryException

use of com.neuronrobotics.sdk.common.MissingNativeLibraryException in project java-bowler by NeuronRobotics.

the class SerialConnection method connect.

/* (non-Javadoc)
	 * @see com.neuronrobotics.sdk.common.BowlerAbstractConnection#connect()
	 */
@Override
public boolean connect() {
    if (isConnected()) {
        Log.error(port + " is already connected.");
        return true;
    }
    try {
        if (serial != null)
            serial.disconnect();
        serial = new NRSerialPort(getPort(), baud);
        serial.connect();
        setDataIns(new DataInputStream(serial.getInputStream()));
        setDataOuts(new DataOutputStream(serial.getOutputStream()));
        setConnected(true);
    } catch (UnsatisfiedLinkError e) {
        throw new MissingNativeLibraryException(e.getMessage());
    } catch (Exception e) {
        Log.error("Failed to connect on port: " + port + " exception: ");
        e.printStackTrace();
        setConnected(false);
    }
    if (isConnected()) {
        serial.notifyOnDataAvailable(true);
    }
    return isConnected();
}
Also used : DataOutputStream(java.io.DataOutputStream) MissingNativeLibraryException(com.neuronrobotics.sdk.common.MissingNativeLibraryException) NRSerialPort(gnu.io.NRSerialPort) DataInputStream(java.io.DataInputStream) MissingNativeLibraryException(com.neuronrobotics.sdk.common.MissingNativeLibraryException)

Example 2 with MissingNativeLibraryException

use of com.neuronrobotics.sdk.common.MissingNativeLibraryException in project java-bowler by NeuronRobotics.

the class SerialConnection method disconnect.

/* (non-Javadoc)
	 * @see com.neuronrobotics.sdk.common.BowlerAbstractConnection#disconnect()
	 */
@Override
public void disconnect() {
    if (isConnected())
        // new RuntimeException().printStackTrace();
        Log.warning("Disconnecting Serial Connection");
    try {
        try {
            serial.disconnect();
        } catch (Exception e) {
        // e.printStackTrace();
        // throw new RuntimeException(e);
        }
        serial = null;
        setConnected(false);
    } catch (UnsatisfiedLinkError e) {
        throw new MissingNativeLibraryException(e.getMessage());
    }
}
Also used : MissingNativeLibraryException(com.neuronrobotics.sdk.common.MissingNativeLibraryException) MissingNativeLibraryException(com.neuronrobotics.sdk.common.MissingNativeLibraryException)

Example 3 with MissingNativeLibraryException

use of com.neuronrobotics.sdk.common.MissingNativeLibraryException in project java-bowler by NeuronRobotics.

the class SerialConnectionPanel method refresh.

public void refresh() {
    connectionCbo.removeAllItems();
    String m = "NRSDK not installed properly, native library not found\n\n" + "librxtxSerial.so       in Linux\n" + "librxtxSerial.jnilib   in OSX\n" + "rxtxSerial.dll           in Windows\n\n" + "This must be in your JVM or system library path. See:\n" + "http://neuronrobotics.com/wiki/Installing_The_Native_Serial_Library";
    try {
        List<String> prts = SerialConnection.getAvailableSerialPorts();
        for (int i = 0; i < prts.size(); i++) {
            String s = prts.get(i);
            if (s.contains("DyIO") || s.contains("Bootloader"))
                connectionCbo.addItem(prts.remove(i));
        }
        for (String s : prts) {
            if (!(s.contains("ttyS") || s.equals("COM1") || s.equals("COM2") || s.contains("ttyACM")))
                connectionCbo.addItem(s);
            else {
            // TODO maybe add the others if you can change the color?
            }
        }
        connectionCbo.addItem(null);
        for (String s : prts) {
            if ((s.contains("ttyS") || s.equals("COM1") || s.equals("COM2") || s.contains("ttyACM")))
                connectionCbo.addItem(s);
        }
    } catch (MissingNativeLibraryException e) {
        JOptionPane.showMessageDialog(this, m, "NRSDK not installed properly", JOptionPane.ERROR_MESSAGE);
        throw new MissingNativeLibraryException(m);
    } catch (Exception e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(this, m, "NRSDK not installed properly", JOptionPane.ERROR_MESSAGE);
        throw new MissingNativeLibraryException(m);
    } catch (Error e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(this, m, "NRSDK not installed properly", JOptionPane.ERROR_MESSAGE);
        throw new MissingNativeLibraryException(m);
    }
    getConnectionDialog().pack();
}
Also used : MissingNativeLibraryException(com.neuronrobotics.sdk.common.MissingNativeLibraryException) MissingNativeLibraryException(com.neuronrobotics.sdk.common.MissingNativeLibraryException)

Example 4 with MissingNativeLibraryException

use of com.neuronrobotics.sdk.common.MissingNativeLibraryException in project java-bowler by NeuronRobotics.

the class BlueCoveManager method disconnect.

/**
 */
public synchronized void disconnect() {
    Log.info("Disconnecting: " + selected);
    deviceList.clear();
    try {
        if (ins != null)
            ins.close();
        if (outs != null)
            outs.close();
        if (conn != null)
            conn.close();
        LocalDevice.getLocalDevice().getDiscoveryAgent().cancelInquiry(this);
        if (searchId != 0xffff)
            LocalDevice.getLocalDevice().getDiscoveryAgent().cancelServiceSearch(searchId);
    } catch (Exception e) {
        throw new MissingNativeLibraryException(e.getMessage());
    }
    Log.info("Disconnected");
}
Also used : MissingNativeLibraryException(com.neuronrobotics.sdk.common.MissingNativeLibraryException) IOException(java.io.IOException) BluetoothStateException(javax.bluetooth.BluetoothStateException) MissingNativeLibraryException(com.neuronrobotics.sdk.common.MissingNativeLibraryException)

Example 5 with MissingNativeLibraryException

use of com.neuronrobotics.sdk.common.MissingNativeLibraryException in project java-bowler by NeuronRobotics.

the class BluetoothSerialConnection method connect.

/* (non-Javadoc)
		 * @see com.neuronrobotics.sdk.common.BowlerAbstractConnection#connect()
		 */
@Override
public synchronized boolean connect() {
    if (isConnected()) {
        Log.error(bluetoothAddress + " is already connected.");
        return true;
    }
    try {
        setConnected(true);
        connecting = true;
        blue.connect(bluetoothAddress);
        setDataIns(blue.getDataIns());
        setDataOuts(blue.getDataOuts());
        connecting = false;
    } catch (UnsatisfiedLinkError e) {
        setConnected(false);
        throw new MissingNativeLibraryException(e.getMessage());
    } catch (Exception e) {
        setConnected(false);
        System.err.println("Failed to connect on port:" + bluetoothAddress + " exception: ");
        e.printStackTrace();
        return false;
    }
    return isConnected();
}
Also used : MissingNativeLibraryException(com.neuronrobotics.sdk.common.MissingNativeLibraryException) MissingNativeLibraryException(com.neuronrobotics.sdk.common.MissingNativeLibraryException)

Aggregations

MissingNativeLibraryException (com.neuronrobotics.sdk.common.MissingNativeLibraryException)5 NRSerialPort (gnu.io.NRSerialPort)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 IOException (java.io.IOException)1 BluetoothStateException (javax.bluetooth.BluetoothStateException)1