国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

SpringBoot+RXTXcomm實(shí)現(xiàn)Java串口通信 讀取串口數(shù)據(jù)以及發(fā)送數(shù)據(jù)

這篇具有很好參考價(jià)值的文章主要介紹了SpringBoot+RXTXcomm實(shí)現(xiàn)Java串口通信 讀取串口數(shù)據(jù)以及發(fā)送數(shù)據(jù)。希望對大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

記錄一下使用SpringBoot+RXTXcomm實(shí)現(xiàn)Java串口通信,使用Java語言開發(fā)串口,對串口進(jìn)行讀寫操作。

案例源碼:SpringBoot+RXTXcomm實(shí)現(xiàn)Java串口通信 讀取串口數(shù)據(jù)以及發(fā)送數(shù)據(jù)

RXTXcomm.jar這個(gè)包支持的系統(tǒng)較多,但是更新太慢,在win系統(tǒng)下使用沒有問題,但是在centos的工控機(jī)系統(tǒng)里使用讀取和發(fā)送有問題,至今沒能解決,報(bào)錯(cuò)的日志也記錄一下


serial port com start success
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f5e636f75da, pid=18871, tid=0x00007f5e635ee700
#
# JRE version: Java(TM) SE Runtime Environment (8.0_144-b01) (build 1.8.0_144-b01)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.144-b01 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [librxtxSerial.so+0x75da]  Java_gnu_io_RXTXPort_nativeDrain+0xea
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/hs_err_pid18871.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
已放棄
[root@localhost home]# 
Java HotSpot(TM) Server VM warning: You have loaded library /home/jdk18/jre/lib/i386/librxtxSerial.so which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
java.lang.UnsatisfiedLinkError: /home/jdk18/jre/lib/i386/librxtxSerial.so: /home/jdk18/jre/lib/i386/librxtxSerial.so: 錯(cuò)誤 ELF 類: ELFCLASS64 (Possible cause: architecture word width mismatch) thrown while loading gnu.io.RXTXCommDriver
15:33:11.580 spring-boot-logging [main] INFO  o.s.b.a.l.ConditionEvaluationReportLoggingListener - 

19:26:03.323 spring-boot-logging [main] INFO  c.z.d.serialport.SerialPortManager - open serial port success:/dev/ttyS1
serial port com start success
19:26:15.326 spring-boot-logging [Thread-5] INFO  c.z.data.serialport.SerialPortThread - stepCount--200
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007ffa604a7733, pid=17020, tid=0x00007ffa6019e700
#
# JRE version: Java(TM) SE Runtime Environment (8.0_144-b01) (build 1.8.0_144-b01)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.144-b01 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [librxtxSerial.so+0x7733]  Java_gnu_io_RXTXPort_nativeDrain+0xc3
#
# Core dump written. Default location: /usr/local/core or core.17020
#
# An error report file with more information is saved as:
# /usr/local/hs_err_pid17020.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
已放棄(吐核)


因此如果要使用RXTXcomm.jar這個(gè)串口包,建議在win系統(tǒng)下使用更好一些,其他系統(tǒng)使用可能出現(xiàn)莫名其妙的問題,如果非要在linux(centos)系統(tǒng)使用,推薦使用jSerialComm.jar

<dependency>
    <groupId>com.fazecast</groupId>
    <artifactId>jSerialComm</artifactId>
    <version>2.9.2</version>
</dependency>

這里記錄使用SpringBoot加RXTXcomm在win10系統(tǒng)下的使用
mfz-rxtx-2.2-20081207-win-x64的下載地址

http://fizzed.com/oss/rxtx-for-java

SpringBoot+RXTXcomm實(shí)現(xiàn)Java串口通信 讀取串口數(shù)據(jù)以及發(fā)送數(shù)據(jù)
根據(jù)自己的系統(tǒng)選擇對應(yīng)的下載包
SpringBoot+RXTXcomm實(shí)現(xiàn)Java串口通信 讀取串口數(shù)據(jù)以及發(fā)送數(shù)據(jù)
SpringBoot+RXTXcomm實(shí)現(xiàn)Java串口通信 讀取串口數(shù)據(jù)以及發(fā)送數(shù)據(jù)
從readme.txt得知編譯的環(huán)境特別舊了,將來的使用定然是越來越少

win-x86, win-x64, ia64
-----------------------------------------------
Built using Microsoft Visual C++ 2008 - not MinGW. The
x86 and x64 versions are native and do not rely on
any other non-standard windows libraries.  Just drop
in the compiled .dlls that are specific to the version
of Java you run. If you installed the 64-bit version
of the JDK, then install the x64 build.

I've tested the x86 and x64 version with Windows 2008,
2003, and Vista SP1.


linux-i386 & linux-x86_64
-----------------------------------------------
Built using CentOS 5.2 and gcc 4.1.2.

Just drop in the compiled .dlls that are specific to
the version of Java you run. If you installed the 64-bit
version of the JDK, then install the x64 build.

I've tested the x86 and x64 versions with x86 and x64
versions of CentOS 5.0 and 5.2.

SpringBoot+RXTXcomm實(shí)現(xiàn)Java串口通信 讀取串口數(shù)據(jù)以及發(fā)送數(shù)據(jù)
根據(jù)文檔,先將rxtxSerial.dll和rxtxParallel.dll放在指定的目錄內(nèi)
我自己電腦的JAVA_HOME
SpringBoot+RXTXcomm實(shí)現(xiàn)Java串口通信 讀取串口數(shù)據(jù)以及發(fā)送數(shù)據(jù)
那么文件存放位置
SpringBoot+RXTXcomm實(shí)現(xiàn)Java串口通信 讀取串口數(shù)據(jù)以及發(fā)送數(shù)據(jù)
至于 RXTXcomm.jar包不放在文檔里的位置,放在具體的項(xiàng)目內(nèi)引用(根據(jù)個(gè)人喜好來,我直接按照文檔的方式去放,發(fā)現(xiàn)不起作用)

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project 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">

    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>boot.example.mfz.rxtx</groupId>
    <artifactId>boot-example-serial-port-mfz-rxtx-2.0.5</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>boot-example-serial-port-mfz-rxtx-2.0.5</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>gnu.io</groupId>
            <artifactId>RXTXcomm</artifactId>
            <version>2.2</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/libs/jar/RXTXcomm.jar</systemPath>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.example.BootRXTXApplication</mainClass>
                    <includeSystemScope>true</includeSystemScope><!--外部進(jìn)行打包-->
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

這里有個(gè)點(diǎn)兒

<systemPath>${project.basedir}/libs/jar/RXTXcomm.jar</systemPath>

SpringBoot+RXTXcomm實(shí)現(xiàn)Java串口通信 讀取串口數(shù)據(jù)以及發(fā)送數(shù)據(jù)
BootRXTXApplication.java

package com.example;


import com.example.serialport.SerialPortManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import javax.annotation.PreDestroy;
import java.io.IOException;
import java.util.List;


@SpringBootApplication
@EnableScheduling
@EnableAsync
public class BootRXTXApplication implements CommandLineRunner {

    private final Logger log =  LoggerFactory.getLogger(this.getClass());

    public static void main(String[] args) throws IOException {
        SpringApplication.run(BootRXTXApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        try{
            List<String> portList = SerialPortManager.getSerialPortList();
            if(!portList.isEmpty()){
                log.info(portList.toString());
                SerialPortManager.connectSerialPort();
            }
        } catch (Exception e){
            log.error("獲取串口信息失敗");
        }

    }

    @PreDestroy
    public void destroy() {
        SerialPortManager.closeSerialPort();
        System.exit(0);
    }



}

測試往串口發(fā)數(shù)據(jù)
SerialPortSendController.java

package com.example.controller;

import com.example.serialport.ConvertHexStrAndStrUtils;
import com.example.serialport.SerialPortManager;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
public class SerialPortSendController {

    //  http://localhost:8781/sendTest?message=mywmyyhtw

    @GetMapping(value = "/sendTest")
    @ResponseBody
    public String sendStringTopic(@RequestParam(name="message",required = true) String message) throws Exception {
        SerialPortManager.sendSerialPortData(ConvertHexStrAndStrUtils.strToHexStr(message));
        return "success";
    }

}

字符串以及16進(jìn)制以及字節(jié)之間的轉(zhuǎn)換工具類ConvertHexStrAndStrUtils.java

package com.example.serialport;

import java.nio.charset.StandardCharsets;

public class ConvertHexStrAndStrUtils {

    private static final char[] HEXES = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

    public static String bytesToHexStr(byte[] bytes) {
        if (bytes == null || bytes.length == 0) {
            return null;
        }
        StringBuilder hex = new StringBuilder(bytes.length * 2);
        for (byte b : bytes) {
            hex.append(HEXES[(b >> 4) & 0x0F]);
            hex.append(HEXES[b & 0x0F]);
        }
        return hex.toString().toUpperCase();
    }

    public static byte[] hexStrToBytes(String hex) {
        if (hex == null || hex.length() == 0) {
            return null;
        }
        char[] hexChars = hex.toCharArray();
        byte[] bytes = new byte[hexChars.length / 2];   // 如果 hex 中的字符不是偶數(shù)個(gè), 則忽略最后一個(gè)
        for (int i = 0; i < bytes.length; i++) {
            bytes[i] = (byte) Integer.parseInt("" + hexChars[i * 2] + hexChars[i * 2 + 1], 16);
        }
        return bytes;
    }

    public static String strToHexStr(String str) {
        StringBuilder sb = new StringBuilder();
        byte[] bs = str.getBytes();
        int bit;
        for (int i = 0; i < bs.length; i++) {
            bit = (bs[i] & 0x0f0) >> 4;
            sb.append(HEXES[bit]);
            bit = bs[i] & 0x0f;
            sb.append(HEXES[bit]);
        }
        return sb.toString().trim();
    }

    public static String hexStrToStr(String hexStr) {
        //能被16整除,肯定可以被2整除
        byte[] array = new byte[hexStr.length() / 2];
        try {
            for (int i = 0; i < array.length; i++) {
                array[i] = (byte) (0xff & Integer.parseInt(hexStr.substring(i * 2, i * 2 + 2), 16));
            }
            hexStr = new String(array, StandardCharsets.UTF_8);
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
        return hexStr;
    }

}

串口工具類 我這里默認(rèn)寫死COM1 波特率9600
SerialPortManager.java

package com.example.serialport;

import gnu.io.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.TooManyListenersException;
import java.util.concurrent.TimeUnit;

public class SerialPortManager {

    private static final Logger log =  LoggerFactory.getLogger(SerialPortManager.class);

    public static String SERIAL_PORT_NUMBER = "COM1";

    public static final int SERIAL_BAUD_RATE = 9600;

    public static volatile long SERIAL_CALLBACK_TIME = System.currentTimeMillis()/1000;

    public static volatile boolean SERIAL_PORT_STATE = false;

    public static volatile SerialPort SERIAL_PORT_OBJECT = null;

    //  獲得系統(tǒng)可用的端口名稱列表
    @SuppressWarnings("unchecked")
    public static List<String> getSerialPortList() {
        List<String> systemPorts = new ArrayList<>();
        //獲得系統(tǒng)可用的端口
        Enumeration<CommPortIdentifier> portList = CommPortIdentifier.getPortIdentifiers();
        while (portList.hasMoreElements()) {
            String portName = portList.nextElement().getName();//獲得端口的名字
            systemPorts.add(portName);
        }
        return systemPorts;
    }

    public static void connectSerialPort(){
        try {
            closeSerialPort();
            TimeUnit.MILLISECONDS.sleep(4000);
            if(openSerialPort()){
                System.out.println("serial port com start success");
            }
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }

    //  打開串口  設(shè)置中斷和監(jiān)聽事件
    public static boolean openSerialPort() {
        try {
            CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(SERIAL_PORT_NUMBER);
            CommPort commPort = portIdentifier.open(SERIAL_PORT_NUMBER, 3000);
            if(commPort == null){return false;}
            //判斷是不是串口
            if (commPort instanceof SerialPort) {
                SerialPort serialPort = (SerialPort) commPort;
                //設(shè)置串口參數(shù)(波特率,數(shù)據(jù)位8,停止位1,校驗(yàn)位無)
                serialPort.setSerialPortParams(SERIAL_BAUD_RATE, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
                // 當(dāng)有數(shù)據(jù)到達(dá)時(shí)喚醒數(shù)據(jù)接收線程
                serialPort.notifyOnDataAvailable(true);
                // 當(dāng)串口連接中斷時(shí)喚醒中斷線程
                serialPort.notifyOnBreakInterrupt(true);
                serialPort.notifyOnCarrierDetect(true);
                serialPort.notifyOnDSR(true);
                // 添加串口監(jiān)聽事件
                serialPort.addEventListener(new SerialPortListener(new SerialPortCallback()));
                SerialPortManager.SERIAL_PORT_OBJECT = serialPort;
                SerialPortManager.SERIAL_PORT_STATE = true;
                log.info("open serial port success:" + SERIAL_PORT_NUMBER);
                return true;
            } else {
                //是其他類型的端口
                throw new NoSuchPortException();
            }
        } catch (NoSuchPortException e) {
            log.error("not find serial port:" + e.getMessage());
        } catch (PortInUseException e) {
            log.error("the serial port used:" + e.getMessage());
        } catch (UnsupportedCommOperationException e) {
            log.error("open others serial port:" + e.getMessage());
        } catch (TooManyListenersException e) {
            log.error("the more listener this serial port:"+ e.getMessage());
        }

        return false;
    }

    //  關(guān)閉串口
    public static void closeSerialPort() {
        SERIAL_PORT_STATE = false;
        if (SERIAL_PORT_OBJECT != null) {
            SERIAL_PORT_OBJECT.close();
            SERIAL_PORT_OBJECT = null;
            log.info("serial port close");
        }
    }

    //  向串口發(fā)送數(shù)據(jù)
    public static void sendSerialPortData(String data) {
        OutputStream outputStream = null;
        try {
            outputStream = SERIAL_PORT_OBJECT.getOutputStream();
            outputStream.write(ConvertHexStrAndStrUtils.hexStrToBytes(data));
            outputStream.flush();
            log.info("send data success:"+data);
        } catch (IOException e) {
            log.error("read data exception:"+e.getMessage());
        } finally {
            try {
                outputStream.close();
            } catch (IOException e) {
                log.error("read data inputStream close error:"+ e.getMessage());
            }
        }
    }

    //  從串口讀取數(shù)據(jù)
    public static byte[] readSerialPortData() {
        InputStream in = null;
        byte[] bytes = {};
        try {
            TimeUnit.MILLISECONDS.sleep(200);
            in = SERIAL_PORT_OBJECT.getInputStream();
            byte[] readBuffer = new byte[1];
            int bytesNum = in.read(readBuffer);
            while (bytesNum > 0) {
                bytes = concat(bytes, readBuffer);
                bytesNum = in.read(readBuffer);
            }
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return bytes;
    }


    public static byte[] concat(byte[] firstArray, byte[] secondArray) {
        if (firstArray == null || secondArray == null) {
            return null;
        }
        byte[] bytes = new byte[firstArray.length + secondArray.length];
        System.arraycopy(firstArray, 0, bytes, 0, firstArray.length);
        System.arraycopy(secondArray, 0, bytes, firstArray.length, secondArray.length);
        return bytes;
    }

}

SerialPortListener.java

package com.example.serialport;

import gnu.io.SerialPortEvent;
import gnu.io.SerialPortEventListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SerialPortListener implements SerialPortEventListener {

    private final Logger log =  LoggerFactory.getLogger(this.getClass());

    private final SerialPortCallback serialPortCallback;

    public SerialPortListener(SerialPortCallback serialPortCallback) {
        this.serialPortCallback = serialPortCallback;
    }

    public void serialEvent(SerialPortEvent serialPortEvent) {
        log.warn("SerialPortTestListener:"+serialPortEvent.getEventType());
        SerialPortManager.SERIAL_CALLBACK_TIME = System.currentTimeMillis()/1000;
        if (serialPortEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
            if (serialPortCallback != null) {
                serialPortCallback.dataAvailable();
            }
        }

    }




}

從串口接收數(shù)據(jù)的SerialPortCallback.java

package com.example.serialport;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SerialPortCallback {

    private final Logger log =  LoggerFactory.getLogger(this.getClass());

    public void dataAvailable() {
        try {
            //throw new Exception();
            byte[] data = SerialPortManager.readSerialPortData();
            String s = ConvertHexStrAndStrUtils.bytesToHexStr(data);
            log.info("rev--data:"+s);
        } catch (Exception e) {
            log.error(e.toString());
        }
    }



}

定時(shí)器SerialPortTimer.java

package com.example.serialport;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;


@Service
public class SerialPortTimer {


    @Async
    @Scheduled(cron = "0 0/5 * * * ?")
    public void timeSerialPortScheduled() throws IOException, InterruptedException {
        long now = System.currentTimeMillis();
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd:HH:mm:ss");
        System.out.println("timeSerialPortScheduled--"+format.format(now));
        long interval = 2 * 60 * 60;
        long rebootInterval = 24 * 60 * 60;
        long difference =  now/1000 - SerialPortManager.SERIAL_CALLBACK_TIME;

        // 當(dāng)2個(gè)小時(shí)內(nèi)收不到串口數(shù)據(jù)重啟串口
        if(difference > interval){
            SerialPortManager.connectSerialPort();
        }

        //  當(dāng)24小時(shí)內(nèi)都還是收不到串口數(shù)據(jù)重啟系統(tǒng)
        if(difference > rebootInterval){
            try {
                String osName = System.getProperty("os.name");
                if(osName.startsWith("Windows")) {
                    Runtime.getRuntime().exec("shutdown -r -t 0 -f");
                } else if(osName.startsWith("Linux")){
                    Runtime.getRuntime().exec("reboot");
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

    }

}

代碼結(jié)構(gòu)

│  pom.xml
│  
├─doc
│  │  mfz-rxtx-2.2-20081207-win-x64.zip
│  │  mfz-rxtx-2.2-20081207-win-x86.zip
│  │  
│  └─mfz-rxtx-2.2-20081207-win-x64
│          BuildProperties.txt
│          Install.txt
│          Readme.txt
│          ReleaseNotes.txt
│          RXTXcomm.jar
│          rxtxParallel.dll
│          rxtxSerial.dll
│          
├─libs
│  └─jar
│          jna.jar
│          RXTXcomm.jar
│          
├─src
│  ├─main
│  │  ├─java
│  │  │  └─com
│  │  │      └─example
│  │  │          │  BootRXTXApplication.java
│  │  │          │  
│  │  │          ├─controller
│  │  │          │      SerialPortSendController.java
│  │  │          │      
│  │  │          └─serialport
│  │  │                  ConvertHexStrAndStrUtils.java
│  │  │                  SerialPortCallback.java
│  │  │                  SerialPortListener.java
│  │  │                  SerialPortManager.java
│  │  │                  SerialPortTimer.java
│  │  │                  
│  │  └─resources
│  │          application.properties
│  │          logback-spring.xml
│  │          
│  └─test
│      └─java
│          └─com
│              └─example
│                      BootRXTXApplicationTest.java
│            

接收數(shù)據(jù)測試 通過com2 向 com1發(fā)送數(shù)據(jù) 那么就算SpringBoot串口接收數(shù)據(jù)
SpringBoot+RXTXcomm實(shí)現(xiàn)Java串口通信 讀取串口數(shù)據(jù)以及發(fā)送數(shù)據(jù)
可以看到控制臺有打印數(shù)據(jù)
SpringBoot+RXTXcomm實(shí)現(xiàn)Java串口通信 讀取串口數(shù)據(jù)以及發(fā)送數(shù)據(jù)
發(fā)送數(shù)據(jù)測試

http://localhost:8781/sendTest?message=mywmyyhtw

可以看到控制臺
SpringBoot+RXTXcomm實(shí)現(xiàn)Java串口通信 讀取串口數(shù)據(jù)以及發(fā)送數(shù)據(jù)
對應(yīng)的接收端
SpringBoot+RXTXcomm實(shí)現(xiàn)Java串口通信 讀取串口數(shù)據(jù)以及發(fā)送數(shù)據(jù)文章來源地址http://www.zghlxwxcb.cn/news/detail-443148.html

到了這里,關(guān)于SpringBoot+RXTXcomm實(shí)現(xiàn)Java串口通信 讀取串口數(shù)據(jù)以及發(fā)送數(shù)據(jù)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 【STM32】STM32F103C8T6串口通信,實(shí)現(xiàn)3個(gè)串口收發(fā)數(shù)據(jù)

    串口通信(Serial Communications)實(shí)現(xiàn)單片機(jī)與電腦或者其它外設(shè)進(jìn)行通信,通信時(shí)只需兩根線(TX,RX)就可以實(shí)現(xiàn)數(shù)據(jù)傳輸。STM32f103有三個(gè)串口,分別為串口1(RX PA10, TX PA 9),串口2(RX PA3,TX PA2),串口3(RX PB11,TX PB10)。 以下代碼是配置三個(gè)串口: usart.c usart.h main.c 注意,

    2024年02月12日
    瀏覽(28)
  • SpringBoot(java)實(shí)現(xiàn)websocket實(shí)現(xiàn)實(shí)時(shí)通信

    SpringBoot(java)實(shí)現(xiàn)websocket實(shí)現(xiàn)實(shí)時(shí)通信

    WebSockets是一種在Web應(yīng)用程序中實(shí)現(xiàn)實(shí)時(shí)通信的技術(shù)。它允許客戶端和服務(wù)器之間建立持久的、雙向的通信通道,從而使得服務(wù)器可以實(shí)時(shí)向客戶端推送數(shù)據(jù),而不需要客戶端不斷地向服務(wù)器發(fā)起請求。這種實(shí)時(shí)通信的能力對于需要即時(shí)更新數(shù)據(jù)的應(yīng)用程序非常有用,比如在線

    2024年04月29日
    瀏覽(30)
  • 關(guān)于Qt用多線程實(shí)現(xiàn)usb溫度傳感器(串口通信)的數(shù)據(jù)接收中遇到的問題及猜想(不一定正確)

    關(guān)于Qt用多線程實(shí)現(xiàn)usb溫度傳感器(串口通信)的數(shù)據(jù)接收中遇到的問題及猜想(不一定正確)

    由于是初學(xué),僅僅對串口編程有個(gè)了解,大概的功能是通過兩個(gè)按鈕實(shí)現(xiàn)串口數(shù)據(jù)的接收和暫停,其他的功能暫不深入研究。 通過串口調(diào)試助手發(fā)現(xiàn),該串口的屬性設(shè)置如左所示,接收的數(shù)據(jù)轉(zhuǎn)為字符串后顯示格式如右所示。這里是打算將右邊的溫度顯示在一個(gè)LCD控件中,效

    2024年02月01日
    瀏覽(25)
  • 采用串口中斷方式實(shí)現(xiàn)串口通信

    采用串口中斷方式實(shí)現(xiàn)串口通信

    中斷方式 中斷方式是處理器和外部設(shè)備的數(shù)據(jù)傳輸方式。一方通過申請中斷的方式與另一方進(jìn)行數(shù)據(jù)傳輸,收發(fā)雙方可以并行工作。 中斷系統(tǒng) 中斷裝置和中斷處理程序統(tǒng)稱為中斷系統(tǒng)。 中斷系統(tǒng)是計(jì)算機(jī)的重要組成部分。實(shí)時(shí)控制、故障自動(dòng)處理、計(jì)算機(jī)與外圍設(shè)備間的數(shù)

    2024年02月16日
    瀏覽(22)
  • Java 串口通信(RS232/485)

    Java 串口通信(RS232/485)

    Java 實(shí)現(xiàn)串口通信,同時(shí)通過 WebSocket 與 UI 實(shí)時(shí)交互傳遞通信數(shù)據(jù) 準(zhǔn)備工作: 虛擬串口工具:Launch Virtual Serial Port Driver 串口調(diào)試助手:SSCOM RS485 在線 CRC檢驗(yàn)碼計(jì)算:CRC 測試鏈接 1.擴(kuò)展包和依賴庫 以上兩個(gè)包可以直接網(wǎng)上下載,注意和JDK版本搭配即可 2.Pom配置 串口通信包:

    2024年02月13日
    瀏覽(23)
  • Labview串口通信VISA實(shí)現(xiàn)串口收發(fā)

    Labview串口通信VISA實(shí)現(xiàn)串口收發(fā)

    前面使用過調(diào)用 MSComm 控件的方式(Labview串口通信MSComm實(shí)現(xiàn)串口收發(fā)),即利用 Windows 提供的控件對象,在 LabVIEW 中對該控件的屬性和方法進(jìn)行操作,來實(shí)現(xiàn)串口通信。之所以使用 MSComm 控件,是因?yàn)楸仁褂?VISA 來實(shí)現(xiàn)串口通信要靈活一些,比如可以通過回調(diào)的方式,在 PC 的

    2024年02月15日
    瀏覽(23)
  • Labview串口通信MSComm實(shí)現(xiàn)串口收發(fā)

    Labview串口通信MSComm實(shí)現(xiàn)串口收發(fā)

    本文介紹使用 ActiveX 控件 MSComm 實(shí)現(xiàn)高性能的串口收發(fā)。 MSComm 作為一個(gè)串行通訊控件,每個(gè) MSComm 控件,都對應(yīng)一個(gè)串口,若需訪問多個(gè)串口時(shí)必須使用多個(gè) MSComm 控件。 MSComm 是 ActiveX 控件,可以在 PC 上控制串口數(shù)據(jù)的發(fā)送和接收,支持查詢方式和中斷方式(Windows 下稱為事

    2024年02月15日
    瀏覽(19)
  • 【Python】串口通信-與FPGA、藍(lán)牙模塊實(shí)現(xiàn)串口通信(Python+FPGA)

    【Python】串口通信-與FPGA、藍(lán)牙模塊實(shí)現(xiàn)串口通信(Python+FPGA)

    ??歡迎來到Python專欄~與FPGA、藍(lán)牙模塊實(shí)現(xiàn)串口通信 ☆* o(≧▽≦)o *☆ 嗨 ~我是 小夏與酒 ?? ? 博客主頁: 小夏與酒的博客 ??該系列 文章專欄: Python學(xué)習(xí)專欄 文章作者技術(shù)和水平有限,如果文中出現(xiàn)錯(cuò)誤,希望大家能指正?? ?? 歡迎大家關(guān)注! ?? Python與FPGA串口通信

    2024年02月15日
    瀏覽(20)
  • STM32 串口 DMA 數(shù)據(jù)讀取(詳細(xì)代碼)

    最近重新開始學(xué)32,搞到串口 DMA 的時(shí)候, 數(shù)據(jù)讀取卡了很長一段時(shí)間,最終,功夫不負(fù)有心人終于搞出來了。在此以記錄一下,方便以后查詢使用。 在調(diào)試的過程中也遇到了很多bug,有些簡直就是低級問題,但是還是卡了很久,在此寫出來給自己加深印象,同時(shí)已給后來者

    2024年02月16日
    瀏覽(16)
  • 串口通信實(shí)現(xiàn)-串口接收(vivado&verilog版)

    串口通信實(shí)現(xiàn)-串口接收(vivado&verilog版)

    串口系列知識分享: (1)串口通信實(shí)現(xiàn)-串口發(fā)送 (2)串口通信發(fā)送多字節(jié)數(shù)據(jù) (3)串口通信實(shí)現(xiàn)-串口接收 (4)UART 通信-使用VIO進(jìn)行板級驗(yàn)證 (5)串口接收-控制LED閃爍 (6)使用串口發(fā)送實(shí)現(xiàn)ACX720開發(fā)板時(shí)鐘顯示 (7)串口發(fā)送+RAM+VGA傳圖 此文介紹uart串口協(xié)議(串口接

    2024年02月12日
    瀏覽(43)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包