Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback, please email oracle-forums_moderators_us@oracle.com

JSP RS232

843838Dec 29 2005 — edited Dec 29 2005
i want to put in a web page data received from serial port...but i
don't receive anything in page.
Please say me how can i resolve this problem....
//// Serial.java
package test;

import java.io.*;
import java.lang.*;
import javax.comm.*;
import java.util.*;

public class Serial implements SerialPortEventListener
{

private SerialPort port;
private CommPortIdentifier ID; //COM1

private InputStream in;
private OutputStream out;
private int data;

public Serial(){

try
{
ID = CommPortIdentifier.getPortIdentifier("COM1");
port = (SerialPort)ID.open("Serial",2000);
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)
{

switch(e.getEventType())
{
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
case SerialPortEvent.DATA_AVAILABLE:
try
{
while (in.available() > 0)
{
data=in.read();
executa(data);
}
}
catch (IOException ev) {}
break;
}
}

public void executa (int data){

this.data=data;
}


public int arata(){

return data;
}

} //end class





///// Rs232.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<META http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<TITLE>weather_data.jsp</TITLE>
</HEAD>

<BODY>
<% test.Serial wb = new test.Serial(); %>
<P>data received <%=wb.arata() %></P>

</BODY>
</HTML>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 7 2023
Added on Dec 29 2005
2 comments
138 views