| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- package com.zksy.lamp.server;
- import org.springframework.stereotype.Component;
- import org.springframework.stereotype.Service;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- /**
- * @author Administrator
- * @version 1.0
- * @project dh-server-micro
- * @description 指令执行
- * @date 2025/2/10 16:25:14
- */
- @Component
- public class ExecutionServer {
- private BufferedReader reader;
- private BufferedWriter writer;
- public String ExecutionData(String data) {
- try {
- String msg = "AT+STACH1=1\r\n";// \r\n(回车换行)
- System.out.println("第1路闭合,发送指令:AT+STACH1=1\\r\\n");
- //发送数据
- writer.write(msg);
- writer.flush();
- //读数据
- msg = reader.readLine();
- msg = msg.replace("\r\n", "\\r\\n");
- System.out.println("设备应答:" + msg);
- System.out.println("指令执行成功!");
- Thread.sleep(100);
- return msg;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return "发送指令:"+data+"失败";
- }
- }
|