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();

}

}

}

相关推荐
空中海几秒前
第四章:导航与路由
android
2501_916007472 小时前
iOS逆向工程:详细解析ptrace反调试机制的破解方法与实战步骤
android·macos·ios·小程序·uni-app·cocoa·iphone
空中海2 小时前
第三章:状态管理与 Jetpack 架构组件
android·架构
峥嵘life2 小时前
Android + Kiro AI软件开发实战教程
android·后端·学习
流星雨在线2 小时前
安卓路由技术选型调研
android·therouter·arouter
千里马学框架2 小时前
Ubuntu 24 搭建aosp源码环境详细笔记
android·linux·ubuntu·framework·安卓·aosp·源码环境
空中海3 小时前
安卓 第六章:主题、样式与国际化
android
Ehtan_Zheng3 小时前
7个Kotlin Delegate
android
用户69371750013843 小时前
2026 Android 开发,现在还能入行吗?
android·前端·ai编程
YBZha3 小时前
Android Camera2 + OpenGL 竖屏或横屏预览会有“轻微拉伸”
android