In mina2.0, you can use serial transmission for connection, just like using TCP communication. Obtain Mina 2.0
You can download the latest Mina version. If you want to obtain Mina of other versions, you can check the developer manual if you have any questions.
Prerequisites
Prompt message:
If you want to access the serial port through a Java program, you need a local library (. DLL or. so depends on your operating system ). mina is using rxtx.org this: ftp://ftp.qbang.org/pub/rxtx/rxtx-2.1-7-bins-r2.zip. placed correctly. DLL or. so in JDK/JRE's JRE/lib/i386/path, or use-djava. library. path = argument specifically points to the local library path
Prompt message:
TheMina-transport-serialThe jar package is not completely included in the release. You can download it from here.
Connect to the serial port
Serial Communication only provides one ioconnector interface, because serial communication is based on point-to-point communication. This problem has been mentioned in the previous tutorial. To connect to a serial communication port, you must create a serialconne.
// create your connectorIoConnector connector = new SerialConnector()connector.setHandler( ... here your buisness logic IoHandler ... );
This is not much different from creating a socketconnector. Now you create an address to connect to a serial port.
SerialAddress portAddress=new SerialAddress( "/dev/ttyS0", 38400, 8, StopBits.BITS_1, Parity.NONE, FlowControl.NONE );
The first parameter is the serial port identifier. For Windows systems, serial ports are called "COM1", "com2 ",... for Linux and Unix systems, such as "/dev/ttys0", "/dev/ttys1", and "/dev/ttyusb0.
The remaining parameters depend on the device in use and the desired communication characteristics:
- Baud Rate
- Digit
- Parity
- Traffic Control Mechanism
Once this is done, the connector can connect to this address
ConnectFuture future = connector.connect( portAddress );future.await();IoSession sessin = future.getSession();
Look! Everything else is the same. You can add your own filter and decoder as you wish. To learn more about RS232, see: http://en.wikipedia.org/wiki/RS232
(Supplement: As this manual is constantly being updated, it may change. The last update date is. It is strongly recommended that you read the original document)