6

I am trying to connect to my arduino with Java and OSx yosemite, but am getting the following error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no usbJava in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1865)
    at java.lang.Runtime.loadLibrary0(Runtime.java:870)
    at java.lang.System.loadLibrary(System.java:1122)
    at ch.ntb.usb.LibusbJava.<clinit>(LibusbJava.java:366)
    at ch.ntb.usb.USB.init(USB.java:315)
    at org.zu.ardulink.connection.usb.DigisparkUSBConnection.getPortList(DigisparkUSBConnection.java:116)
    at org.zu.ardulink.Link.getPortList(Link.java:217)
    at BlinkLED.main(BlinkLED.java:36)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

This is the code I'm executing:

public static void main(String[] args) {
        try {
            Link link = Link.getDefaultInstance();
            link = getDigisparkConnection(); // Comment this row if you use just the default connection

            List<String> portList = link.getPortList();
            if(portList != null && portList.size() > 0) {
                String port = portList.get(0);
                System.out.println("Connecting on port: " + port);
                boolean connected = link.connect(port);
                System.out.println("Connected:" + connected);
                Thread.sleep(2000);
                int power = IProtocol.HIGH;
                while(true) {
                    System.out.println("Send power:" + power);
                    link.sendPowerPinSwitch(2, power);
                    if(power == IProtocol.HIGH) {
                        power = IProtocol.LOW;
                    } else {
                        power = IProtocol.HIGH;
                    }
                    Thread.sleep(2000);
                }
            } else {
                System.out.println("No port found!");
            }

        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }

    private static Link getDigisparkConnection() {
        Set<String> protocolNames = ProtocolHandler.getInstalledProtocolImplementationNames();
        SimpleBinaryProtocol protocol = new SimpleBinaryProtocol();
        if(!protocolNames.contains(SimpleBinaryProtocol.NAME)) {
            ProtocolHandler.installProtocolImplementation(protocol);
        }
        return Link.createInstance("digisparkConnection", SimpleBinaryProtocol.NAME, new DigisparkUSBConnection("digisparkConnection", protocol.getIncomingMessageDivider()));
    }

When I comment the 4th line (link = getDigisparkConnection();), I get the following error:

java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver
Exception in thread "main" java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1865)
    at java.lang.Runtime.loadLibrary0(Runtime.java:870)
    at java.lang.System.loadLibrary(System.java:1122)
    at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:83)
    at org.zu.ardulink.connection.serial.SerialConnection.connect(SerialConnection.java:161)
    at org.zu.ardulink.connection.serial.SerialConnection.connect(SerialConnection.java:139)
    at org.zu.ardulink.connection.serial.SerialConnection.connect(SerialConnection.java:227)
    at org.zu.ardulink.Link.connect(Link.java:187)
    at BlinkLED.main(BlinkLED.java:37)

That has something to do with the native rxtx lib but I am not being able to solve it. I am using IntelliJ IDEA as IDE. Looking for this error, I've only found linux answers, but nothing regarding OSX. Thanks

Sebastian Breit
  • 6,137
  • 1
  • 35
  • 53

1 Answers1

1

Posible solutions:

  1. Check if you have all libraries in the newest stable release.

  2. Check if your program has permission to comunicate throw serial comunication. If not, do it with chmod command.

Community
  • 1
  • 1
Jan Černý
  • 1,268
  • 2
  • 17
  • 31