tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Donald Horrell \(BT\)" <>
Subject How do I configure Tomcat to write to a Serial Port?
Date Sat, 02 Oct 2004 13:04:39 GMT
I've downloaded and installed the Java Communications API (version 2) and 
Tomcat 5.0.25. The whole lot uses Java 1.4.0.

My servlet is below, but when I invoke it, I get a log and an exception:
"Serial port is already in use."
 org.apache.catalina.valves.ErrorReportValve.invoke( org.apache.coyote.tomcat5.CoyoteAdapter.service(
org.apache.coyote.http11.Http11Processor.process( org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection( org.apache.tomcat.util.threads.ThreadPool$ some point, I'm going to need to find a way of limiting
the poolsize forthis servlet to 1 only too.CheersDon.--------------------------------Source:package
java.util.Enumeration;import javax.comm.*;import javax.servlet.ServletException;import javax.servlet.SingleThreadModel;import
javax.servlet.http.*;public class Send extends HttpServlet implements SingleThreadModel{ 
 /** The output stream which writes to the Com port. */   PrintWriter out = null;   public
void init() throws ServletException   {      // Open the serial port.      Enumeration portList
= CommPortIdentifier.getPortIdentifiers();      while (portList.hasMoreElements())      {
        CommPortIdentifier portId = (CommPortIdentifier)portList.nextElement();         if
(portId.getPortType() == CommPortIdentifier.PORT_SERIAL)         {            //if (portId.getName().equals("/dev/term/a"))
{            if (portId.getName().equals("COM1"))            {               SerialPort serialPort
= null;               try               {                  serialPort = (SerialPort)("SendApplet",2000));
                 out = new PrintWriter(serialPort.getOutputStream());                  serialPort.setSerialPortParams(9600,
          SerialPort.PARITY_NONE);               }               catch (PortInUseException
e)               {                  System.out.println("Serial port is already in use.");
                 throw(new ServletException());               }               catch (IOException
e)               {                  System.out.println("Failed to connect to output stream.");
                 throw(new ServletException());               }               catch (UnsupportedCommOperationException
e)               {                  System.out.println("Failed to set comms params.");   
              throw(new ServletException());               }            }         }      }
  }   public void destroy()   {   // Release the serial port.   }   public void doGet(HttpServletRequest
req, HttpServletResponse resp)   {      System.out.println("doGet.");      doWork(req, resp);
  }   public void doPost(HttpServletRequest req, HttpServletResponse resp)   {      System.out.println("doPost.");
     doWork(req, resp);   }   public void doWork(HttpServletRequest req, HttpServletResponse
resp)   {      // Take the msg param and send it to COM1.      String msg = req.getParameter("msg");
     System.out.println("Sending["+msg+"].");      if (msg != null)      {         out.println(msg);
     }   }}

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message