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

}

}

}

相关推荐
nono牛1 小时前
ps -A|grep gate
android
未知名Android用户2 小时前
Android动态变化渐变背景
android
nono牛3 小时前
Gatekeeper 的精确定义
android
stevenzqzq4 小时前
android启动初始化和注入理解3
android
城东米粉儿6 小时前
compose 状态提升 笔记
android
粤M温同学7 小时前
Android 实现沉浸式状态栏
android
ljt27249606617 小时前
Compose笔记(六十八)--MutableStateFlow
android·笔记·android jetpack
stevenzqzq8 小时前
Android Studio 断点调试核心技巧总结
android·ide·android studio
aqi009 小时前
FFmpeg开发笔记(九十八)基于FFmpeg的跨平台图形用户界面LosslessCut
android·ffmpeg·kotlin·音视频·直播·流媒体