|
|
@@ -69,15 +69,17 @@ public class ExecutionServer {
|
|
|
}
|
|
|
public String ExecutionData(String msg) {
|
|
|
try {
|
|
|
+ String returnMsgReplace = "";
|
|
|
System.out.println("第1路闭合,发送指令:"+msg);
|
|
|
//发送数据
|
|
|
writer.write(msg);
|
|
|
writer.flush();
|
|
|
//读数据
|
|
|
- msg = reader.readLine();
|
|
|
- System.out.println("msg================:"+msg);
|
|
|
- if (msg != null) {
|
|
|
- msg = msg.replace("\r\n", "\\r\\n");
|
|
|
+ String returnMsg = reader.readLine();
|
|
|
+ System.out.println("returnMsg================:"+returnMsg);
|
|
|
+ if (returnMsg != null) {
|
|
|
+ returnMsgReplace = returnMsg.replace("\r\n", "\\r\\n");
|
|
|
+ System.out.println("设备应答:" + returnMsgReplace);
|
|
|
} else {
|
|
|
System.out.println("接收到的消息为 null,重新建立连接...");
|
|
|
// 关闭当前连接资源
|
|
|
@@ -87,19 +89,18 @@ public class ExecutionServer {
|
|
|
// 重新发送指令
|
|
|
writer.write(msg);
|
|
|
writer.flush();
|
|
|
- msg = reader.readLine();
|
|
|
- System.out.println("重新连接后接收到的消息:" + msg);
|
|
|
+ String returnMsg2 = reader.readLine();
|
|
|
+ returnMsgReplace = returnMsg2.replace("\r\n", "\\r\\n");
|
|
|
+ System.out.println("重新连接后接收到的消息:" + returnMsgReplace);
|
|
|
}
|
|
|
- msg = msg.replace("\r\n", "\\r\\n");
|
|
|
- System.out.println("设备应答:" + msg);
|
|
|
- if("AT".equals(msg)) {
|
|
|
+ if("AT".equals(returnMsgReplace)) {
|
|
|
String s = "AT+ACK\r\n";
|
|
|
writer.write(s);
|
|
|
writer.flush();
|
|
|
}
|
|
|
System.out.println("指令执行成功!");
|
|
|
Thread.sleep(100);
|
|
|
- return msg;
|
|
|
+ return returnMsgReplace;
|
|
|
} catch (Exception e) {
|
|
|
log.info(e.toString());
|
|
|
throw new RuntimeException("指令执行失败");
|