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

}

}

}

相关推荐
秃了也弱了。26 分钟前
MySQL空间函数详解,MySQL记录经纬度并进行计算
android·数据库·mysql
.豆鲨包1 小时前
【Android】Binder机制浅析
android·binder
Nerve3 小时前
GooglePay: API 文档
android·google
Nerve3 小时前
GooglePay: 订阅商品购买流程
android·google
summerkissyou19873 小时前
Audio-触摸音-播放流程
android
Nerve3 小时前
GooglePay: 消耗商品购买流程
android·google
LiteHeaven3 小时前
Android 8.1 Unable to create application data 问题分析
android
Nerve4 小时前
GooglePay: 一个基于 Google Play Billing Library 封装的 Android 支付库
android·google
Nerve4 小时前
Google Play 结算系统入门指南
android·google
青莲8434 小时前
Android Jetpack - 2 ViewModel
android·前端