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 byte1024;

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

}

}

}

相关推荐
GY-932 分钟前
【Android】适配不同的屏幕尺寸
android
Chenpip11 小时前
安卓 14/15 上装不上:四层原因与三行检查
android·app分发·应用分发·海哈游分发·内测
TT哇1 小时前
【Android 之旅】Android 通俗易懂记
android·gitee
雨白2 小时前
工厂设计模式实战:从简单工厂到抽象工厂的演进之路
android
Digitally2 小时前
7 种主流安卓设备备份与恢复方法
android
恋猫de小郭2 小时前
Flutter HC 旋转 ANR,而且还和之前的 HCPP 问题类似
android·前端·flutter
Digitally2 小时前
如何在安卓设备上备份和恢复通话记录:完整指南
android
StarsGreen2 小时前
Android 的graphicsstats 服务讲解
android
_祝你今天愉快2 小时前
Android 高级绘制:[六] 基于PathMeasure源码分析path测量问题
android
FungLeo3 小时前
FengCMS · PHP+MySQL 升级实录· PHP Session 锁:什么时候释放能救活并发
android·mysql·php·session·fengcms