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

}

}

}

相关推荐
gregmankiw5 小时前
Nemotron架构(Mamba3+Transformer+Moe)
android·深度学习·transformer
xianjian09126 小时前
MySQL 的 INSERT(插入数据)详解
android·数据库·mysql
欧简墨7 小时前
kotlin Android Extensions插件迁移到viewbinding总结
android·trae
货拉拉技术8 小时前
优雅解决Android app后台悬浮窗权限问题
android
用户69371750013848 小时前
Android 手机终于能当电脑用了
android·前端
用户5172231574809 小时前
android资源类型与布局资源详细介绍
android
优选资源分享9 小时前
GKD v1.11.6 | 安卓开屏广告跳过工具 可用版
android
robotx10 小时前
安卓zygote启动相关
android
Mac的实验室11 小时前
2026年最新真实社交怎么注册?手把手教你如何成功注册Truth Social账号
android
毕设源码-郭学长11 小时前
【开题答辩全过程】以 基于Android的点餐APP的设计为例,包含答辩的问题和答案
android