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

}

}

}

相关推荐
jack1868911 小时前
安卓手机忘记锁屏密码怎么办? 无需密码也可解锁
android·智能手机
应用市场14 小时前
不用一张图片的像素小游戏:小人是字符串,房间是矩形,平衡靠两千个假玩家
android·kotlin·游戏开发
stevenzqzq15 小时前
android 对渠道的理解
android
QEasycloud15 小时前
BOM接口抛转失败钉钉通知策略实战教程:MySQL异常日志到钉钉消息的端到端配置
android·mysql·钉钉
AIsoft_868915 小时前
医患交流内容如何做好记录?
android·iphone
蒸鱼Yuzheng16 小时前
Android Native 崩溃证据链:Tombstone、Build ID 与 Trace 如何联合归因
android·ndk·tombstone·调试符号·崩溃分析
事圆则缓16 小时前
Kotlin 变量与函数:把页面状态和行为写成清楚的契约
android·开发语言·kotlin
hunterandroid16 小时前
MVVM 迁移到 MVI:复杂页面状态如何收敛
android
妖星16 小时前
Android 开机动画定制:从 bootanimation.zip 到源码编译
android
临期冰淇淋17 小时前
MTK平台 安卓16 GMS报错修改
android·java·前端