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

}

}

}

相关推荐
summerkissyou198717 分钟前
Android-Audio-编码和解码
android·audio
dawudayudaxue22 分钟前
Eclipse安卓环境配置
android·java·eclipse
曾经我也有梦想26 分钟前
Day5 Kotlin 协程
android
00后程序员张36 分钟前
iOS上架工具,AppUploader(开心上架)用于证书生成、描述文件管理Xcode用于应用构建
android·macos·ios·小程序·uni-app·iphone·xcode
2501_915921431 小时前
只有 IPA 没有源码时,如何给 iOS 应用做安全处理
android·安全·ios·小程序·uni-app·iphone·webview
恋猫de小郭1 小时前
Flutter 3.41 iOS 键盘负优化:一个代码洁癖引发的负优化
android·前端·flutter
十六年开源服务商1 小时前
2026年WordPress网站安全检测服务避坑指南
android·安全
一直向钱2 小时前
android stutio 安装Ai插件写代码
android
linchare2 小时前
[原创]如何排查php-fpm的502报错(SIGSEGV)
android