Mina2.0 user manual Chinese version-Chapter 6 Transmission section 2 based on serial transmission in Mina

Source: Internet
Author: User
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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.