rev:手持新改接口

This commit is contained in:
2024-02-28 13:39:42 +08:00
parent 68a9b6f4e0
commit 46c18e95d4
24 changed files with 855 additions and 464 deletions

View File

@@ -10,11 +10,37 @@ import lombok.Setter;
@Setter
public class ItemProtocol {
/**
* 心跳
*/
public static final String ITEM_HEARTBEAT = "heartbeat";
/**
* 工作模式
*/
public static final String ITEM_MODE = "mode";
/**
* 光电信号
*/
public static final String ITEM_MOVE = "move";
/**
* 动作信号
*/
public static final String ITEM_ACTION = "action";
/**
* 报警信号
*/
public static final String ITEM_ERROR = "error";
/**
* 下发命令
*/
public static final String ITEM_TO_COMMAND = "to_command";
boolean isOnline;
private final PhotoelectricDetectionDeviceDriver driver;
@@ -34,7 +60,22 @@ public class ItemProtocol {
}
}
public int getHeartbeat() {
return this.getOpcIntegerValue(ItemProtocol.ITEM_HEARTBEAT);
}
public int getMode() {
return this.getOpcIntegerValue(ItemProtocol.ITEM_MODE);
}
public int getMove() {
return this.getOpcIntegerValue(ItemProtocol.ITEM_MOVE);
}
public int getAction() {
return this.getOpcIntegerValue(ItemProtocol.ITEM_ACTION);
}
public int getError() {
return this.getOpcIntegerValue(ItemProtocol.ITEM_ERROR);
}
public int getToCommand() {
return this.getOpcIntegerValue(ItemProtocol.ITEM_TO_COMMAND);
}
}

View File

@@ -35,13 +35,43 @@ import java.util.Map;
@RequiredArgsConstructor
public class PhotoelectricDetectionDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, StandardRequestMethod, HeartbeatableDeviceDriver {
/**
* 心跳
*/
private int heartbeat = 0;
private int lastHeartbeat = this.heartbeat;
// 光电信号
/**
* 工作模式
*/
private int mode = 0;
private int lastMode = this.mode;
/**
* 光电信号
*/
private int move = 0;
private int lastMove = this.move;
private final static int MODE = 3;
/**
* 动作信号
*/
private int action = 0;
private int lastAction = this.action;
/**
* 报警信号
*/
private int error = 0;
private int lastError = this.error;
/**
* 下发命令
*/
private int toCommand = 0;
private int lastToCommand = this.toCommand;
private static final int MODE = 3;
private String currentDeviceCode = null;
private boolean isOnline = false;
@@ -67,14 +97,20 @@ public class PhotoelectricDetectionDeviceDriver extends AbstractOpcDeviceDriver
try {
this.currentDeviceCode = this.getDeviceCode();
this.heartbeat = this.itemProtocol.getHeartbeat();
this.mode = this.itemProtocol.getMode();
this.move = this.itemProtocol.getMove();
this.action = this.itemProtocol.getAction();
this.error = this.itemProtocol.getError();
this.toCommand = this.itemProtocol.getToCommand();
if (this.move != this.lastMove) {
if (move == 0) {
requireSuccess = false;
}
}
if (MODE > 0 && !requireSuccess) {
if (mode > 0 && !requireSuccess) {
Object methodName = this.device.getExtraValue().get(String.valueOf(MODE));
if (ObjectUtil.isNotEmpty(methodName)) {
try {
@@ -99,7 +135,12 @@ public class PhotoelectricDetectionDeviceDriver extends AbstractOpcDeviceDriver
log.error(e.getMessage(), e);
return;
}
this.lastHeartbeat = this.heartbeat;
this.lastMode = this.mode;
this.lastMove = this.move;
this.lastAction = this.action;
this.lastError = this.error;
this.lastToCommand = this.toCommand;
}
private void executionMethodByMode(String methodName) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {

View File

@@ -52,13 +52,18 @@ public class PhotoelectricDetectionStationDefinition implements OpcDeviceDriverD
@Override
public List<ItemDTO> getReadableItemDTOs() {
ArrayList<ItemDTO> itemDTOs = new ArrayList<>();
itemDTOs.add(new ItemDTO(ItemProtocol.ITEM_HEARTBEAT, "心跳", ""));
itemDTOs.add(new ItemDTO(ItemProtocol.ITEM_MODE, "工作模式", ""));
itemDTOs.add(new ItemDTO(ItemProtocol.ITEM_MOVE, "光电信号", ""));
itemDTOs.add(new ItemDTO(ItemProtocol.ITEM_ACTION, "动作信号", ""));
itemDTOs.add(new ItemDTO(ItemProtocol.ITEM_ERROR, "报警信号", ""));
return itemDTOs;
}
@Override
public List<ItemDTO> getWriteableItemDTOs() {
ArrayList<ItemDTO> itemDTOs = new ArrayList<>();
itemDTOs.add(new ItemDTO(ItemProtocol.ITEM_TO_COMMAND, "下发命令", ""));
return itemDTOs;
}
}