I wnat to see in browser an status from an device connected on rs232
port
The java class for read from serial port is:
//Serial.java
import java.io.*;
import java.util.*;
import java.lang.*;
import javax.comm.*;
public class Serial implements SerialPortEventListener
{
SerialPort port;
CommPortIdentifier ID;
InputStream in;
OutputStream out;
String text1="ok";
public void alarm(){
try
{
ID = CommPortIdentifier.getPortIdentifier("COM1");
port = (SerialPort)ID.open("alarm",1000);
in = port.getInputStream();
out = port.getOutputStream();
port.notifyOnDataAvailable(true);
port.setSerialPortParams (19200, port.DATABITS_8, port.STOPBITS_1,
port.PARITY_NONE);
port.setFlowControlMode(port.FLOWCONTROL_NONE);
}
catch (Exception e) {}
}
public void serialEvent(SerialPortEvent e)
{
int data = 0;
String text1;
switch(e.getEventType())
{
case SerialPortEvent.DATA_AVAILABLE:
try
{
while (in.available() > 0)
{
data=in.read();
if ('S' == (char)data)
{
data=in.read();
update_status(data);
}
}
}
catch (IOException ev) {}
break;
}
}
public String update_status (int s)
{
int temp = s;
int val = temp & 0x01;
if (val==0x01)
text1 = "ok";
else
text1 = "not ok";
return text1;
}
}//end class
Tha jsp page is :
//RS232.jsp
<%@ page import="Serial" %>
<HTML>
<HEAD>
<TITLE>Using a JavaBean</TITLE>
</HEAD>
<BODY>
<% Serial rs232 = new Serial(); %>
The status is: <%= rs232.update_status() %>
</BODY>
</HTML>
I started Apache Tomcat 5.0 server (run on Winxp); I put RS232.jsp in
"webapps/Root" and Serial.class in "webapps/Root/WEB-INF/classes
On executing "http://localhost/RS232.jsp" I have an error :
//....................
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: -1 in the jsp file: null
Generated servlet error:
[javac] Compiling 1 source file
C:\Tomcat5\work\Catalina\localhost\_\org\apache\js p\RS232_jsp.java:6:
'.' expected
import Serial;
^
1 error
//...........................
What can be wrong????