|
|
@@ -1,10 +1,12 @@
|
|
|
package com.zksy.lamp.server;
|
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.BufferedWriter;
|
|
|
+import java.io.IOException;
|
|
|
|
|
|
/**
|
|
|
* @author Administrator
|
|
|
@@ -15,12 +17,22 @@ import java.io.BufferedWriter;
|
|
|
*/
|
|
|
@Component
|
|
|
public class ExecutionServer {
|
|
|
+ private final TcpServer tcpServer;
|
|
|
private BufferedReader reader;
|
|
|
private BufferedWriter writer;
|
|
|
+ @Autowired
|
|
|
+ public ExecutionServer(TcpServer tcpServer) {
|
|
|
+ this.tcpServer = tcpServer;
|
|
|
+ }
|
|
|
|
|
|
public String ExecutionData(String data) {
|
|
|
try {
|
|
|
- String msg = "AT+STACH1=1\r\n";// \r\n(回车换行)
|
|
|
+ reader = tcpServer.getReader();
|
|
|
+ writer = tcpServer.getWriter();
|
|
|
+ if (reader == null || writer == null) {
|
|
|
+ throw new IOException("TcpServer not initialized properly.");
|
|
|
+ }
|
|
|
+ String msg = "AT+STACH1=1\r\n";
|
|
|
System.out.println("第1路闭合,发送指令:AT+STACH1=1\\r\\n");
|
|
|
//发送数据
|
|
|
writer.write(msg);
|