GWT使用com端口

时间:2012-06-29 13:11:02

标签: java gwt

如何在GWT中使用com端口。

comm.java它是用于在com端口上写入的函数

package com.hell.server;

import jssc.SerialPort;
import jssc.SerialPortException;

public class comm {



    public String writeHelloString(String portName) {
         SerialPort serialPort = new SerialPort("COM5");

            try  {

                serialPort.openPort();

                serialPort.setParams(SerialPort.BAUDRATE_9600,
                                     SerialPort.DATABITS_8,
                                     SerialPort.STOPBITS_1,
                                     SerialPort.PARITY_NONE);


               serialPort.writeBytes(portName.getBytes());
                @SuppressWarnings("unused")
                byte[] buffer = serialPort.readBytes(10);

                serialPort.closePort();

            }

            catch (SerialPortException ex) {
            // System.out.println(ex);

         }

                return "dsada"; 
    }
}

服务器的功能。

public String greetServer(String input) throws IllegalArgumentException {
         comm A = new comm();
         A.writeHelloString("$KE");
         return input;
    }

GWT客户端与服务器的接口:

   @RemoteServiceRelativePath("greet")
    public interface GreetingService extends RemoteService {
        String greetServer(String name) throws IllegalArgumentException;

    }

这是正确的??????? !!! 不起作用,有很多错误...

来自控制台的错误:

Jun 29, 2012 10:21:59 AM com.google.appengine.tools.development.ApiProxyLocalImpl log
SEVERE: javax.servlet.ServletContext log: Exception while dispatching incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract java.lang.String com.hell.client.GreetingService.greetServer(java.lang.String) throws java.lang.IllegalArgumentException' threw an unexpected exception: java.lang.NoClassDefFoundError: jssc/SerialPortException
......

Caused by: java.lang.NoClassDefFoundError: jssc/SerialPortException
    at com.hell.server.GreetingServiceImpl.greetServer(GreetingServiceImpl.java:21)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115)
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:569)
    ... 34 more
Caused by: java.lang.ClassNotFoundException: jssc.SerialPortException
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:176)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 41 more

1 个答案:

答案 0 :(得分:0)

您正尝试使用Google应用引擎与SerialPort进行互动(GWT只是通过RCP启动代码)。

请参阅https://developers.google.com/appengine/docs/java/jrewhitelist以获取可在google app engine下运行的课程列表。