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

}

}

}

相关推荐
斗锋在干嘛28 分钟前
Android里面开子线程的方法
android
yangshuo128135 分钟前
WSA(Windows 安卓子系统)过检测教程
android
jiet_h2 小时前
Kotlin 中 集合 Collection 的扩展方法完全指南
android·开发语言·kotlin
吃饭了呀呀呀2 小时前
🐳 《Android》 安卓开发教程 - 自定义 Toast
android·后端
斗锋在干嘛4 小时前
在Android中问AMS 和 PMS的区别和作用
android
雯0609~5 小时前
PHP:将关联数组转换为索引数组的完整示例
android·oracle·php
Wgllss6 小时前
Android提升开发测试效率,程序员应该多干了些什么?
android·架构·android jetpack
兰琛6 小时前
Android免费实现excel文件(简单)转为PDF文件
android·pdf·excel
斗锋在干嘛6 小时前
Android 回答视频边播放边下载的问题
android·jvm·音视频
斗锋在干嘛6 小时前
Android 中Intent 相关问题
android