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 SerialPortEvent Listener
{
SerialPort port;
CommPortIdentif ier ID;
InputStream in;
OutputStream out;
String text1="ok";
public void alarm(){
try
{
ID = CommPortIdentif ier.getPortIden tifier("COM1");
port = (SerialPort)ID. open("alarm",10 00);
in = port.getInputSt ream();
out = port.getOutputS tream();
port.notifyOnDa taAvailable(tru e);
port.setSerialP ortParams (19200, port.DATABITS_8 , port.STOPBITS_1 ,
port.PARITY_NON E);
port.setFlowCon trolMode(port.F LOWCONTROL_NONE );
}
catch (Exception e) {}
}
public void serialEvent(Ser ialPortEvent e)
{
int data = 0;
String text1;
switch(e.getEve ntType())
{
case SerialPortEvent .DATA_AVAILABLE :
try
{
while (in.available() > 0)
{
data=in.read();
if ('S' == (char)data)
{
data=in.read();
update_status(d ata);
}
}
}
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_st atus() %>
</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.jasp er.JasperExcept ion: 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\local host\_\org\apac he\jsp\RS232_js p.java:6:
'.' expected
import Serial;
^
1 error
//............... ............
What can be wrong????
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 SerialPortEvent Listener
{
SerialPort port;
CommPortIdentif ier ID;
InputStream in;
OutputStream out;
String text1="ok";
public void alarm(){
try
{
ID = CommPortIdentif ier.getPortIden tifier("COM1");
port = (SerialPort)ID. open("alarm",10 00);
in = port.getInputSt ream();
out = port.getOutputS tream();
port.notifyOnDa taAvailable(tru e);
port.setSerialP ortParams (19200, port.DATABITS_8 , port.STOPBITS_1 ,
port.PARITY_NON E);
port.setFlowCon trolMode(port.F LOWCONTROL_NONE );
}
catch (Exception e) {}
}
public void serialEvent(Ser ialPortEvent e)
{
int data = 0;
String text1;
switch(e.getEve ntType())
{
case SerialPortEvent .DATA_AVAILABLE :
try
{
while (in.available() > 0)
{
data=in.read();
if ('S' == (char)data)
{
data=in.read();
update_status(d ata);
}
}
}
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_st atus() %>
</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.jasp er.JasperExcept ion: 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\local host\_\org\apac he\jsp\RS232_js p.java:6:
'.' expected
import Serial;
^
1 error
//............... ............
What can be wrong????
Comment