Didn't get a response to this. - josh
---------- Forwarded message ---------- From: Joshua Schell <[email protected]> Date: Wed, Jul 14, 2010 at 3:29 PM Subject: Serial messageReceived.. To: [email protected] Hi, I'm currently using the Apache MINA 2.0.0-RC1 build. The problem I am having is receiving messages after sending data to a device serially. I have verified that I should be receiving data through the use of other serial utility programs as well as using Java's "gnu.io.*" library. However, using the mina, nothing reaches the *messageReceived* method in the Handler class. I tried printing out a test string but the method is never called. This tells me that Im and not getting a proper response using the Mina serial api. The code is here: *(Note1: This is based off of the serial tutorial on your site. The second source after SerialClient.java is the Handler (SerialHandler.java) class that extends IoHandlerAdapter. The code below should compile and run on java 1.6.)* * **(Note2: I'm emailing you this since I'd rather use your Serial API which is much cleaner. I am currently using the TCP and eventually UDP API's for the same project and They are excellent for quick development. So, thanks.)* * ///////**BEGIN SERIALCLIENT/////////////////////* package com.esys.sts.device.monitor.serial.client; import org.apache.mina.core.future.ConnectFuture; import org.apache.mina.core.service.IoAcceptor; import org.apache.mina.core.service.IoConnector; import org.apache.mina.core.session.IoSession; import org.apache.mina.filter.codec.ProtocolCodecFilter; import org.apache.mina.filter.codec.textline.TextLineCodecFactory; import org.apache.mina.transport.serial.SerialAddress; import org.apache.mina.transport.serial.SerialConnector; import org.apache.mina.transport.serial.SerialAddress.DataBits; import org.apache.mina.transport.serial.SerialAddress.FlowControl; import org.apache.mina.transport.serial.SerialAddress.Parity; import org.apache.mina.transport.serial.SerialAddress.StopBits; import org.apache.mina.transport.socket.nio.NioSocketAcceptor; import com.esys.sts.device.monitor.helper.Printer; import com.esys.sts.device.monitor.tcp.filter.CodecFactory; public class SerialClient { /** * @param args */ public static void main(String[] args) { IoConnector connector = new SerialConnector(); connector.setHandler( new SerialHandler()); connector.getFilterChain().addLast("codec", new ProtocolCodecFilter( new TextLineCodecFactory())); SerialAddress portAddress = new SerialAddress( "COM1", 115200, DataBits.DATABITS_8, StopBits.BITS_2, Parity.NONE, FlowControl.NONE ); ConnectFuture future = null; try { future = connector.connect( portAddress ).await(); } catch (InterruptedException e1) { Printer.printException(SerialClient.class, e1); } future.awaitUninterruptibly(); IoSession session = future.getSession(); //Printer.println(""+session.getRemoteAddress()); connector.broadcast(">20WFFFFD1\r\n"); //connector.broadcast(">01L2DF\r\n"); //Printer.println(""+session.getReadMessages()); } } *///////END SERIALCLIENT////////////////////////////////////// * * ///////BEGIN SERIALHANDLER//////////////////////////////////////* package com.esys.sts.device.monitor.serial.client; import org.apache.mina.core.service.IoHandlerAdapter; import org.apache.mina.core.session.IdleStatus; import org.apache.mina.core.session.IoSession; import com.esys.sts.device.monitor.exceptions.UndefinedMethodException; import com.esys.sts.device.monitor.helper.Printer; public class SerialHandler extends IoHandlerAdapter { @Override public void exceptionCaught(IoSession ioSession, Throwable arg1) throws Exception { Printer.printException(SerialHandler.class, arg1); } @Override public void messageReceived(IoSession ioSession, Object message) throws Exception { Printer.println("messageReceived"); Printer.println((String) message); } @Override public void messageSent(IoSession ioSession, Object message) throws Exception { Printer.println("messageSent: " + (String)message); } @Override public void sessionClosed(IoSession ioSession) throws Exception { } @Override public void sessionCreated(IoSession ioSession) throws Exception { Printer.println("sessionCreated"); } @Override public void sessionIdle(IoSession ioSession, IdleStatus idleStatus) throws Exception { Printer.println( "IDLE " + ioSession.getIdleCount( idleStatus )); } @Override public void sessionOpened(IoSession ioSession) throws Exception { Printer.println("sessionOpened"); } } *///////END SERIALHANDLER////////////////////////////////////// * - josh
