|
|
@ -1,6 +1,5 @@
|
|
|
|
package com.xydl.cac.controller;
|
|
|
|
package com.xydl.cac.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import com.fazecast.jSerialComm.SerialPort;
|
|
|
|
|
|
|
|
import com.xydl.cac.model.Response;
|
|
|
|
import com.xydl.cac.model.Response;
|
|
|
|
import com.xydl.cac.model.StaticVariable;
|
|
|
|
import com.xydl.cac.model.StaticVariable;
|
|
|
|
import com.xydl.cac.service.IcdFileConfigService;
|
|
|
|
import com.xydl.cac.service.IcdFileConfigService;
|
|
|
@ -16,12 +15,11 @@ import org.springframework.web.socket.WebSocketSession;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
@Api(tags = {"测试接口"})
|
|
|
|
@Api(tags = {"测试接口文档"})
|
|
|
|
@RequestMapping("test")
|
|
|
|
@RequestMapping("test")
|
|
|
|
@Slf4j
|
|
|
|
@Slf4j
|
|
|
|
public class TestController extends BasicController {
|
|
|
|
public class TestController extends BasicController {
|
|
|
@ -91,50 +89,30 @@ public class TestController extends BasicController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/discover")
|
|
|
|
@GetMapping("/discover")
|
|
|
|
public Response<List<String>> discoverSerialPort() {
|
|
|
|
public Response<String> discoverSerialPort() {
|
|
|
|
List<SerialPort> list1 = serialPortService.discoverSerialPort();
|
|
|
|
Boolean aBoolean = serialPortService.discoverSerialPort();
|
|
|
|
StaticVariable.serialPorts = list1;
|
|
|
|
if (aBoolean) {
|
|
|
|
List<String> list = new ArrayList<>();
|
|
|
|
return Response.success("发现了");
|
|
|
|
list1.forEach(item -> {
|
|
|
|
} else {
|
|
|
|
list.add(item.getSystemPortName());
|
|
|
|
return Response.fail("未找到");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
Response<List<String>> response = Response.success(list);
|
|
|
|
|
|
|
|
return response;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/open")
|
|
|
|
@GetMapping("/open")
|
|
|
|
public Response<Boolean> openSerialPort(String portname) {
|
|
|
|
public Response<Boolean> openSerialPort() {
|
|
|
|
for (SerialPort port : StaticVariable.serialPorts) {
|
|
|
|
return Response.success(serialPortService.openSerialPort());
|
|
|
|
if (port.getSystemPortName().equals(portname)) {
|
|
|
|
|
|
|
|
return Response.success(serialPortService.openSerialPort(port));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Response.fail("Failed to find port ");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/send")
|
|
|
|
@GetMapping("/send")
|
|
|
|
public String sendData(int data,String portname) throws IOException {
|
|
|
|
public String sendData(boolean data) throws IOException {
|
|
|
|
//发送数据注意,提前与接收设备沟通好协议,发送什么样类型的数据设备才可以进行响应,否则设备无响应
|
|
|
|
//发送数据注意,提前与接收设备沟通好协议,发送什么样类型的数据设备才可以进行响应,否则设备无响应
|
|
|
|
for (SerialPort port : StaticVariable.serialPorts) {
|
|
|
|
serialPortService.sendData(data);
|
|
|
|
if (port.getSystemPortName().equals(portname)) {
|
|
|
|
|
|
|
|
if (data == 0) {
|
|
|
|
|
|
|
|
serialPortService.sendData(port, false);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
serialPortService.sendData(port, true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return "Data sent>>>";
|
|
|
|
return "Data sent>>>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/close")
|
|
|
|
@GetMapping("/close")
|
|
|
|
public String closeSerialPort(String portname) {
|
|
|
|
public String closeSerialPort(String portname) {
|
|
|
|
for (SerialPort port : StaticVariable.serialPorts) {
|
|
|
|
serialPortService.closeSerialPort();
|
|
|
|
if (port.getSystemPortName().equals(portname)) {
|
|
|
|
|
|
|
|
serialPortService.closeSerialPort(port,portname);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return "Serial port closed";
|
|
|
|
return "Serial port closed";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|