package com.zhitan.controller;
|
|
import com.zhitan.model.entity.OpcData;
|
import com.zhitan.service.IOpcService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.List;
|
|
/**
|
* OPC UA控制器
|
*/
|
@Slf4j
|
@RestController
|
@RequestMapping("/api/opc")
|
public class OpcController {
|
|
private final IOpcService opcService;
|
|
@Autowired
|
public OpcController(IOpcService opcService) {
|
this.opcService = opcService;
|
}
|
|
/**
|
* 获取OPC UA连接状态
|
*/
|
@GetMapping("/status")
|
public boolean getConnectionStatus() {
|
return opcService.isConnected();
|
}
|
|
/**
|
* 手动连接OPC UA服务器
|
*/
|
@PostMapping("/connect")
|
public boolean connect() {
|
return opcService.connect();
|
}
|
|
/**
|
* 断开OPC UA连接
|
*/
|
@PostMapping("/disconnect")
|
public void disconnect() {
|
opcService.disconnect();
|
}
|
|
/**
|
* 启动数据采集
|
*/
|
@PostMapping("/start")
|
public void startCollection() {
|
opcService.startDataCollection();
|
}
|
|
/**
|
* 停止数据采集
|
*/
|
@PostMapping("/stop")
|
public void stopCollection() {
|
opcService.stopDataCollection();
|
}
|
|
/**
|
* 读取所有节点数据
|
*/
|
@GetMapping("/data")
|
public List<OpcData> readAllData() {
|
return opcService.readAllNodes();
|
}
|
}
|