Hello all,
I need some help because I am not able to access the serial port through a
Java applet in Java 2. This is my configuration:
- Java 2 (JDK 1.2) running under Win98.
- javacomm20 installed according to the documentation.
- win32comm.dll in many places: <JDK>\bin, <JRE>\bin, ., etc.
- java.policy (in <JRE>\lib\security\):
grant {
permission java.security.AllPermission;
};
I tried to run the simplest example from the COMM API samples:
SimpleWrite.java. The program works fine when executed as an standalone
application:
------
Port list: javax.comm.CommPortEnumerator@d8e8ecf0Port id:
javax.comm.CommPortIdentifier@df54ecf0Found COM1Port in
usejavax.comm.PortInUseException: Port currently owned by Unknown Windows
Application at javax.comm.CommPortIdentifier.open(Compiled Code) at
SimpleWrite.main(Compiled Code)java.lang.NullPointerException at
SimpleWrite.main(Compiled Code)Exception in thread "main" Process Exit...
------
(ok, the output is right because my mouse is owning COM1)
But this is the output when runned like an applet:
------
Caught java.lang.IllegalArgumentException: name can't be null while
loading driver com.sun.comm.Win32DriverPort list:
javax.comm.CommPortEnumerator@30f8ec74------
(and the program stops without any aditional information. See, at the
code, where it stops).
This is the output with both appletviewer and Java2 Plug-In.
Could anyone, please, help me??
Jes�s Pa�l
---------------------------------
CODE:
---------------------------------
----------
SimpleWrite.java
----------
import java.io.*;
import java.util.*;
import javax.comm.*;
public class SimpleWrite {
static Enumeration portList;
static CommPortIdentifier portId;
static String messageString = "Hello, world!\n";
static SerialPort serialPort;
static OutputStream outputStream;
public static void main(String[] args) {
portList = CommPortIdentifier.getPortIdentifiers();
System.out.println("Port list: "+portList);
while (portList.hasMoreElements()) {
//
// THE APPLET DOES NOT REACH HERE!!!
//
portId = (CommPortIdentifier) portList.nextElement();
System.out.println("Port id: "+portId);
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals("COM1")) {
//if (portId.getName().equals("/dev/term/a")) {
System.out.println("Found COM1");
try {
serialPort = (SerialPort)
portId.open("SimpleWriteApp", 2000);
} catch (PortInUseException e) {
System.out.println("Puerto in use");
e.printStackTrace();
}
try {
outputStream = serialPort.getOutputStream();
} catch (IOException e) {
e.printStackTrace();
}
try {
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {
e.printStackTrace();
}
try {
outputStream.write(messageString.getBytes());
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
}
---------
AppSimple.java
---------
import java.applet.*;
public class AppSimple extends Applet{
public void init(){
try{
String[] args=new String[0];
SimpleWrite.main(args);
} catch (Exception e){
e.printStackTrace();
}
}
}
---------
simple.html
---------
Simple Write Applet
<applet code=AppSimple.class width=100 height=100></applet>
Visit the OpenCard Framework's WWW site at http://www.opencard.org/ for
access to documentation, code, presentations, and OCF announcements.
-----------------------------------------------------------------------------
To unsubscribe from the OCF Mailing list, send a mail to
"[EMAIL PROTECTED]" with the word "unsubscribe" in the BODY of the
message.