Spero che tutto questo serva a qualcun'altro :-)
ecco qui il codice:
codice:
package microcom;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JApplet;
import gnu.io.*;
import java.io.*;
import java.util.*;
public class comApplet extends JApplet {
static Enumeration portList;
static CommPortIdentifier portId;
static String messageString = "\"articolo\"500H1R\n1T";
static String param = "";
static SerialPort serialPort;
static OutputStream outputStream;
/**
* Initialization method that will be called after the applet is loaded
* into the browser.
*/
@Override
public void init() {
try {
Class.forName("gnu.io.CommPortIdentifier");
//System.setSecurityManager(null);
} catch (ClassNotFoundException ex) {
Logger.getLogger(comApplet.class.getName()).log(Level.SEVERE, null, ex);
}
comApplet.class.getClassLoader().getResource("RXTXcomm.jar");
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals("COM1")) {
//if (portId.getName().equals("/dev/term/a")) {
try {
serialPort = (SerialPort)
portId.open("SimpleWriteApp", 2000);
} catch (PortInUseException e) {
Logger.getLogger(comApplet.class.getName()).log(Level.SEVERE, null, e);
}
try {
outputStream = serialPort.getOutputStream();
} catch (IOException e) {
Logger.getLogger(comApplet.class.getName()).log(Level.SEVERE, null, e);
}
try {
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {
Logger.getLogger(comApplet.class.getName()).log(Level.SEVERE, null, e);
}
try {
outputStream.write(messageString.getBytes());
} catch (IOException e) {
Logger.getLogger(comApplet.class.getName()).log(Level.SEVERE, null, e);
}
}
}
}
System.exit(0);
}
// TODO overwrite start(), stop() and destroy() methods
}