GithubHelp home page GithubHelp logo

serial-comm-demo's Introduction

serial-comm-demo

本项目是Java串口通信的spring-boot-starter,可以轻易集成入spring-boot项目中,简单几步就可以方便的读写串口数据

支持windows、linux环境

使用方式:

1.下载serial-comm-demo-0.0.1-SNAPSHOT.jar,添加到项目中,在项目pom.xml中添加配置

<dependency>
    <groupId>org.vesalainen</groupId>
    <artifactId>comm</artifactId>
    <version>1.0.3</version>
</dependency>
<dependency>
    <groupId>com.example</groupId>
    <artifactId>serial-comm-demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/..jar包路径../serial-comm-demo-0.0.1-SNAPSHOT.jar</systemPath>
</dependency>

2.在项目配置文件如application.yml中添加串口配置,以下示意添加COM1、COM2两个串口,波特率均为9600

com:
  serial:
    ports:
      - { port: COM1, speed: 9600 }
      - { port: COM2, speed: 9600 }

3.实现SerialPortReader接口读取串口数据,注册到spring容器中

@Component
public class MySerialPortReader implements SerialPortReader {
    @Override
    public void read(String port, String msg) {
        if ("COM1".equals(port)) {
            System.out.println(msg);
        } 
    }
}

4.如果想向串口写数据,在业务类中注入SerialPortWriter

@Autowired
private SerialPortWriter serialPortWriter;

/**
 * 业务方法
 */
public void func() {
    /*业务代码*/
    serialPortWriter.write("COM2", "hello serial-comm-demo");
    /*业务代码*/
}

serial-comm-demo's People

Contributors

sdweizw avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.