简体   繁体   English

使用jssc和java applet与JS进行串行通信,但浏览器冻结

[英]using jssc and java applet to communicate to Serial with JS but browser freezes

Im trying to talk to the serial port with JS using a java applet. 我正在尝试使用Java小程序与JS进行串行端口通信。 Im not too experienced with java but i managed to get jssc running just fine when not in a applet or using js. 我对Java不太有经验,但是当不在applet或不使用js时,我设法使jssc正常运行。 and Ive also been able to talk between an applet and JS passing functions and variables. 而且Ive还能够在applet和JS传递函数和变量之间进行对话。 but I cannot understand why my browers freezes everytime i try to load the serialCom.class applet that contains the jssc information 但是我不明白为什么每次尝试加载包含jssc信息的serialCom.class小程序时,浏览器都会冻结

here is my java 这是我的java

import jssc.SerialPort;
import jssc.SerialPortException;
import java.applet.*;
import java.awt.*;



public class serialCom extends Applet{


SerialPort serialPort;


public void connect(){
    serialPort = new SerialPort("/dev/pts/2");
    try {
        serialPort.openPort();
        serialPort.setParams(9600, 8, 1, 0);
        serialPort.writeBytes("Hello Again".getBytes());
        serialPort.closePort();
        }
    catch (SerialPortException ex){
        System.out.print(ex);
        }
}
public void disconnect(){
    //SerialPort serialPort = new SerialPort("/dev/pts/1");
    try {
        //serialPort.openPort();
        //serialPort.setParams(9600, 8, 1, 0);
        //serialPort.writeBytes("Hello Again".getBytes());
        serialPort.closePort();
        }
    catch (SerialPortException ex){
        System.out.print(ex);
        }
}
public void writeSerial(){
     //SerialPort serialPort = new SerialPort("/dev/pts/1");
    try {
        //serialPort.openPort();
        //serialPort.setParams(9600, 8, 1, 0);
        serialPort.writeBytes("Hello Again".getBytes());
        //serialPort.closePort();
        }
    catch (SerialPortException ex){
        System.out.print(ex);
        }
}





}

and here is my html 这是我的html

<!DOCTYPE html>
<html>
<head>

<title>
 Will It Work
</title>
</head>
<body>
<div>
<button id="test" onclick="connectTest();">Connect</button>
<button id="test" onclick="writeTest();">Write</button>
<button id="test" onclick="readTest();">Read</button>
<button id="test" onclick="disconnectTest();">Disconnect</button>
<applet code="serialCom.class" id="myApplet" width="0" height="0"></applet>
 <script>
var connectTest = function(){
alert("Im Connected");
myApplet.connect();

}
alert("Connect");
var disconnectTest = function(){
alert("Im Disconnected");
myApplet.disconnect();
}
alert("Disconnect");
var writeTest = function(){
alert("Im Writing");
myApplet,writeSerial();
}
alert("Write");
var readTest = function(){
}
alert("Read");
</script>-->
</div>
</body>
</html>

I'm quite new to all this java applet programming, but its seems like we are trying to do something similar. 我对所有这些Java applet编程都比较陌生,但是似乎我们正在尝试做类似的事情。 I have no idea what exactly is wrong with your code but I found jss-bridge which helped me a lot on achieving serial port communication trough javascript/java-applet. 我不知道您的代码到底有什么问题,但是我发现jss-bridge可以帮助我通过javascript / java-applet实现串行端口通信。

you can download the full code using svn 您可以使用svn下载完整代码

svn checkout http://java-simple-serial-connector.googlecode.com/svn/trunk/ java-simple-serial-connector-read-only

inside the js_terminal folder you will find an index.html that simulates a terminal on your browser to communicate with the serial ports. 在js_terminal文件夹中,您会找到一个index.html,它可以在浏览器上模拟一个终端以与串行端口通信。 it works amazingly well. 它的运作非常出色。 you will also probably need to lower your java security setting or self-sign the applet. 您可能还需要降低Java安全性设置或自签名小程序。

I hope it helps! 希望对您有所帮助!

pd: I know it isn't an answer, but i can't comment yet. PD:我知道这不是答案,但是我还不能发表评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java applet冻结浏览器以及javascript和applet之间进行通信的方式 - java applet freezes browser and way to communicate between javascript and applet 我可以使用jssc与虚拟串行设备通信吗? ttyS0配置问题(Ubuntu) - Can I communicate with virtual serial device using jssc? Problem with ttyS0 configuration (Ubuntu) 延迟使用jssc进行串行通信 - Delay in serial communication using jssc Java Applet:我可以通过串行方式与服务器通信吗? - Java applet: Can I communicate over serial with the server? 如何使用Java小程序安全地与数据库通信 - How to securely communicate with a database using a java applet Java简单串行连接器(jssc)未检测到端口 - Java Simple Serial Connector (jssc) no ports detected 如何在浏览器和Java Web Start applet之间进行通信 - How to communicate between browser and Java Web Start applet Java applet的替代方案,需要通过javascript与浏览器进行通信 - Alternative for java applet which needs to communicate with browser via javascript 使用Java串行通信jssc库的读写操作之间的巨大延迟 - Big delay between write and read operation using Java Serial communication jssc library 使用Applet + Javascript从客户端(浏览器)读取串行端口 - Read serial port from client(Browser) using Applet + Javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM