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

}

}

}

相关推荐
我是好小孩5 小时前
【Android】布局优化:include、merge、ViewStub以及Inflate()源码浅析
android
GISer_Jing5 小时前
2025年Flutter与React Native对比
android·flutter·react native
MasterLi80236 小时前
我的读书清单
android·linux·学习
怪兽20146 小时前
fastjson在kotlin不使用kotlin-reflect库怎么使用?
android·开发语言·kotlin
彭同学学习日志6 小时前
Kotlin Fragment 按钮跳转报错解决:Unresolved reference ‘floatingActionButton‘
android·开发语言·kotlin
Gracker7 小时前
Android Perfetto 系列 9 - CPU 信息解读
android
Gracker7 小时前
Android Perfetto 系列 8:深入理解 Vsync 机制与性能分析
android
Gracker8 小时前
Android Perfetto 系列 07 - MainThread 和 RenderThread 解读
android
Gracker8 小时前
Android Perfetto 系列 5:Android App 基于 Choreographer 的渲染流程
android
Gracker8 小时前
Android Perfetto 系列 6:为什么是 120Hz?高刷新率的优势与挑战
android