1

如何在 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
4

1 回答 1

0

您正在尝试使用谷歌应用引擎与 SerialPort 交互(GWT 只是通过 RCP 启动代码)。

请参阅https://developers.google.com/appengine/docs/java/jrewhitelist了解可在 google app engine 下运行的类列表。

于 2012-07-27T22:01:48.473 回答