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

}

}

}

相关推荐
泡泡以安2 小时前
Unidbg学习笔记(十三):固定随机干扰项
android·逆向
泡泡以安2 小时前
Unidbg学习笔记(十六):Console Debugger
android·逆向
赏金术士2 小时前
Room + Flow 完整教程(现代 Android 官方方案)
android·kotlin·room·compose
泡泡以安2 小时前
Unidbg学习笔记(八):文件系统层补环境
android·逆向
泡泡以安2 小时前
Unidbg学习笔记(六):补环境的思维框架
android·逆向
通往曙光的路上2 小时前
mysql2
android·adb
木易 士心3 小时前
会见SDK文档
android
Co_Hui3 小时前
Android:多线程
android
赏金术士3 小时前
Kotlin 协程面试题大全(Android 高频版)
android·开发语言·kotlin
y小花4 小时前
DRM-Direct Rendering Manager
android·drm