ExecutionServer.java 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package com.zksy.lamp.server;
  2. import org.springframework.stereotype.Component;
  3. import org.springframework.stereotype.Service;
  4. import java.io.BufferedReader;
  5. import java.io.BufferedWriter;
  6. /**
  7. * @author Administrator
  8. * @version 1.0
  9. * @project dh-server-micro
  10. * @description 指令执行
  11. * @date 2025/2/10 16:25:14
  12. */
  13. @Component
  14. public class ExecutionServer {
  15. private BufferedReader reader;
  16. private BufferedWriter writer;
  17. public String ExecutionData(String data) {
  18. try {
  19. String msg = "AT+STACH1=1\r\n";// \r\n(回车换行)
  20. System.out.println("第1路闭合,发送指令:AT+STACH1=1\\r\\n");
  21. //发送数据
  22. writer.write(msg);
  23. writer.flush();
  24. //读数据
  25. msg = reader.readLine();
  26. msg = msg.replace("\r\n", "\\r\\n");
  27. System.out.println("设备应答:" + msg);
  28. System.out.println("指令执行成功!");
  29. Thread.sleep(100);
  30. return msg;
  31. } catch (Exception e) {
  32. e.printStackTrace();
  33. }
  34. return "发送指令:"+data+"失败";
  35. }
  36. }