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

}

}

}

相关推荐
天青Giser1 小时前
Android开发记录
android
子春一2 小时前
Flutter 与原生平台深度集成:打通 iOS 与 Android 的最后一公里
android·flutter·ios
小邓   ༽3 小时前
全场景Android测试:API、工具与案例,从TestCase到Mock类应用指南
android·android 测试·android 组件测试·mock 类·测试 api 应用·组件测试核心
享哥。6 小时前
android MVP模式代码示例
android
qq_717410017 小时前
删除设置-流量使用情况、更多
android
QuantumLeap丶7 小时前
《Flutter全栈开发实战指南:从零到高级》- 23 -混合开发与WebView
android·flutter·ios
_李小白9 小时前
【Android FrameWork】延伸阅读:ViewRootImpl如何管理整个view世界
android
Yang-Never10 小时前
Open GL ES->以指定点为中心缩放图片纹理的完整图解
android·java·开发语言·kotlin·android studio
介一安全10 小时前
【Frida Android】实战篇11:企业常用加密场景 Hook(1)
android·网络安全·逆向·安全性测试·frida