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

}

}

}

相关推荐
00后程序员张27 分钟前
从审核被拒到稳定过审,iOS 上架技术优化
android·ios·小程序·https·uni-app·iphone·webview
不会写DN4 小时前
PHP 中的文件读写与上传
android·开发语言·php
冬奇Lab6 小时前
Android 15音频子系统(七):音量控制系统深度解析
android·音视频开发
方白羽10 小时前
Android NFC 功能集成-读卡器模式
android·app·客户端
进击的cc10 小时前
Android Kotlin:委托属性深度解析
android·kotlin
进击的cc10 小时前
Android Kotlin:Kotlin数据类与密封类
android·kotlin
恋猫de小郭10 小时前
你的蓝牙设备可能正在泄漏你的隐私? Bluehood 如何追踪附近设备并做隐私分析
android·前端·ios
私人珍藏库11 小时前
[Android] 卫星地图 共生地球 v1.1.22
android·app·工具·软件·多功能
冰珊孤雪11 小时前
Android Studio Panda革命性升级:内存诊断、构建标准化与AI调试全解析
android·前端
_李小白12 小时前
【OSG学习笔记】Day 23: ClipNode(动态裁剪)
android·笔记·学习