1
애플릿이 rxtxComm.jar을 통해 직렬 포트에 액세스하기 위해 프로그램 사용 애플릿을 작성하면 java.policy가 변경되므로 서명없이 직렬 포트에 액세스 할 수 있습니다. . Windows에서 실행되는 프로그램은 효과적입니다.하지만 우분투에는 몇 가지 예외가 있습니다 (java.lang.reflect.InvocationTargetException 및 "npobject에서 오류를 호출하는 메서드").이 문제를 해결하기 위해 많은 것을 보냈습니다. 구글로 갈 때, 나는 풀 수 없었다. 같은 문제가있는 사람이 있니? 이 프로그램에 대한 코드는 다음과 같습니다.어떻게 애플릿을 rxtxComm.jar을 통해 직렬 포트에 보낼 수 있습니까? 우분투의 경우
print.html :
function print() {
var zplText = $("#zplText").val();
document.printApplet.print(zplText);
}
<textarea rows="5" cols="6" id="zplText"></textarea>
<a href="#" onClick="print()">print</a>
<applet id="printApplet" alt="" codebase=.. code="zpl/ZplPrint.class">
<PARAM NAME="archive" VALUE="../lib/RXTXcomm.jar">
</applet>
ZplPrint.java :
public class ZplPrint extends Applet {
static String zpl;
static CommPortIdentifier portId;
static CommPort commPort;
static SerialPort serialPort;
@SuppressWarnings("rawtypes")
static Enumeration portList;
static OutputStream out;
public void print(String zplText) {
zpl = zplText;
if (zpl == null) {
return;
}
byte[] zplByte = zpl.getBytes();
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
try {
commPort = portId.open(portId.getName(), 2000);
serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
out = serialPort.getOutputStream();
out.write(zplByte);
commPort.close();
} catch (PortInUseException e) {
e.printStackTrace();
} catch (UnsupportedCommOperationException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
System.out.println("Find CommPort: " + portId.getName());
}
}
}
java.policy :
- 권한 java.lang.RuntimePermission의 " loadLibrary.rxtxSerial ";
- permission java.io.FilePermission "$ {java.home} $ {/} lib $ {/} ext $ {/} x86 $ {/} rxtxSerial.dll", "read";
- permission java.util.PropertyPermission "gnu.io.log.mode", "read";
- 권한 java.util.PropertyPermission "gnu.io.SerialPorts", "write, read";
- permission java.util.PropertyPermission "gnu.io.rxtx.SerialPorts", "read, write";
- permission java.util.PropertyPermission "gnu.io.ParallelPorts", "read";
- permission java.util.PropertyPermission "gnu.io.rxtx.ParallelPorts", "read";
- permission java.lang.RuntimePermission "modifyThreadGroup";
- permission java.lang.RuntimePermission "modifyThread";
첫 행 및 제 우분투는 우분투 다르다 :
- 권한 java.lang.RuntimePermission의 "loadLibrary.librxtxSerial";
- permission java.io.FilePermission "$ {java.home} $ {/} lib $ {/} amd64 $ {/} librxtxSerial.so", "read";
* "java.policy를 변경하므로 애플릿은 서명없이"직렬 포트에 액세스 할 수 있습니다. * 사용자 컴퓨터에서 정책 파일을 변경할 수 없다는 가정하에이 앱을 배포하는 유일한 실제 방법을 제안합니다. 디지털 서명되어 있습니다. –
귀하의 조언을 주셔서 감사합니다. 프로그램이 회사의 소수 PC에서 실행되기 때문에 서명이 까다 롭습니다. – htwj1998