android 控制主板串口

import com.fazecast.jSerialComm.SerialPort;

import java.nio.charset.StandardCharsets;

public class SendAndReceiveFromAllPorts {

public static void main(String[] args) {

SerialPort[] ports = SerialPort.getCommPorts();

// 统一的发送指令(16 进制)

byte[] sendCommand = new byte[]{0xAA, 0xBB, 0xCC};

for (SerialPort port : ports) {

port.openPort();

port.setBaudRate(9600);

// 发送指令

port.writeBytes(sendCommand, sendCommand.length);

// 接收响应

byte[] receiveBuffer = new byte[1024];

int numRead = port.readBytes(receiveBuffer, receiveBuffer.length);

if (numRead > 0) {

String receivedData = new String(receiveBuffer, 0, numRead, StandardCharsets.UTF_8);

System.out.println("从端口 " + port.getSystemPortName() + " 接收到的数据: " + receivedData);

}

port.closePort();

}

}

}

相关推荐
x***13391 小时前
【MyBatisPlus】MyBatisPlus介绍与使用
android·前端·后端
n***54382 小时前
【MySQL】MySQL内置函数--日期函数字符串函数数学函数其他相关函数
android·mysql·adb
z***75154 小时前
【Springboot3+vue3】从零到一搭建Springboot3+vue3前后端分离项目之后端环境搭建
android·前端·后端
程序员陆业聪4 小时前
Android模拟器检测全面指南:从基础到高级策略
android
2501_916008896 小时前
iOS 性能测试的深度实战方法 构建从底层指标到真实场景回放的多工具测试体系
android·ios·小程序·https·uni-app·iphone·webview
w***95496 小时前
SQL美化器:sql-beautify安装与配置完全指南
android·前端·后端
r***12386 小时前
若依微服务中配置 MySQL + DM 多数据源
android·mysql·微服务
ALex_zry7 小时前
MySQL连接数管理与优化实操经验分享
android·mysql·adb
apigfly8 小时前
深入Android系统(十三)Android的窗口系统
android·设计模式·源码
k***85848 小时前
【SpringBoot】【log】 自定义logback日志配置
android·前端·后端