SpringBoot整合Mina串口通讯

整合串口
@Configuration
public class SerialServer {

    private static Log log = LogFactory.getLog(SerialServer.class);
    public static String PORT = PropertyUtil.getProperty("COM_PORT");

    @Bean
    public LoggingFilter loggingFilter() {
        return new LoggingFilter();
    }

    @Bean
    public SerialProtocolCodecFactory serialProtocolCodecFactory() {
        return new SerialProtocolCodecFactory();
    }
    @Bean
    public IoHandlerAdapter ioHandlerAdapter() {
        return new SerialHandler();
    }


    ConnectFuture future ;

    private SerialPooler pooler;

    @Bean
    public SerialConnector serialCon()
    {
        //创建串口连接
        SerialConnector connector = new SerialConnector();
        //绑定处理handler
        connector.setHandler(ioHandlerAdapter());
        //设置过滤器
        connector.getFilterChain().addLast("logger",loggingFilter());
        connector.getFilterChain().addLast("codec",
                new ProtocolCodecFilter(serialProtocolCodecFactory()));
        //配置串口连接
        SerialAddress address = new SerialAddress
                (PORT, 9600, DataBits.DATABITS_8,StopBits.BITS_1 , Parity.NONE, FlowControl.NONE);

        future = connector.connect(address);
        try {
            future.await();
//       IoSession sessin = future.getSession();
            pooler= new SerialPooler();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        log.info("Serial Server Started");
        return connector;
    }

    public void close()
    {
        future.cancel();
        log.info("UDP Server closed");
    }
}
 
  
打包整理
 
  

xml version="1.0" encoding="UTF-8"?>
xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    4.0.0
    jar

    com.natop
    goes2
    1.0-SNAPSHOT

    
        org.springframework.boot
        spring-boot-starter-parent
        1.2.5.RELEASE
    

    
        UTF-8
        3.2.9.RELEASE
        2.4.4
        1.7
    

    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
       
        
            org.springframework.boot
            spring-boot-starter-thymeleaf
        
        
            org.springframework.boot
            spring-boot-starter-jdbc
        
        
            org.springframework.boot
            spring-boot-starter-actuator
        


        
            org.mybatis
            mybatis-spring
            1.2.2
        
        
            org.mybatis
            mybatis
            3.2.8
        

        
            org.apache.tomcat
            tomcat-jdbc
        

        
            mysql
            mysql-connector-java
        

        
        
            com.alibaba
            fastjson
            1.1.43
        
        
        
            io.springfox
            springfox-swagger2
            2.2.2
        
        
            io.springfox
            springfox-swagger-ui
            2.2.2
        

        
            com.fasterxml.jackson.core
            jackson-annotations
            ${version.jackson}
        
        
            com.fasterxml.jackson.core
            jackson-databind
            ${version.jackson}
        
        
            com.fasterxml.jackson.core
            jackson-core
            ${version.jackson}
        

        
            org.apache.mina
            mina-core
            2.0.9
        
        
            org.apache.mina
            mina-transport-apr
            2.0.9
        
        
            org.apache.mina
            mina-transport-serial
            2.0.9
        

        
            com.google.code.gson
            gson
            2.2.4
        
        
            org.bidib.jbidib.org.qbang.rxtx
            rxtxcomm
            2.2
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
                
                    true
                
            
            
                org.apache.felix
                maven-bundle-plugin
                true
            

            
           
        
    
    
        
            spring-milestone
            https://repo.spring.io/libs-release
        
    

    
        
            spring-milestone
            https://repo.spring.io/libs-release
        
    



你可能感兴趣的:(SpringBoot整合Mina串口通讯)