Java and mBed interface

15 Oct 2011

I am trying to stablish communication between Java codes and mBed. I ran the code in the example:

http://mbed.org/cookbook/Interfacing-with-Java

but the line of code

mbed = new SerialRxTxRPC("COM5", 9600);

is sending exceptions.

What should I do?

Thanks

18 Oct 2011

you could show us the exceptions ?

11 Jun 2016

This is the exception. I have same problem.

java.lang.NoClassDefFoundError: javax/comm/SerialPortEventListener at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) at java.net.URLClassLoader.access$100(URLClassLoader.java:73) at java.net.URLClassLoader$1.run(URLClassLoader.java:368) at java.net.URLClassLoader$1.run(URLClassLoader.java:362) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:361) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) at java.lang.Class.privateGetMethodRecursive(Class.java:3048) at java.lang.Class.getMethod0(Class.java:3018) at java.lang.Class.getMethod(Class.java:1784) at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526) Caused by: java.lang.ClassNotFoundException: javax.comm.SerialPortEventListener at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 19 more Error: A JNI error has occurred, please check your installation and try again

13 Jun 2016

I am also this difficulty, I used the same sample

Exception in thread "main" java.lang.NoClassDefFoundError: gnu/io/NoSuchPortException]

What should I do?

Thanks

14 Jun 2016

I'm having success with Jserialcomm http://fazecast.github.io/jSerialComm/

See an example

package jserial;

import com.fazecast.jSerialComm.SerialPort;
import com.fazecast.jSerialComm.SerialPortDataListener;
import com.fazecast.jSerialComm.SerialPortEvent;

public class Jserial {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        SerialPort comPort = SerialPort.getCommPort("COM2");
        comPort.openPort();
        comPort.addDataListener(new SerialPortDataListener() {
   
   @Override
   public int getListeningEvents() { return SerialPort.LISTENING_EVENT_DATA_AVAILABLE; }
   @Override
   
   public void serialEvent(SerialPortEvent event)
   {
      if (event.getEventType() != SerialPort.LISTENING_EVENT_DATA_AVAILABLE)
         return;
      byte[] newData = new byte[comPort.bytesAvailable()];
      //int numRead = comPort.readBytes(newData, newData.length);
      int numRead = comPort.readBytes(newData, newData.length);
      //System.out.println("Read " + numRead + " bytes.");
      
      for (int i = 0; i < newData.length; ++i)
         System.out.print((char)newData[i]);
      System.out.println("\n");
      
      }
        });
    }