|
|
@@ -2,11 +2,10 @@ 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;
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
+import java.io.*;
|
|
|
+import java.net.Socket;
|
|
|
|
|
|
/**
|
|
|
* @author Administrator
|
|
|
@@ -17,21 +16,26 @@ import java.io.IOException;
|
|
|
*/
|
|
|
@Component
|
|
|
public class ExecutionServer {
|
|
|
- private final TcpServer tcpServer;
|
|
|
+ @Autowired
|
|
|
+ private TcpServer tcpServer;
|
|
|
private BufferedReader reader;
|
|
|
private BufferedWriter writer;
|
|
|
- @Autowired
|
|
|
- public ExecutionServer(TcpServer tcpServer) {
|
|
|
- this.tcpServer = tcpServer;
|
|
|
- }
|
|
|
-
|
|
|
- public String ExecutionData(String data) {
|
|
|
+ @PostConstruct
|
|
|
+ public void init() {
|
|
|
try {
|
|
|
reader = tcpServer.getReader();
|
|
|
writer = tcpServer.getWriter();
|
|
|
if (reader == null || writer == null) {
|
|
|
- throw new IOException("TcpServer not initialized properly.");
|
|
|
+ throw new IOException("Reader or Writer is not available.");
|
|
|
}
|
|
|
+ System.out.println("Reader and Writer initialized successfully.");
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public String ExecutionData(String data) {
|
|
|
+ try {
|
|
|
String msg = "AT+STACH1=1\r\n";
|
|
|
System.out.println("第1路闭合,发送指令:AT+STACH1=1\\r\\n");
|
|
|
//发送数据
|