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

}

}

}

相关推荐
2601_963771376 小时前
Offloading WP-Cron and Securing Ticket Webhooks on Enterprise IT Sites
android
花燃柳卧7 小时前
跨平台路由组件工程源码补充上传
android·flutter·kotlin
apihz7 小时前
随机驾考题目(C 照科一 / 科四 2000+ 题)免费API调用教程
android·java·c语言·开发语言·网络协议·tcp/ip
宸翰8 小时前
uni-app 设置 Android 底部虚拟导航栏背景色
android·前端·uni-app
TechNomad8 小时前
Kotlin类对象与接口详解
android·kotlin
QiLinkOS13 小时前
QiLink OS的失败数据共享平台的运作模式是否适用于所有行业?
android·开发语言·人工智能·算法·重构·开源
杉氧13 小时前
Framework 补完计划 (2):BufferQueue 与 SurfaceFlinger —— 像素的跨进程“接力赛”
android·架构·android jetpack
牢七13 小时前
RCE?复现成功
android
一化十13 小时前
Android16 自定义全局手势 任意界面依次点击屏幕四个角返回Home界面
android
三少爷的鞋15 小时前
Android 面试系列:Kotlin 协程的 delay 到底发生在哪个线程?
android