驱动更新

This commit is contained in:
2022-11-19 21:27:27 +08:00
parent e215e85079
commit a7662678d6
18 changed files with 4166 additions and 2 deletions

View File

@@ -25,7 +25,15 @@ public enum DriverTypeEnum {
AGV_NDC_TWO(8, "agv_ndc_two", "NDC2楼AGV", "agv"),
HONGXIANG_DEVICE(8, "hongxiang_device", "烘箱设备点位", "conveyor");
HONGXIANG_DEVICE(9, "hongxiang_device", "烘箱设备点位", "conveyor"),
OVEN_MANIPULATOR(10, "oven_manipulator", "烘箱-行架机械手", "station"),
SLIT_TWO_MANIPULATOR(11, "slit_two_manipulator", "分切双工位-行架机械手", "station"),
BOX_PALLETIZING_MANIPULATOR(12, "box_palletizing_manipulator", "木箱码垛-行架机械手", "station"),
SIEMENS_CONVEYOR(13, "siemens_conveyor", "西门子-输送机驱动", "conveyor");
//驱动索引

View File

@@ -0,0 +1,64 @@
package org.nl.acs.device_driver.basedriver.box_palletizing_manipulator;
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;
import org.nl.acs.device_driver.DeviceDriver;
import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination;
import org.nl.acs.opc.Device;
import org.nl.acs.opc.DeviceType;
import org.springframework.stereotype.Service;
import java.util.LinkedList;
import java.util.List;
/**
* 木箱码垛-行架机械手
*
*/
@Service
public class BoxPalletizingManipulatorDefination implements OpcDeviceDriverDefination {
@Override
public String getDriverCode() {
return "box_palletizing_manipulator";
}
@Override
public String getDriverName() {
return "木箱码垛-行架机械手";
}
@Override
public String getDriverDescription() {
return "木箱码垛-行架机械手";
}
@Override
public DeviceDriver getDriverInstance(Device device) {
return (new BoxPalletizingManipulatorDeviceDriver()).setDevice(device).setDriverDefination(this);
}
@Override
public Class<? extends DeviceDriver> getDeviceDriverType() {
return BoxPalletizingManipulatorDeviceDriver.class;
}
@Override
public List<DeviceType> getFitDeviceTypes() {
List<DeviceType> types = new LinkedList();
types.add(DeviceType.station);
return types;
}
@Override
public List<ItemDto> getReadableItemDtos() {
return ItemProtocol.getReadableItemDtos();
}
@Override
public List<ItemDto> getWriteableItemDtos() {
return ItemProtocol.getWriteableItemDtos();
}
}

View File

@@ -0,0 +1,282 @@
package org.nl.acs.device_driver.basedriver.box_palletizing_manipulator;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.device.device_driver.standard_inspect.ReadUtil;
import org.nl.acs.device.service.DeviceService;
import org.nl.acs.device_driver.DeviceDriver;
import org.nl.acs.device_driver.RouteableDeviceDriver;
import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver;
import org.nl.acs.device_driver.driver.ExecutableDeviceDriver;
import org.nl.acs.ext.wms.service.AcsToWmsService;
import org.nl.acs.instruction.service.InstructionService;
import org.nl.acs.instruction.service.dto.Instruction;
import org.nl.acs.log.service.DeviceExecuteLogService;
import org.nl.acs.monitor.DeviceStageMonitor;
import org.nl.acs.opc.Device;
import org.nl.acs.opc.DeviceAppService;
import org.nl.acs.opc.DeviceAppServiceImpl;
import org.nl.acs.route.service.RouteLineService;
import org.nl.acs.task.service.TaskService;
import org.nl.modules.wql.util.SpringContextHolder;
import org.openscada.opc.lib.da.Server;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.*;
/**
* 木箱码垛-行架机械手
*/
@Slf4j
@Data
@RequiredArgsConstructor
public class BoxPalletizingManipulatorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor {
protected ItemProtocol itemProtocol = new ItemProtocol(this);
@Autowired
InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl");
@Autowired
DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl");
@Autowired
RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl");
@Autowired
TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl");
@Autowired
DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl");
@Autowired
AcsToWmsService acsToWmsService = SpringContextHolder.getBean("acsToWmsServiceImpl");
@Autowired
DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class);
//工作模式
int mode = 0;
int last_mode = 0;
//光电信号
int move = 0;
int last_move = 0;
//动作信号
int action = 0;
int last_action = 0;
//行走列
int walk_y = 0;
int last_walk_y = 0;
//报警信号
int error = 0;
int last_error = 0;
//任务号
int task = 0;
int last_task = 0;
Boolean isonline = true;
int hasGoods = 0;
String message = null;
Boolean iserror = false;
Integer heartbeat_tag;
private Date instruction_require_time = new Date();
private int instruction_require_time_out;
//行架机械手申请任务成功标识
boolean requireSucess = false;
private int instruction_finished_time_out;
int branchProtocol = 0;
//暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域
int flag;
String device_code;
@Override
public Device getDevice() {
return this.device;
}
@Override
public void execute() {
String message = null;
try {
device_code = this.getDeviceCode();
mode = this.itemProtocol.getMode();
move = this.itemProtocol.getMove();
action = this.itemProtocol.getAction();
walk_y = this.itemProtocol.getWalk_y();
error = this.itemProtocol.getError();
task = this.itemProtocol.getTask();
if (mode != last_mode) {
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_mode + "->" + mode);
}
if (move != last_move) {
logServer.deviceItemValue(this.device_code, "move", String.valueOf(move));
logServer.deviceExecuteLog(this.device_code, "", "", "信号move" + last_move + "->" + move);
}
if (action != last_action) {
logServer.deviceItemValue(this.device_code, "action", String.valueOf(action));
logServer.deviceExecuteLog(this.device_code, "", "", "信号action" + last_action + "->" + action);
}
if (error != last_error) {
logServer.deviceItemValue(this.device_code, "error", String.valueOf(error));
logServer.deviceExecuteLog(this.device_code, "", "", "信号error" + last_error + "->" + error);
}
if (walk_y != last_walk_y) {
logServer.deviceItemValue(this.device_code, "walk_y", String.valueOf(walk_y));
logServer.deviceExecuteLog(this.device_code, "", "", "信号walk_y" + last_walk_y + "->" + walk_y);
}
if (task != last_task) {
logServer.deviceItemValue(this.device_code, "task", String.valueOf(task));
logServer.deviceExecuteLog(this.device_code, "", "", "信号task" + last_task + "->" + task);
}
} catch (Exception var17) {
return;
}
if (!this.itemProtocol.getIsonline()) {
this.setIsonline(false);
this.setIserror(true);
message = "信号量同步异常";
//未联机
} else if (mode == 0) {
this.setIsonline(false);
this.setIserror(true);
message = "未联机";
//有报警
} else if (error != 0) {
this.setIsonline(false);
this.setIserror(true);
message = "有报警";
//无报警
} else {
this.setIsonline(true);
this.setIserror(false);
message = "";
Instruction instruction = null;
List toInstructions;
}
last_mode = mode;
last_move = move;
last_action = action;
last_walk_y = walk_y;
last_error = error;
last_task = task;
}
public boolean exe_error() {
if (this.error == 0) {
return true;
} else {
log.debug("设备报警");
return false;
}
}
public boolean exe_business() {
return true;
}
public synchronized boolean finish_instruction(Instruction inst) throws Exception {
instructionService.finish(inst);
return true;
}
public void writing(String param, String value) {
String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
+ "." + param;
String opcservcerid = this.getDevice().getOpc_server_id();
Server server = ReadUtil.getServer(opcservcerid);
Map<String, Object> itemMap = new HashMap<String, Object>();
itemMap.put(to_param, value);
// itemMap.put(to_param, Integer.parseInt(value));
ReadUtil.write(itemMap, server);
}
public void executing(Server server, Map<String, Object> itemMap) {
ReadUtil.write(itemMap, server);
}
public void writing(int command) {
String opcservcerid = this.getDevice().getOpc_server_id();
Server server = ReadUtil.getServer(opcservcerid);
Map<String, Object> itemMap = new HashMap<String, Object>();
ReadUtil.write(itemMap, server);
}
//将扩展表中的字符串数据转换成集合
public List<String> getExtraDeviceCodes(String extraName) {
String extraValue = (String) this.getDevice().getExtraValue().get(extraName);
String devicesString = extraValue.substring(1, extraValue.length() - 1);
List<String> devicesList = new ArrayList<>();
String[] devices = devicesString.split(",");
for (int i = 0; i < devices.length; i++) {
String s = devices[i].replace("\"", "").replace("\"", "");
devicesList.add(s);
}
return devicesList;
}
@Override
public JSONObject getDeviceStatusName() {
JSONObject jo = new JSONObject();
String mode = "";
String move = "";
String action = "";
String walk_y = "";
if (this.getMode() == 0) {
mode = "脱机";
} else if (this.getMode() == 1) {
mode = "单机";
} else if (this.getMode() == 2) {
mode = "待机";
} else if (this.getMode() == 3) {
mode = "运行中";
}
if (this.getMove() == 0) {
move = "无货";
} else if (this.getMove() == 1) {
move = "有货";
}
if (this.getAction() == 1) {
action = "取货中";
} else if (this.getAction() == 2) {
action = "取货完成";
} else if (this.getAction() == 3) {
action = "放货中";
} else if (this.getAction() == 4) {
action = "放货完成";
}
jo.put("device_name", this.getDevice().getDevice_name());
jo.put("mode", mode);
jo.put("move", move);
jo.put("action", action);
jo.put("task", task);
jo.put("walk_y", walk_y);
jo.put("isOnline", this.getIsonline());
jo.put("error", this.getError());
jo.put("isError", this.getIserror());
jo.put("message", this.getMessage());
return jo;
}
@Override
public void setDeviceStatus(JSONObject data) {
}
}

View File

@@ -0,0 +1,109 @@
package org.nl.acs.device_driver.basedriver.box_palletizing_manipulator;
import cn.hutool.core.util.StrUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@Data
public class ItemProtocol {
//心跳
public static String item_heartbeat = "heartbeat";
//工作模式
public static String item_mode = "mode";
//光电信号
public static String item_move = "move";
//动作信号
public static String item_action = "action";
//行走列
public static String item_walk_y = "walk_y";
//报警
public static String item_error = "error";
//任务号
public static String item_task = "task";
private BoxPalletizingManipulatorDeviceDriver driver;
public ItemProtocol(BoxPalletizingManipulatorDeviceDriver driver) {
this.driver = driver;
}
public int getHeartbeat() {
return this.getOpcIntegerValue(item_heartbeat);
}
public int getMode() {
return this.getOpcIntegerValue(item_mode);
}
public int getMove() {
return this.getOpcIntegerValue(item_move);
}
public int getAction() {
return this.getOpcIntegerValue(item_action);
}
public int getWalk_y() {
return this.getOpcIntegerValue(item_walk_y);
}
public int getError() {
return this.getOpcIntegerValue(item_error);
}
public int getTask() {
return this.getOpcIntegerValue(item_task);
}
Boolean isonline;
public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) {
log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false);
} else {
setIsonline(true);
return value;
}
return 0;
}
public String getOpcStringValue(String protocol) {
String value = this.driver.getStringValue(protocol);
if (StrUtil.isEmpty(value)) {
} else {
return value;
}
return "0";
}
public static List<ItemDto> getReadableItemDtos() {
ArrayList list = new ArrayList();
list.add(new ItemDto(item_heartbeat, "心跳", "DB1.B0"));
list.add(new ItemDto(item_mode, "工作模式", "DB1.B1"));
list.add(new ItemDto(item_move, "光电信号", "DB1.B2"));
list.add(new ItemDto(item_action, "动作信号", "DB1.B3"));
list.add(new ItemDto(item_walk_y, "行走列", "DB1.B4"));
list.add(new ItemDto(item_error, "报警信号", "DB1.B5"));
list.add(new ItemDto(item_task, "任务号", "DB1.D6"));
return list;
}
public static List<ItemDto> getWriteableItemDtos() {
ArrayList list = new ArrayList();
return list;
}
}

View File

@@ -0,0 +1,122 @@
package org.nl.acs.device_driver.basedriver.oven_manipulator;
import cn.hutool.core.util.StrUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@Data
public class ItemProtocol {
//心跳
public static String item_heartbeat = "heartbeat";
//工作模式
public static String item_mode = "mode";
//光电信号
public static String item_move = "move";
//动作信号
public static String item_action = "action";
//行走列
public static String item_walk_y = "walk_y";
//报警
public static String item_error = "error";
//任务号
public static String item_task = "task";
//下发命令
public static String item_to_command = "to_command";
//下发起始站
public static String item_to_onset = "to_onset";
//下发目标站
public static String item_to_target = "to_target";
//下发任务号
public static String item_to_task = "to_task";
private OvenGantryManipulatorDeviceDriver driver;
public ItemProtocol(OvenGantryManipulatorDeviceDriver driver) {
this.driver = driver;
}
public int getHeartbeat() {
return this.getOpcIntegerValue(item_heartbeat);
}
public int getMode() {
return this.getOpcIntegerValue(item_mode);
}
public int getMove() {
return this.getOpcIntegerValue(item_move);
}
public int getAction() {
return this.getOpcIntegerValue(item_action);
}
public int getWalk_y() {
return this.getOpcIntegerValue(item_walk_y);
}
public int getError() {
return this.getOpcIntegerValue(item_error);
}
public int getTask() {
return this.getOpcIntegerValue(item_task);
}
Boolean isonline;
public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) {
log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false);
} else {
setIsonline(true);
return value;
}
return 0;
}
public String getOpcStringValue(String protocol) {
String value = this.driver.getStringValue(protocol);
if (StrUtil.isEmpty(value)) {
} else {
return value;
}
return "0";
}
public static List<ItemDto> getReadableItemDtos() {
ArrayList list = new ArrayList();
list.add(new ItemDto(item_heartbeat, "心跳", "DB1.B0"));
list.add(new ItemDto(item_mode, "工作模式", "DB1.B1"));
list.add(new ItemDto(item_move, "光电信号", "DB1.B2"));
list.add(new ItemDto(item_action, "动作信号", "DB1.B3"));
list.add(new ItemDto(item_walk_y, "行走列", "DB1.B4"));
list.add(new ItemDto(item_error, "报警信号", "DB1.B5"));
list.add(new ItemDto(item_task, "任务号", "DB1.D6"));
return list;
}
public static List<ItemDto> getWriteableItemDtos() {
ArrayList list = new ArrayList();
list.add(new ItemDto(item_to_command, "下发命令", "DB2.W0"));
list.add(new ItemDto(item_to_onset, "下发起始站", "DB2.W2"));
list.add(new ItemDto(item_to_target, "下发目标站", "DB2.W4"));
list.add(new ItemDto(item_to_task, "下发任务号", "DB2.D6"));
return list;
}
}

View File

@@ -0,0 +1,64 @@
package org.nl.acs.device_driver.basedriver.oven_manipulator;
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;
import org.nl.acs.device_driver.DeviceDriver;
import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination;
import org.nl.acs.opc.Device;
import org.nl.acs.opc.DeviceType;
import org.springframework.stereotype.Service;
import java.util.LinkedList;
import java.util.List;
/**
* 烘箱-行架机械手
*
*/
@Service
public class OvenGantryManipulatorDefination implements OpcDeviceDriverDefination {
@Override
public String getDriverCode() {
return "oven_manipulator";
}
@Override
public String getDriverName() {
return "烘箱-行架机械手";
}
@Override
public String getDriverDescription() {
return "烘箱-行架机械手";
}
@Override
public DeviceDriver getDriverInstance(Device device) {
return (new OvenGantryManipulatorDeviceDriver()).setDevice(device).setDriverDefination(this);
}
@Override
public Class<? extends DeviceDriver> getDeviceDriverType() {
return OvenGantryManipulatorDeviceDriver.class;
}
@Override
public List<DeviceType> getFitDeviceTypes() {
List<DeviceType> types = new LinkedList();
types.add(DeviceType.station);
return types;
}
@Override
public List<ItemDto> getReadableItemDtos() {
return ItemProtocol.getReadableItemDtos();
}
@Override
public List<ItemDto> getWriteableItemDtos() {
return ItemProtocol.getWriteableItemDtos();
}
}

View File

@@ -0,0 +1,301 @@
package org.nl.acs.device_driver.basedriver.oven_manipulator;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.device.device_driver.standard_inspect.ReadUtil;
import org.nl.acs.device.service.DeviceService;
import org.nl.acs.device_driver.DeviceDriver;
import org.nl.acs.device_driver.RouteableDeviceDriver;
import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver;
import org.nl.acs.device_driver.driver.ExecutableDeviceDriver;
import org.nl.acs.ext.wms.service.AcsToWmsService;
import org.nl.acs.instruction.service.InstructionService;
import org.nl.acs.instruction.service.dto.Instruction;
import org.nl.acs.log.service.DeviceExecuteLogService;
import org.nl.acs.monitor.DeviceStageMonitor;
import org.nl.acs.opc.Device;
import org.nl.acs.opc.DeviceAppService;
import org.nl.acs.opc.DeviceAppServiceImpl;
import org.nl.acs.route.service.RouteLineService;
import org.nl.acs.task.service.TaskService;
import org.nl.modules.wql.util.SpringContextHolder;
import org.openscada.opc.lib.da.Server;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.*;
/**
* 烘箱-行架机械手
*/
@Slf4j
@Data
@RequiredArgsConstructor
public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor {
protected ItemProtocol itemProtocol = new ItemProtocol(this);
@Autowired
InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl");
@Autowired
DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl");
@Autowired
RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl");
@Autowired
TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl");
@Autowired
DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl");
@Autowired
AcsToWmsService acsToWmsService = SpringContextHolder.getBean("acsToWmsServiceImpl");
@Autowired
DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class);
//工作模式
int mode = 0;
int last_mode = 0;
//光电信号
int move = 0;
int last_move = 0;
//动作信号
int action = 0;
int last_action = 0;
//行走列
int walk_y = 0;
int last_walk_y = 0;
//报警信号
int error = 0;
int last_error = 0;
//任务号
int task = 0;
int last_task = 0;
Boolean isonline = true;
int hasGoods = 0;
String message = null;
Boolean iserror = false;
Integer heartbeat_tag;
private Date instruction_require_time = new Date();
private int instruction_require_time_out;
//行架机械手申请任务成功标识
boolean requireSucess = false;
private int instruction_finished_time_out;
int branchProtocol = 0;
//暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域
int flag;
String device_code;
@Override
public Device getDevice() {
return this.device;
}
@Override
public void execute() {
String message = null;
try {
device_code = this.getDeviceCode();
mode = this.itemProtocol.getMode();
move = this.itemProtocol.getMove();
action = this.itemProtocol.getAction();
walk_y = this.itemProtocol.getWalk_y();
error = this.itemProtocol.getError();
task = this.itemProtocol.getTask();
if (mode != last_mode) {
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_mode + "->" + mode);
}
if (move != last_move) {
logServer.deviceItemValue(this.device_code, "move", String.valueOf(move));
logServer.deviceExecuteLog(this.device_code, "", "", "信号move" + last_move + "->" + move);
}
if (action != last_action) {
logServer.deviceItemValue(this.device_code, "action", String.valueOf(action));
logServer.deviceExecuteLog(this.device_code, "", "", "信号action" + last_action + "->" + action);
}
if (error != last_error) {
logServer.deviceItemValue(this.device_code, "error", String.valueOf(error));
logServer.deviceExecuteLog(this.device_code, "", "", "信号error" + last_error + "->" + error);
}
if (walk_y != last_walk_y) {
logServer.deviceItemValue(this.device_code, "walk_y", String.valueOf(walk_y));
logServer.deviceExecuteLog(this.device_code, "", "", "信号walk_y" + last_walk_y + "->" + walk_y);
}
if (task != last_task) {
logServer.deviceItemValue(this.device_code, "task", String.valueOf(task));
logServer.deviceExecuteLog(this.device_code, "", "", "信号task" + last_task + "->" + task);
}
} catch (Exception var17) {
return;
}
if (!this.itemProtocol.getIsonline()) {
this.setIsonline(false);
this.setIserror(true);
message = "信号量同步异常";
//未联机
} else if (mode == 0) {
this.setIsonline(false);
this.setIserror(true);
message = "未联机";
//有报警
} else if (error != 0) {
this.setIsonline(false);
this.setIserror(true);
message = "有报警";
//无报警
} else {
this.setIsonline(true);
this.setIserror(false);
message = "";
Instruction instruction = null;
List toInstructions;
}
last_mode = mode;
last_move = move;
last_action = action;
last_walk_y = walk_y;
last_error = error;
last_task = task;
}
public boolean exe_error() {
if (this.error == 0) {
return true;
} else {
log.debug("设备报警");
return false;
}
}
public boolean exe_business() {
return true;
}
public synchronized boolean finish_instruction(Instruction inst) throws Exception {
instructionService.finish(inst);
return true;
}
public void writing(String param, String value) {
String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
+ "." + param;
String opcservcerid = this.getDevice().getOpc_server_id();
Server server = ReadUtil.getServer(opcservcerid);
Map<String, Object> itemMap = new HashMap<String, Object>();
itemMap.put(to_param, value);
// itemMap.put(to_param, Integer.parseInt(value));
ReadUtil.write(itemMap, server);
}
public void executing(Server server, Map<String, Object> itemMap) {
ReadUtil.write(itemMap, server);
}
public void writing(int command) {
String opcservcerid = this.getDevice().getOpc_server_id();
Server server = ReadUtil.getServer(opcservcerid);
Map<String, Object> itemMap = new HashMap<String, Object>();
ReadUtil.write(itemMap, server);
}
//将扩展表中的字符串数据转换成集合
public List<String> getExtraDeviceCodes(String extraName) {
String extraValue = (String) this.getDevice().getExtraValue().get(extraName);
String devicesString = extraValue.substring(1, extraValue.length() - 1);
List<String> devicesList = new ArrayList<>();
String[] devices = devicesString.split(",");
for (int i = 0; i < devices.length; i++) {
String s = devices[i].replace("\"", "").replace("\"", "");
devicesList.add(s);
}
return devicesList;
}
@Override
public JSONObject getDeviceStatusName() {
JSONObject jo = new JSONObject();
String mode = "";
String move = "";
String action = "";
String walk_y = "";
if (this.getMode() == 0) {
mode = "脱机";
} else if (this.getMode() == 1) {
mode = "单机";
} else if (this.getMode() == 2) {
mode = "待机";
} else if (this.getMode() == 3) {
mode = "运行中";
}
if (this.getMove() == 0) {
move = "无货";
} else if (this.getMove() == 1) {
move = "有货";
}
if (this.getAction() == 1) {
action = "取货中";
} else if (this.getAction() == 2) {
action = "取货完成";
} else if (this.getAction() == 3) {
action = "放货中";
} else if (this.getAction() == 4) {
action = "放货完成";
}
jo.put("device_name", this.getDevice().getDevice_name());
jo.put("mode", mode);
jo.put("move", move);
jo.put("action", action);
jo.put("task", task);
jo.put("walk_y", walk_y);
jo.put("isOnline", this.getIsonline());
jo.put("error", this.getError());
jo.put("isError", this.getIserror());
jo.put("message", this.getMessage());
return jo;
}
@Override
public void setDeviceStatus(JSONObject data) {
}
// public void writing(int type, int command) {
// String to_material_code = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
// + "." + ItemProtocol.item_to_material_code;
// String opcservcerid = this.getDevice().getOpc_server_id();
// Server server = ReadUtil.getServer(opcservcerid);
// Map<String, Object> itemMap = new HashMap<String, Object>();
// if (type == 2) {
// itemMap.put(to_material_code, command);
// }
// ReadUtil.write(itemMap, server);
//
// }
}

View File

@@ -0,0 +1,127 @@
package org.nl.acs.device_driver.basedriver.siemens_conveyor;
import cn.hutool.core.util.StrUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@Data
public class ItemProtocol {
//心跳
public static String item_heartbeat = "heartbeat";
//工作模式
public static String item_mode = "mode";
//光电信号
public static String item_move = "move";
//托盘方向
public static String item_carrier_direction = "carrier_direction";
//报警
public static String item_error = "error";
//任务号
public static String item_task = "task";
//下发命令
public static String item_to_command = "to_command";
//下发目标站
public static String item_to_target = "to_target";
//下发托盘类型
public static String item_to_container_type = "to_container_type";
//下发任务号
public static String item_to_task = "to_task";
//困扎次数
public static String item_to_strap_times = "to_strap_times";
//木箱长度
public static String item_to_length = "to_length";
//木箱宽度
public static String item_to_weight = "to_weight";
//木箱高度
public static String item_to_height = "to_height";
private SiemensConveyorDeviceDriver driver;
public ItemProtocol(SiemensConveyorDeviceDriver driver) {
this.driver = driver;
}
public int getHeartbeat() {
return this.getOpcIntegerValue(item_heartbeat);
}
public int getMode() {
return this.getOpcIntegerValue(item_mode);
}
public int getMove() {
return this.getOpcIntegerValue(item_move);
}
public int getCarrier_direction() {
return this.getOpcIntegerValue(item_carrier_direction);
}
public int getError() {
return this.getOpcIntegerValue(item_error);
}
public int getTask() {
return this.getOpcIntegerValue(item_task);
}
Boolean isonline;
public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) {
log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false);
} else {
setIsonline(true);
return value;
}
return 0;
}
public String getOpcStringValue(String protocol) {
String value = this.driver.getStringValue(protocol);
if (StrUtil.isEmpty(value)) {
} else {
return value;
}
return "0";
}
public static List<ItemDto> getReadableItemDtos() {
ArrayList list = new ArrayList();
list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0"));
list.add(new ItemDto(item_mode, "工作模式", "DB600.B2"));
list.add(new ItemDto(item_move, "光电信号", "DB600.B3"));
list.add(new ItemDto(item_carrier_direction, "托盘方向", "DB600.B4"));
list.add(new ItemDto(item_error, "报警信号", "DB600.B6"));
list.add(new ItemDto(item_task, "任务号", "DB600.D10"));
return list;
}
public static List<ItemDto> getWriteableItemDtos() {
ArrayList list = new ArrayList();
list.add(new ItemDto(item_to_command, "下发命令", "DB601.W2"));
list.add(new ItemDto(item_to_target, "下发目标站", "DB601.W4"));
list.add(new ItemDto(item_to_container_type, "下发托盘类型", "DB601.W6"));
list.add(new ItemDto(item_to_task, "下发任务号", "DB601.D8"));
list.add(new ItemDto(item_to_strap_times, "困扎次数", "DB601.W12"));
list.add(new ItemDto(item_to_length, "木箱长度", "DB601.W14"));
list.add(new ItemDto(item_to_weight, "木箱宽度", "DB601.W16"));
list.add(new ItemDto(item_to_height, "木箱高度", "DB601.W18"));
return list;
}
}

View File

@@ -0,0 +1,64 @@
package org.nl.acs.device_driver.basedriver.siemens_conveyor;
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;
import org.nl.acs.device_driver.DeviceDriver;
import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination;
import org.nl.acs.opc.Device;
import org.nl.acs.opc.DeviceType;
import org.springframework.stereotype.Service;
import java.util.LinkedList;
import java.util.List;
/**
* 西门子-输送机驱动
*
*/
@Service
public class SiemensConveyorDefination implements OpcDeviceDriverDefination {
@Override
public String getDriverCode() {
return "siemens_conveyor";
}
@Override
public String getDriverName() {
return "西门子-输送机驱动";
}
@Override
public String getDriverDescription() {
return "西门子-输送机驱动";
}
@Override
public DeviceDriver getDriverInstance(Device device) {
return (new SiemensConveyorDeviceDriver()).setDevice(device).setDriverDefination(this);
}
@Override
public Class<? extends DeviceDriver> getDeviceDriverType() {
return SiemensConveyorDeviceDriver.class;
}
@Override
public List<DeviceType> getFitDeviceTypes() {
List<DeviceType> types = new LinkedList();
types.add(DeviceType.station);
return types;
}
@Override
public List<ItemDto> getReadableItemDtos() {
return ItemProtocol.getReadableItemDtos();
}
@Override
public List<ItemDto> getWriteableItemDtos() {
return ItemProtocol.getWriteableItemDtos();
}
}

View File

@@ -0,0 +1,267 @@
package org.nl.acs.device_driver.basedriver.siemens_conveyor;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.device.device_driver.standard_inspect.ReadUtil;
import org.nl.acs.device.service.DeviceService;
import org.nl.acs.device_driver.DeviceDriver;
import org.nl.acs.device_driver.RouteableDeviceDriver;
import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver;
import org.nl.acs.device_driver.driver.ExecutableDeviceDriver;
import org.nl.acs.ext.wms.service.AcsToWmsService;
import org.nl.acs.instruction.service.InstructionService;
import org.nl.acs.instruction.service.dto.Instruction;
import org.nl.acs.log.service.DeviceExecuteLogService;
import org.nl.acs.monitor.DeviceStageMonitor;
import org.nl.acs.opc.Device;
import org.nl.acs.opc.DeviceAppService;
import org.nl.acs.opc.DeviceAppServiceImpl;
import org.nl.acs.route.service.RouteLineService;
import org.nl.acs.task.service.TaskService;
import org.nl.modules.wql.util.SpringContextHolder;
import org.openscada.opc.lib.da.Server;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.*;
/**
* 西门子-输送机驱动
*/
@Slf4j
@Data
@RequiredArgsConstructor
public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor {
protected ItemProtocol itemProtocol = new ItemProtocol(this);
@Autowired
InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl");
@Autowired
DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl");
@Autowired
RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl");
@Autowired
TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl");
@Autowired
DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl");
@Autowired
AcsToWmsService acsToWmsService = SpringContextHolder.getBean("acsToWmsServiceImpl");
@Autowired
DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class);
//工作模式
int mode = 0;
int last_mode = 0;
//光电信号
int move = 0;
int last_move = 0;
//托盘方向
int carrier_direction = 0;
int last_carrier_direction = 0;
//报警信号
int error = 0;
int last_error = 0;
//任务号
int task = 0;
int last_task = 0;
Boolean isonline = true;
int hasGoods = 0;
String message = null;
Boolean iserror = false;
Integer heartbeat_tag;
private Date instruction_require_time = new Date();
private int instruction_require_time_out;
//行架机械手申请任务成功标识
boolean requireSucess = false;
private int instruction_finished_time_out;
int branchProtocol = 0;
//暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域
int flag;
String device_code;
@Override
public Device getDevice() {
return this.device;
}
@Override
public void execute() {
String message = null;
try {
device_code = this.getDeviceCode();
mode = this.itemProtocol.getMode();
move = this.itemProtocol.getMove();
carrier_direction = this.itemProtocol.getCarrier_direction();
error = this.itemProtocol.getError();
task = this.itemProtocol.getTask();
if (mode != last_mode) {
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_mode + "->" + mode);
}
if (move != last_move) {
logServer.deviceItemValue(this.device_code, "move", String.valueOf(move));
logServer.deviceExecuteLog(this.device_code, "", "", "信号move" + last_move + "->" + move);
}
if (carrier_direction != last_carrier_direction) {
logServer.deviceItemValue(this.device_code, "carrier_direction", String.valueOf(carrier_direction));
logServer.deviceExecuteLog(this.device_code, "", "", "信号carrier_direction" + last_carrier_direction + "->" + carrier_direction);
}
if (error != last_error) {
logServer.deviceItemValue(this.device_code, "error", String.valueOf(error));
logServer.deviceExecuteLog(this.device_code, "", "", "信号error" + last_error + "->" + error);
}
if (task != last_task) {
logServer.deviceItemValue(this.device_code, "task", String.valueOf(task));
logServer.deviceExecuteLog(this.device_code, "", "", "信号task" + last_task + "->" + task);
}
} catch (Exception var17) {
return;
}
if (!this.itemProtocol.getIsonline()) {
this.setIsonline(false);
this.setIserror(true);
message = "信号量同步异常";
//未联机
} else if (mode == 0) {
this.setIsonline(false);
this.setIserror(true);
message = "未联机";
//有报警
} else if (error != 0) {
this.setIsonline(false);
this.setIserror(true);
message = "有报警";
//无报警
} else {
this.setIsonline(true);
this.setIserror(false);
message = "";
Instruction instruction = null;
List toInstructions;
}
last_mode = mode;
last_move = move;
last_carrier_direction = carrier_direction;
last_error = error;
last_task = task;
}
public boolean exe_error() {
if (this.error == 0) {
return true;
} else {
log.debug("设备报警");
return false;
}
}
public boolean exe_business() {
return true;
}
public synchronized boolean finish_instruction(Instruction inst) throws Exception {
instructionService.finish(inst);
return true;
}
public void writing(String param, String value) {
String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
+ "." + param;
String opcservcerid = this.getDevice().getOpc_server_id();
Server server = ReadUtil.getServer(opcservcerid);
Map<String, Object> itemMap = new HashMap<String, Object>();
itemMap.put(to_param, value);
// itemMap.put(to_param, Integer.parseInt(value));
ReadUtil.write(itemMap, server);
}
public void executing(Server server, Map<String, Object> itemMap) {
ReadUtil.write(itemMap, server);
}
public void writing(int command) {
String opcservcerid = this.getDevice().getOpc_server_id();
Server server = ReadUtil.getServer(opcservcerid);
Map<String, Object> itemMap = new HashMap<String, Object>();
ReadUtil.write(itemMap, server);
}
@Override
public JSONObject getDeviceStatusName() {
JSONObject jo = new JSONObject();
String mode = "";
String move = "";
String carrier_direction = "";
if (this.getMode() == 0) {
mode = "脱机";
} else if (this.getMode() == 1) {
mode = "单机";
} else if (this.getMode() == 2) {
mode = "待机";
} else if (this.getMode() == 3) {
mode = "运行中";
}
if (this.getMove() == 0) {
move = "无货";
} else if (this.getMove() == 1) {
move = "有货";
}
if (this.carrier_direction == 1) {
carrier_direction = "正转";
} else if (this.carrier_direction == 2) {
carrier_direction = "反转";
}
jo.put("device_name", this.getDevice().getDevice_name());
jo.put("mode", mode);
jo.put("move", move);
jo.put("carrier_direction", carrier_direction);
jo.put("task", task);
jo.put("isOnline", this.getIsonline());
jo.put("error", this.getError());
jo.put("isError", this.getIserror());
jo.put("message", this.getMessage());
return jo;
}
@Override
public void setDeviceStatus(JSONObject data) {
}
// public void writing(int type, int command) {
// String to_material_code = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
// + "." + ItemProtocol.item_to_material_code;
// String opcservcerid = this.getDevice().getOpc_server_id();
// Server server = ReadUtil.getServer(opcservcerid);
// Map<String, Object> itemMap = new HashMap<String, Object>();
// if (type == 2) {
// itemMap.put(to_material_code, command);
// }
// ReadUtil.write(itemMap, server);
//
// }
}

View File

@@ -0,0 +1,168 @@
package org.nl.acs.device_driver.basedriver.slit_two_manipulator;
import cn.hutool.core.util.StrUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@Data
public class ItemProtocol {
//心跳
public static String item_heartbeat = "heartbeat";
//工作模式
public static String item_mode = "mode";
//设备状态
public static String item_status = "status";
//前工位光电信号
public static String item_move1 = "move1";
//后工位光电信号
public static String item_move2 = "move2";
//前工位动作信号
public static String item_action1 = "action1";
//后工位动作信号
public static String item_action2 = "action2";
//行走列
public static String item_walk_y = "walk_y";
//报警信号
public static String item_error = "error";
//前工位任务号
public static String item_task1 = "task1";
//后工位任务号
public static String item_task2 = "task2";
//前工位下发命令
public static String item_to_command1 = "to_command1";
//前工位下发起始站
public static String item_to_onset1 = "to_onset1";
//前工位下发目标站
public static String item_to_target1 = "to_target1";
//前工位下发任务号
public static String item_to_task1 = "to_task1";
//后工位下发命令
public static String item_to_command2 = "to_command2";
//后工位下发起始站
public static String item_to_onset2 = "to_onset2";
//后工位下发目标站
public static String item_to_target2 = "to_target2";
//后工位下发任务号
public static String item_to_task2 = "to_task2";
private SlitTwoManipulatorDeviceDriver driver;
public ItemProtocol(SlitTwoManipulatorDeviceDriver driver) {
this.driver = driver;
}
public int getHeartbeat() {
return this.getOpcIntegerValue(item_heartbeat);
}
public int getMode() {
return this.getOpcIntegerValue(item_mode);
}
public int getStatus() {
return this.getOpcIntegerValue(item_status);
}
public int getError() {
return this.getOpcIntegerValue(item_error);
}
public int getMove1() {
return this.getOpcIntegerValue(item_move1);
}
public int getMove2() {
return this.getOpcIntegerValue(item_move2);
}
public int getAction1() {
return this.getOpcIntegerValue(item_action1);
}
public int getAction2() {
return this.getOpcIntegerValue(item_action2);
}
public int getWalk_y() {
return this.getOpcIntegerValue(item_walk_y);
}
public int getTask1() {
return this.getOpcIntegerValue(item_task1);
}
public int getTask2() {
return this.getOpcIntegerValue(item_task2);
}
//是否有货
public int hasGoods(int move) {
return move;
}
Boolean isonline;
public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) {
log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false);
} else {
setIsonline(true);
return value;
}
return 0;
}
public String getOpcStringValue(String protocol) {
String value = this.driver.getStringValue(protocol);
if (StrUtil.isEmpty(value)) {
} else {
return value;
}
return "0";
}
public static List<ItemDto> getReadableItemDtos() {
ArrayList list = new ArrayList();
list.add(new ItemDto(item_heartbeat, "心跳", "DB1.B0"));
list.add(new ItemDto(item_mode, "工作模式", "DB1.B1"));
list.add(new ItemDto(item_status, "设备状态", "DB1.B2"));
list.add(new ItemDto(item_move1, "前工位光电信号", "DB1.B3"));
list.add(new ItemDto(item_move2, "后工位光电信号", "DB1.B4"));
list.add(new ItemDto(item_action1, "前工位动作信号", "DB1.B5"));
list.add(new ItemDto(item_action2, "后工位动作信号", "DB2.B6"));
list.add(new ItemDto(item_walk_y, "行走列", "DB1.B7"));
list.add(new ItemDto(item_error, "报警信号", "DB1.B8"));
list.add(new ItemDto(item_task1, "前工位任务号", "DB1.D10"));
list.add(new ItemDto(item_task2, "后工位任务号", "DB1.D14"));
return list;
}
public static List<ItemDto> getWriteableItemDtos() {
ArrayList list = new ArrayList();
list.add(new ItemDto(item_to_command1, "前工位下发命令", "DB2.W0"));
list.add(new ItemDto(item_to_onset1, "前工位下发起始站", "DB2.W2"));
list.add(new ItemDto(item_to_target1, "前工位下发目标站", "DB2.W4"));
list.add(new ItemDto(item_to_task1, "前工位下发任务号", "DB2.D6"));
list.add(new ItemDto(item_to_command2, "后工位下发命令", "DB2.W10"));
list.add(new ItemDto(item_to_onset2, "后工位下发起始站", "DB2.W12"));
list.add(new ItemDto(item_to_target2, "后工位下发目标站", "DB2.W14"));
list.add(new ItemDto(item_to_task2, "后工位下发任务号", "DB2.D16"));
return list;
}
}

View File

@@ -0,0 +1,62 @@
package org.nl.acs.device_driver.basedriver.slit_two_manipulator;
import org.nl.acs.device.device_driver.standard_inspect.ItemDto;
import org.nl.acs.device_driver.DeviceDriver;
import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination;
import org.nl.acs.opc.Device;
import org.nl.acs.opc.DeviceType;
import org.springframework.stereotype.Service;
import java.util.LinkedList;
import java.util.List;
/**
* 分切双工位行架机械手
*
*/
@Service
public class SlitTwoManipulatorDefination implements OpcDeviceDriverDefination {
@Override
public String getDriverCode() {
return "slit_two_manipulator";
}
@Override
public String getDriverName() {
return "分切双工位-行架机械手";
}
@Override
public String getDriverDescription() {
return "分切双工位-行架机械手";
}
@Override
public DeviceDriver getDriverInstance(Device device) {
return (new SlitTwoManipulatorDeviceDriver()).setDevice(device).setDriverDefination(this);
}
@Override
public Class<? extends DeviceDriver> getDeviceDriverType() {
return SlitTwoManipulatorDeviceDriver.class;
}
@Override
public List<DeviceType> getFitDeviceTypes() {
List<DeviceType> types = new LinkedList();
types.add(DeviceType.station);
return types;
}
@Override
public List<ItemDto> getReadableItemDtos() {
return ItemProtocol.getReadableItemDtos();
}
@Override
public List<ItemDto> getWriteableItemDtos() {
return ItemProtocol.getWriteableItemDtos();
}
}

View File

@@ -0,0 +1,392 @@
package org.nl.acs.device_driver.basedriver.slit_two_manipulator;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.device.device_driver.standard_inspect.ReadUtil;
import org.nl.acs.device.service.DeviceService;
import org.nl.acs.device_driver.DeviceDriver;
import org.nl.acs.device_driver.RouteableDeviceDriver;
import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver;
import org.nl.acs.device_driver.driver.ExecutableDeviceDriver;
import org.nl.acs.ext.wms.service.AcsToWmsService;
import org.nl.acs.instruction.service.InstructionService;
import org.nl.acs.instruction.service.dto.Instruction;
import org.nl.acs.log.service.DeviceExecuteLogService;
import org.nl.acs.monitor.DeviceStageMonitor;
import org.nl.acs.opc.Device;
import org.nl.acs.opc.DeviceAppService;
import org.nl.acs.opc.DeviceAppServiceImpl;
import org.nl.acs.route.service.RouteLineService;
import org.nl.acs.task.service.TaskService;
import org.nl.modules.wql.util.SpringContextHolder;
import org.openscada.opc.lib.da.Server;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.*;
/**
* 分切双工位行架机械手
*/
@Slf4j
@Data
@RequiredArgsConstructor
public class SlitTwoManipulatorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor {
protected ItemProtocol itemProtocol = new ItemProtocol(this);
@Autowired
InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl");
@Autowired
DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl");
@Autowired
RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl");
@Autowired
TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl");
@Autowired
AcsToWmsService acsToWmsService = SpringContextHolder.getBean("acsToWmsServiceImpl");
@Autowired
DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppServiceImpl.class);
//当前指令1
Instruction inst1 = null;
//当前指令2
Instruction inst2 = null;
DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl");
//工作模式
int mode = 0;
int last_mode = 0;
//设备状态
int status = 0;
int last_status = 0;
//前后工位光电信号
int move1 = 0;
int last_move1 = 0;
int move2 = 0;
int last_move2 = 0;
//前后工位动作信号
int action1 = 0;
int last_action1 = 0;
int action2 = 0;
int last_action2 = 0;
//报警信号
int error = 0;
int last_error = 0;
//行走列
int walk_y = 0;
int last_walk_y = 0;
//前后工位任务号
int task1 = 0;
int last_task1 = 0;
int task2 = 0;
int last_task2 = 0;
Boolean isonline = true;
//后工位申请任务请求标记
Boolean requireBackSucess = false;
//前工位申请任务请求标记
Boolean requireHeadSucess = false;
int hasGoods = 0;
String message = null;
Boolean iserror = false;
int branchProtocol = 0;
//暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域
int flag;
String device_code;
//请求超时时间
private int instruction_require_time_out = 3000;
@Override
public Device getDevice() {
return this.device;
}
@Override
public void execute() throws Exception {
String message = null;
try {
device_code = this.getDeviceCode();
mode = this.itemProtocol.getMode();
status = this.itemProtocol.getStatus();
move1 = this.itemProtocol.getMove1();
move2 = this.itemProtocol.getMove2();
action1 = this.itemProtocol.getAction1();
action2 = this.itemProtocol.getAction2();
walk_y = this.itemProtocol.getWalk_y();
error = this.itemProtocol.getError();
task1 = this.itemProtocol.getTask1();
task2 = this.itemProtocol.getTask2();
if (mode != last_mode) {
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode" + last_mode + "->" + mode);
}
if (error != last_error) {
logServer.deviceItemValue(this.device_code, "error", String.valueOf(error));
logServer.deviceExecuteLog(this.device_code, "", "", "信号error" + last_error + "->" + error);
}
if (status != last_status) {
logServer.deviceItemValue(this.device_code, "status", String.valueOf(status));
logServer.deviceExecuteLog(this.device_code, "", "", "信号status" + last_status + "->" + status);
}
if (move1 != last_move1) {
logServer.deviceItemValue(this.device_code, "move1", String.valueOf(move1));
logServer.deviceExecuteLog(this.device_code, "", "", "信号move1" + last_move1 + "->" + move1);
}
if (move2 != last_move2) {
logServer.deviceItemValue(this.device_code, "move2", String.valueOf(move2));
logServer.deviceExecuteLog(this.device_code, "", "", "信号move2" + last_move2 + "->" + move2);
}
if (action1 != last_action1) {
logServer.deviceItemValue(this.device_code, "action1", String.valueOf(action1));
logServer.deviceExecuteLog(this.device_code, "", "", "信号action1" + last_action1 + "->" + action1);
}
if (action2 != last_action2) {
logServer.deviceItemValue(this.device_code, "action2", String.valueOf(action2));
logServer.deviceExecuteLog(this.device_code, "", "", "信号action2" + last_action2 + "->" + action2);
}
if (walk_y != last_walk_y) {
logServer.deviceItemValue(this.device_code, "walk_y", String.valueOf(walk_y));
logServer.deviceExecuteLog(this.device_code, "", "", "信号walk_y" + last_walk_y + "->" + walk_y);
}
if (task1 != last_task1) {
logServer.deviceItemValue(this.device_code, "task1", String.valueOf(task1));
logServer.deviceExecuteLog(this.device_code, "", "", "信号task1" + last_task1 + "->" + task1);
}
if (task2 != last_task2) {
logServer.deviceItemValue(this.device_code, "task2", String.valueOf(task2));
logServer.deviceExecuteLog(this.device_code, "", "", "信号task2" + last_task2 + "->" + task2);
}
} catch (Exception var17) {
return;
}
if (!this.itemProtocol.getIsonline()) {
this.setIsonline(false);
this.setIserror(true);
message = "信号量同步异常";
//未联机
} else if (mode == 0) {
this.setIsonline(false);
this.setIserror(true);
message = "未联机";
//有报警
} else if (error != 0) {
this.setIsonline(false);
this.setIserror(true);
message = "有报警";
//无报警
} else {
this.setIsonline(true);
this.setIserror(false);
message = "";
Instruction instruction = null;
List toInstructions;
}
last_mode = mode;
last_error = error;
last_status = status;
last_move1 = move1;
last_move2 = move2;
last_action1 = action1;
last_action2 = action2;
last_walk_y = walk_y;
last_task1 = task1;
last_task2 = task2;
}
public boolean exe_error() {
if (this.error == 0) {
return true;
} else {
log.debug("设备报警");
return false;
}
}
public void writing(String param, String value) {
String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
+ "." + param;
String opcservcerid = this.getDevice().getOpc_server_id();
Server server = ReadUtil.getServer(opcservcerid);
Map<String, Object> itemMap = new HashMap<String, Object>();
itemMap.put(to_param, value);
ReadUtil.write(itemMap, server);
}
public boolean exe_business() {
return true;
}
protected void executing(Instruction instruction) {
this.executing(1, instruction, "");
}
public void executing(int command, Instruction instruction, String appendMessage) {
String opcservcerid = this.getDevice().getOpc_server_id();
Server server = ReadUtil.getServer(opcservcerid);
Map<String, Object> itemMap = new HashMap<String, Object>();
ReadUtil.write(itemMap, server);
}
public synchronized boolean finish_instruction(Instruction inst) throws Exception {
instructionService.finish(inst);
return true;
}
public void executing(Server server, Map<String, Object> itemMap) {
ReadUtil.write(itemMap, server);
}
public void writing1(int command) {
String to_command1 = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
+ "." + ItemProtocol.item_to_command1;
String opcservcerid = this.getDevice().getOpc_server_id();
Server server = ReadUtil.getServer(opcservcerid);
Map<String, Object> itemMap = new HashMap<String, Object>();
itemMap.put(to_command1, command);
ReadUtil.write(itemMap, server);
}
public void writing2(int command) {
String to_command2 = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
+ "." + ItemProtocol.item_to_command2;
String opcservcerid = this.getDevice().getOpc_server_id();
Server server = ReadUtil.getServer(opcservcerid);
Map<String, Object> itemMap = new HashMap<String, Object>();
itemMap.put(to_command2, command);
ReadUtil.write(itemMap, server);
}
public void writing(int type, int command) {
String opcservcerid = this.getDevice().getOpc_server_id();
Server server = ReadUtil.getServer(opcservcerid);
Map<String, Object> itemMap = new HashMap<String, Object>();
ReadUtil.write(itemMap, server);
}
//将扩展表中的字符串数组数据转换成集合
public List<String> getExtraDeviceCodes(String extraName){
String extraValue = (String) this.getDevice().getExtraValue().get(extraName);
String devicesString = extraValue.substring(1, extraValue.length() - 1);
List<String> devicesList = new ArrayList<>();
String[] devices = devicesString.split(",");
for (int i = 0; i < devices.length; i++) {
String s = devices[i].replace("\"", "").replace("\"", "");
devicesList.add(s);
}
return devicesList;
}
@Override
public JSONObject getDeviceStatusName() {
JSONObject jo = new JSONObject();
String move1 = "";
String move2 = "";
String action1 = "";
String action2 = "";
String walk_y = "";
String mode = "";
String status = "";
if (this.getMode() == 0) {
mode = "脱机";
} else if (this.getMode() == 1) {
mode = "单机";
} else if (this.getMode() == 2) {
mode = "待机";
} else if (this.getMode() == 3) {
mode = "运行中";
}
if (this.getStatus() == 1) {
status = "待机";
} else if (this.getStatus() == 2) {
status = "生产中";
} else if (this.getStatus() == 3) {
status = "故障";
}
if (this.getMove1() == 0) {
move1 = "无货";
} else if (this.getMove1() == 1) {
move1 = "有货";
}
if (this.getMove2() == 0) {
move2 = "无货";
} else if (this.getMove2() == 1) {
move2 = "有货";
}
if (this.getAction1() == 1) {
action1 = "取货中";
} else if (this.getAction1() == 2) {
action1 = "取货完成";
} else if (this.getAction1() == 3) {
action1 = "放货中";
} else if (this.getAction1() == 4) {
action1 = "放货完成";
}
if (this.getAction2() == 1) {
action2 = "取货中";
} else if (this.getAction2() == 2) {
action2 = "取货完成";
} else if (this.getAction2() == 3) {
action2 = "放货中";
} else if (this.getAction2() == 4) {
action2 = "放货完成";
}
if (this.getWalk_y() == 0) {
walk_y = "原位";
} else if (this.getWalk_y() == 2) {
walk_y = "非原位";
}
jo.put("device_name", this.getDevice().getDevice_name());
jo.put("mode", mode);
jo.put("status", status);
jo.put("move1", move1);
jo.put("move2", move2);
jo.put("action1", action1);
jo.put("action2", action2);
jo.put("walk_y", walk_y);
jo.put("error", this.getError());
jo.put("task1", this.getTask1());
jo.put("task2", this.getTask2());
jo.put("isOnline", this.getIsonline());
jo.put("isError", this.getIserror());
jo.put("message", this.getMessage());
return jo;
}
@Override
public void setDeviceStatus(JSONObject data) {
}
}