3 changed files with 237 additions and 0 deletions
@ -0,0 +1,59 @@ |
|||||
|
package org.nl.acs.device.driver.conveyor.strip_conveyor; |
||||
|
|
||||
|
import org.nl.acs.device.driver.ItemDto; |
||||
|
|
||||
|
import org.nl.acs.device.driver.DeviceDriverBaseReader; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.ArrayList; |
||||
|
|
||||
|
public enum ItemProtocol implements DeviceDriverBaseReader.KeyProvider { |
||||
|
HEARTBEAT("heartbeat", "心跳", "DB1001.B0"), |
||||
|
IN_OUT_MODE("inOutMode", "出入库模式", "DB1001.B1"), |
||||
|
SWITCH_IN_OUT("switchInOut", "允许切换出入库模式", "DB1001.B2"), |
||||
|
TO_COMMAND("toCommand", "下发切换出入库模式", "DB1001.B3"); |
||||
|
|
||||
|
private final String key; |
||||
|
private final String description; |
||||
|
private final String address; |
||||
|
|
||||
|
ItemProtocol(String key, String description, String address) { |
||||
|
this.key = key; |
||||
|
this.description = description; |
||||
|
this.address = address; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String getKey() { |
||||
|
return this.key; |
||||
|
} |
||||
|
|
||||
|
public String getDescription() { |
||||
|
return description; |
||||
|
} |
||||
|
|
||||
|
public String getAddress() { |
||||
|
return address; |
||||
|
} |
||||
|
|
||||
|
public static List<ItemDto> getReadableItemDtos() { |
||||
|
List<ItemDto> list = new ArrayList<>(); |
||||
|
for (ItemProtocol prop : values()) { |
||||
|
if (!prop.getKey().startsWith("to")) { |
||||
|
list.add(new ItemDto(prop.getKey(), prop.getDescription(), prop.getAddress())); |
||||
|
} |
||||
|
} |
||||
|
return list; |
||||
|
} |
||||
|
|
||||
|
public static List<ItemDto> getWriteableItemDtos() { |
||||
|
List<ItemDto> list = new ArrayList<>(); |
||||
|
for (ItemProtocol prop : values()) { |
||||
|
if (prop.getKey().startsWith("to")) { |
||||
|
list.add(new ItemDto(prop.getKey(), prop.getDescription(), prop.getAddress())); |
||||
|
} |
||||
|
} |
||||
|
return list; |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,56 @@ |
|||||
|
package org.nl.acs.device.driver.conveyor.strip_conveyor; |
||||
|
|
||||
|
import org.nl.acs.device.driver.ItemDto; |
||||
|
import org.nl.acs.device.device.domain.Device; |
||||
|
import org.nl.acs.device.device.enums.DeviceType; |
||||
|
import org.nl.acs.device.driver.DeviceDriver; |
||||
|
import org.nl.acs.device.driver.OpcDeviceDriverDefination; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.util.LinkedList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
@Service |
||||
|
public class StripConveyorDefinition implements OpcDeviceDriverDefination { |
||||
|
@Override |
||||
|
public String getDriverCode() { |
||||
|
return "strip_conveyor_device"; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String getDriverName() { |
||||
|
return "标准版-输送线"; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String getDriverDescription() { |
||||
|
return "标准版-输送线"; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public DeviceDriver getDriverInstance(Device device) { |
||||
|
return (new StripConveyorDeviceDriver()).setDevice(device).setDriverDefination(this); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Class<? extends DeviceDriver> getDeviceDriverType() { |
||||
|
return StripConveyorDeviceDriver.class; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<DeviceType> getFitDeviceTypes() { |
||||
|
List<DeviceType> types = new LinkedList(); |
||||
|
types.add(DeviceType.conveyor); |
||||
|
return types; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<ItemDto> getReadableItemDtos() { |
||||
|
return ItemProtocol.getReadableItemDtos(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<ItemDto> getWriteableItemDtos() { |
||||
|
return ItemProtocol.getWriteableItemDtos(); |
||||
|
} |
||||
|
} |
@ -0,0 +1,122 @@ |
|||||
|
package org.nl.acs.device.driver.conveyor.strip_conveyor; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import lombok.Getter; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import lombok.Setter; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.nl.acs.device.device.domain.Device; |
||||
|
import org.nl.acs.device.driver.*; |
||||
|
import org.nl.acs.monitor.DeviceStageMonitor; |
||||
|
import org.nl.config.SpringContextHolder; |
||||
|
import org.nl.config.lucene.service.LuceneExecuteLogService; |
||||
|
import org.nl.config.lucene.service.dto.LuceneLogDto; |
||||
|
|
||||
|
@Slf4j |
||||
|
@Getter |
||||
|
@Setter |
||||
|
@RequiredArgsConstructor |
||||
|
public class StripConveyorDeviceDriver extends AbstractOpcDeviceDriver implements |
||||
|
DeviceDriver, |
||||
|
ExecutableDeviceDriver, |
||||
|
RouteableDeviceDriver, |
||||
|
DeviceStageMonitor, |
||||
|
StandardRequestMethod, |
||||
|
DeviceDriverBaseReader { |
||||
|
|
||||
|
private final LuceneExecuteLogService logService = SpringContextHolder.getBean(LuceneExecuteLogService.class); |
||||
|
|
||||
|
/** |
||||
|
* 心跳 |
||||
|
*/ |
||||
|
private int heartbeat = 0; |
||||
|
private int lastHeartbeat = 0; |
||||
|
/** |
||||
|
* 出入库模式 |
||||
|
*/ |
||||
|
private int inOutMode = 0; |
||||
|
private int lastInOutMode = 0; |
||||
|
/** |
||||
|
* 允许切换出入库模式 |
||||
|
*/ |
||||
|
private int switchInOut = 0; |
||||
|
private int lastSwitchInOut = 0; |
||||
|
/** |
||||
|
* 下发切换出入库模式 |
||||
|
*/ |
||||
|
private int toCommand = 0; |
||||
|
private int lastToCommand = 0; |
||||
|
/** |
||||
|
* 当前设备编号 |
||||
|
*/ |
||||
|
private String currentDeviceCode; |
||||
|
|
||||
|
/** |
||||
|
* 消息 |
||||
|
*/ |
||||
|
private String message; |
||||
|
|
||||
|
/** |
||||
|
* 请求标记 |
||||
|
*/ |
||||
|
boolean requireSuccess = false; |
||||
|
|
||||
|
/** |
||||
|
* 请求时间 |
||||
|
*/ |
||||
|
private long requireTime = System.currentTimeMillis(); |
||||
|
|
||||
|
/** |
||||
|
* 请求间隔时间 |
||||
|
*/ |
||||
|
private long requireTimeOut = 3000L; |
||||
|
|
||||
|
@Override |
||||
|
public Device getDevice() { |
||||
|
return this.device; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public <E extends Enum<E> & KeyProvider, T> T getOpcValue(E item, Class<T> fieldClassType) { |
||||
|
return (T) this.getValue(item.getKey()); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void setLog(String key, Object newValue, Object oldValue) { |
||||
|
logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "自动线程读取信号:" + key + ",由" + oldValue + "->" + newValue)); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void execute() { |
||||
|
this.currentDeviceCode = this.getDevice().getDevice_code(); |
||||
|
this.loadAssignData(currentDeviceCode, ItemProtocol.class); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void executeLogic() { |
||||
|
if (!this.online) { |
||||
|
this.message = "设备离线"; |
||||
|
} else { |
||||
|
this.message = ""; |
||||
|
//编写业务逻辑方法
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public JSONObject getDeviceStatusName() throws Exception { |
||||
|
JSONObject jo = new JSONObject(); |
||||
|
jo.put("device_code", this.currentDeviceCode); |
||||
|
jo.put("device_name", this.getDevice().getDevice_name()); |
||||
|
jo.put("driver_type", "strip_conveyor_device"); |
||||
|
jo.put("is_click", false); |
||||
|
jo.put("message", this.message); |
||||
|
jo.put("isOnline", this.online); |
||||
|
return jo; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void setDeviceStatus(JSONObject data) { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue