This commit is contained in:
USER-20220102CG\noblelift
2022-07-12 21:24:25 +08:00
parent 3ee0d6d5ae
commit 40b33f447c
6 changed files with 1108 additions and 3 deletions

View File

@@ -61,7 +61,10 @@ public enum DriverTypeEnum {
HAILIANG_PACKER_STATION(26, "hailiang_packer_station", "海亮-包装机工位", "conveyor"),
HAILIANG_XJ_PLC_TEST(27, "hailiang_xj_plc_test", "海亮-信捷PLC", "conveyor");
HAILIANG_XJ_PLC_TEST(27, "hailiang_xj_plc_test", "海亮-信捷PLC", "conveyor"),
HAILIANG_SMART_PLC_TEST(28, "hailiang_smart_plc_test", "海亮-西门子SMART200PLC", "conveyor");
//驱动索引

View File

@@ -0,0 +1,61 @@
package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_smart_plc_test;
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;
/**
* 海亮迅捷plc测试
*/
@Service
public class HailiangSmartplcTestDefination implements OpcDeviceDriverDefination {
@Override
public String getDriverCode() {
return "hailiang_smart_plc_test";
}
@Override
public String getDriverName() {
return "海亮-西门子plc测试";
}
@Override
public String getDriverDescription() {
return "海亮-西门子plc测试";
}
@Override
public DeviceDriver getDriverInstance(Device device) {
return (new HailiangSmartplcTestDeviceDriver()).setDevice(device).setDriverDefination(this);
}
@Override
public Class<? extends DeviceDriver> getDeviceDriverType() {
return HailiangSmartplcTestDeviceDriver.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();
}
}

View File

@@ -0,0 +1,289 @@
package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_smart_plc_test;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.agv.server.AgvService;
import org.nl.acs.config.server.AcsConfigService;
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.ext.wms.service.impl.AcsToWmsServiceImpl;
import org.nl.acs.instruction.service.InstructionService;
import org.nl.acs.instruction.service.dto.Instruction;
import org.nl.acs.log.service.LogServer;
import org.nl.acs.opc.Device;
import org.nl.acs.opc.DeviceAppService;
import org.nl.acs.order.service.ProduceshiftorderService;
import org.nl.acs.route.service.RouteLineService;
import org.nl.acs.task.service.TaskService;
import org.nl.utils.SpringContextHolder;
import org.openscada.opc.lib.da.Server;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* 海亮清洗机储料仓
*/
@Slf4j
@Data
@RequiredArgsConstructor
public class HailiangSmartplcTestDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver {
protected ItemProtocol itemProtocol = new ItemProtocol(this);
@Autowired
DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class);
@Autowired
InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class);
@Autowired
DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class);
@Autowired
TaskService taskserver = SpringContextHolder.getBean(TaskService.class);
@Autowired
RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class);
@Autowired
AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class);
@Autowired
AcsConfigService acsConfigService = SpringContextHolder.getBean(AcsConfigService.class);
@Autowired
LogServer logServer = SpringContextHolder.getBean(LogServer.class);
@Autowired
ProduceshiftorderService produceshiftorderService = SpringContextHolder.getBean(ProduceshiftorderService.class);
@Autowired
AgvService agvService = SpringContextHolder.getBean(AgvService.class);
String container;
String container_type_desc;
String last_container_type_desc;
String last_container;
//放货准备锁
String putReadyLock = null;
//有货标记
protected boolean has_goods_tag = false;
int heartbeat = 0;
int mode =0;
int error =0;
int error_num =0;
int open_time =0;
int close_time =0;
int ready_time =0;
int running_time =0;
int error_time =0;
int voltage =0;
int temperature =0;
int current =0;
int material =0;
int lack_material =0;
int full_material =0;
int storage_qty =0;
int feeding_qty =0;
int blanking_qty =0;
int qualified_qty =0;
int unqualified_qty =0;
int finish =0;
int task =0;
int noload_electricity_consumption =0;
int prod_electricity_consumption =0;
int gas_consumption =0;
int water_consumption =0;
int oil_level =0;
int monthly_electricity_consumption =0;
int pause =0;
int last_mode =0;
int last_error =0;
int last_error_num =0;
int last_open_time =0;
int last_close_time =0;
int last_ready_time =0;
int last_running_time =0;
int last_error_time =0;
int last_voltage =0;
int last_temperature =0;
int last_current =0;
int last_material =0;
int last_lack_material =0;
int last_full_material =0;
int last_storage_qty =0;
int last_feeding_qty =0;
int last_blanking_qty =0;
int last_qualified_qty =0;
int last_unqualified_qty =0;
int last_finish =0;
int last_task =0;
int last_noload_electricity_consumption =0;
int last_prod_electricity_consumption =0;
int last_gas_consumption =0;
int last_water_consumption =0;
int last_oil_level =0;
int last_monthly_electricity_consumption =0;
int last_pause =0;
Boolean isonline = true;
int hasGoods = 0;
String message = null;
Boolean iserror = false;
boolean hasVehicle = false;
boolean isReady = false;
protected int instruction_num = 0;
protected int instruction_num_truth = 0;
boolean isFold = false;
private String assemble_check_tag;
private Date instruction_require_time = new Date();
private Date instruction_finished_time = new Date();
private Date instruction_apply_time = new Date();
private int instruction_require_time_out = 3000;
//请求成功标记
Boolean requireSucess = false;
//申请指令成功标记
Boolean applySucess = false;
String inst_message;
private int instruction_finished_time_out;
int branchProtocol = 0;
//备注
String remark;
//数量
String qty;
//当前指令
Instruction inst = null;
//上次指令
Instruction last_inst = null;
//暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域
int flag = 0;
int agvphase=0;
int index =0;
String device_code;
@Override
public Device getDevice() {
return this.device;
}
@Override
public void execute() throws Exception {
device_code = this.getDeviceCode();
heartbeat = this.itemProtocol.getItem_heartbeat();
mode = this.itemProtocol.getItem_mode();
error = this.itemProtocol.getItem_error();
error_num = this.itemProtocol.getItem_error_num();
open_time = this.itemProtocol.getItem_open_time();
close_time = this.itemProtocol.getItem_close_time();
ready_time = this.itemProtocol.getItem_ready_time();
running_time = this.itemProtocol.getItem_running_time();
error_time = this.itemProtocol.getItem_error_time();
voltage = this.itemProtocol.getItem_voltage();
temperature = this.itemProtocol.getItem_temperature();
current = this.itemProtocol.getItem_current();
material = this.itemProtocol.getItem_material();
lack_material = this.itemProtocol.getItem_lack_material();
full_material = this.itemProtocol.getItem_full_material();
storage_qty = this.itemProtocol.getItem_storage_qty();
feeding_qty = this.itemProtocol.getItem_feeding_qty();
blanking_qty = this.itemProtocol.getItem_blanking_qty();
qualified_qty = this.itemProtocol.getItem_qualified_qty();
unqualified_qty = this.itemProtocol.getItem_unqualified_qty();
finish = this.itemProtocol.getItem_finish();
task = this.itemProtocol.getItem_task();
noload_electricity_consumption = this.itemProtocol.getItem_noload_electricity_consumption();
prod_electricity_consumption = this.itemProtocol.getItem_prod_electricity_consumption();
gas_consumption = this.itemProtocol.getItem_gas_consumption();
water_consumption = this.itemProtocol.getItem_water_consumption();
oil_level = this.itemProtocol.getItem_oil_level();
monthly_electricity_consumption = this.itemProtocol.getItem_monthly_electricity_consumption();
pause = this.itemProtocol.getItem_pause();
if (mode != last_mode) {
this.setRequireSucess(false);
logServer.deviceLogToacs(this.device_code,"","","工作模式切换,刷新请求标记:"+this.requireSucess);
logServer.deviceLog(this.device_code,"mode" ,String.valueOf(mode));
logServer.deviceLogToacs(this.device_code,"","","信号mode:" + last_mode + "->" + mode);
}
if (error != last_error) {
logServer.deviceLog(this.device_code,"error" ,String.valueOf(error));
logServer.deviceLogToacs(this.device_code,"","","信号error:" + last_error + "->" + error);
}
}
public boolean exe_error() {
if (this.error == 0) {
return true;
} else {
log.debug("设备报警");
return false;
}
}
protected void thingToNothing() {
log.debug("从有货到无货 清理数据");
logServer.deviceLogToacs(this.device_code,"","","光电信号切换,刷新请求标记:"+this.requireSucess);
this.setRequireSucess(false);
this.setApplySucess(false);
this.set_last_container(container, container_type_desc);
}
public void set_last_container(String barcode, String type_desc) {
this.setInst_message(null);
this.setContainer(null);
this.set_last_container(barcode);
this.set_last_container_type_desc(type_desc);
}
public void set_last_container(String barcode) {
}
public void set_last_container_type_desc(String type) {
}
public boolean exe_business() {
return true;
}
protected void executing(Instruction instruction) {
this.executing(1, instruction, "");
}
public void executing(int command, Instruction instruction, String appendMessage) {
}
public void executing(Server server, Map<String, Object> itemMap) {
ReadUtil.write(itemMap, server);
}
public void writing(int command) {
}
public void writing(String key, String value) {
String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
+ "." + key;
String opcservcerid = this.getDevice().getOpc_server_id();
Server server = ReadUtil.getServer(opcservcerid);
Map<String, Object> itemMap = new HashMap<String, Object>();
itemMap.put(to_command, value);
ReadUtil.write(itemMap, server);
}
}

View File

@@ -0,0 +1,248 @@
package org.nl.acs.device_driver.basedriver.hailiang_one.hailiang_smart_plc_test;
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_error = "error";
public static String item_error_num = "error_num";
public static String item_open_time = "open_time";
public static String item_close_time = "close_time"; //
public static String item_ready_time = "ready_time"; //
public static String item_running_time = "running_time";
public static String item_error_time = "error_time";
public static String item_voltage = "voltage";
public static String item_temperature = "temperature";
public static String item_current = "current";
public static String item_material = "material";
public static String item_lack_material = "lack_material";
public static String item_full_material = "full_material";
public static String item_storage_qty = "storage_qty";
public static String item_feeding_qty = "feeding_qty";
public static String item_blanking_qty = "blanking_qty";
public static String item_qualified_qty = "qualified_qty";
public static String item_unqualified_qty = "unqualified_qty";
public static String item_finish = "finish";
public static String item_task = "task";
public static String item_noload_electricity_consumption = "noload_electricity_consumption";
public static String item_prod_electricity_consumption = "prod_electricity_consumption";
public static String item_gas_consumption = "gas_consumption";
public static String item_water_consumption = "water_consumption";
public static String item_oil_level = "oil_level";
public static String item_monthly_electricity_consumption = "monthly_electricity_consumption";
public static String item_pause = "pause";
public static String item_to_heartbeat = "to_heartbeat";//
public static String item_to_command = "to_command";//
public static String item_to_feeding = "to_feeding";//
public static String item_to_task = "to_task";//
public static String item_to_pause= "to_pause";//
public static String item_to_clear = "to_clear";//
public static String item_to_finish = "to_finish";//
public static String item_to_open = "to_open";//
public static String item_to_close = "to_close";//
public static String item_to_material = "to_material";//
public static String item_to_qty = "to_qty";//
private HailiangSmartplcTestDeviceDriver driver;
public ItemProtocol(HailiangSmartplcTestDeviceDriver driver) {
this.driver = driver;
}
public int getItem_heartbeat() {
return this.getOpcIntegerValue(item_heartbeat);
}
public int getItem_mode() {
return this.getOpcIntegerValue(item_mode);
}
public int getItem_error() {
return this.getOpcIntegerValue(item_error);
}
public int getItem_error_num() {
return this.getOpcIntegerValue(item_error_num);
}
public int getItem_open_time() {
return this.getOpcIntegerValue(item_open_time);
}
public int getItem_close_time() {
return this.getOpcIntegerValue(item_close_time);
}
public int getItem_ready_time() {
return this.getOpcIntegerValue(item_ready_time);
}
public int getItem_running_time() {
return this.getOpcIntegerValue(item_running_time);
}
public int getItem_error_time() {
return this.getOpcIntegerValue(item_error_time);
}
public int getItem_voltage() {
return this.getOpcIntegerValue(item_voltage);
}
public int getItem_temperature() {
return this.getOpcIntegerValue(item_temperature);
}
public int getItem_current() {
return this.getOpcIntegerValue(item_current);
}
public int getItem_material() {
return this.getOpcIntegerValue(item_material);
}
public int getItem_lack_material() {
return this.getOpcIntegerValue(item_lack_material);
}
public int getItem_full_material() {
return this.getOpcIntegerValue(item_full_material);
}
public int getItem_storage_qty() {
return this.getOpcIntegerValue(item_storage_qty);
}
public int getItem_feeding_qty() {
return this.getOpcIntegerValue(item_feeding_qty);
}
public int getItem_blanking_qty() {
return this.getOpcIntegerValue(item_blanking_qty);
}
public int getItem_qualified_qty() {
return this.getOpcIntegerValue(item_qualified_qty);
}
public int getItem_unqualified_qty() {
return this.getOpcIntegerValue(item_unqualified_qty);
}
public int getItem_finish() {
return this.getOpcIntegerValue(item_mode);
}
public int getItem_task() {
return this.getOpcIntegerValue(item_task);
}
public int getItem_noload_electricity_consumption() {
return this.getOpcIntegerValue(item_noload_electricity_consumption);
}
public int getItem_prod_electricity_consumption() {
return this.getOpcIntegerValue(item_prod_electricity_consumption);
}
public int getItem_gas_consumption() {
return this.getOpcIntegerValue(item_gas_consumption);
}
public int getItem_water_consumption() {
return this.getOpcIntegerValue(item_water_consumption);
}
public int getItem_oil_level() {
return this.getOpcIntegerValue(item_oil_level);
}
public int getItem_monthly_electricity_consumption() {
return this.getOpcIntegerValue(item_monthly_electricity_consumption);
}
public int getItem_pause() {
return this.getOpcIntegerValue(item_pause);
}
Boolean isonline;
public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) {
setIsonline(false);
} else {
setIsonline(true);
return value;
}
return 0;
}
public static List<ItemDto> getReadableItemDtos() {
ArrayList list = new ArrayList();
list.add(new ItemDto(item_heartbeat, "心跳", "VW0"));
list.add(new ItemDto(item_mode, "模式", "VW2"));
list.add(new ItemDto(item_error, "故障", "VW4"));
list.add(new ItemDto(item_error_num, "故障次数", "VD6"));
list.add(new ItemDto(item_open_time, "开机时间", "VD8"));
list.add(new ItemDto(item_close_time, "关机时间", "VD12"));
list.add(new ItemDto(item_ready_time, "待机时间", "VD16"));
list.add(new ItemDto(item_running_time, "生产时间", "VD20"));
list.add(new ItemDto(item_error_time, "故障时间", "VD24"));
list.add(new ItemDto(item_temperature, "温度", "VD28"));
list.add(new ItemDto(item_voltage, "电压", "VD32"));
list.add(new ItemDto(item_current, "电流", "VD36"));
list.add(new ItemDto(item_material, "当前生产产品编号", "VD40"));
list.add(new ItemDto(item_lack_material, "生产缺料信号", "VD44"));
list.add(new ItemDto(item_full_material, "生产满料信号", "VD48"));
list.add(new ItemDto(item_storage_qty, "储料斗数量", "VD52"));
list.add(new ItemDto(item_feeding_qty, "上料数量", "VD56"));
list.add(new ItemDto(item_blanking_qty, "下料数量", "VD60"));
list.add(new ItemDto(item_qualified_qty, "当前生产合格品数量", "VD64"));
list.add(new ItemDto(item_unqualified_qty, "当前生产不合格数量", "VD68"));
list.add(new ItemDto(item_finish, "生产完成", "VD72"));
list.add(new ItemDto(item_task, "任务号", "VD76"));
list.add(new ItemDto(item_noload_electricity_consumption, "空载电能耗(未生产时)", "VD80"));
list.add(new ItemDto(item_prod_electricity_consumption, "生产电能耗", "VD84"));
list.add(new ItemDto(item_gas_consumption, "气压能耗", "VD88"));
list.add(new ItemDto(item_water_consumption, "水流量能耗", "VD92"));
list.add(new ItemDto(item_oil_level, "当前液压油位", "VD96"));
list.add(new ItemDto(item_monthly_electricity_consumption, "本月总电能耗", "VD100"));
list.add(new ItemDto(item_pause, "设备暂停", "VD104"));
return list;
}
public static List<ItemDto> getWriteableItemDtos() {
ArrayList list = new ArrayList();
list.add(new ItemDto(item_to_heartbeat, "心跳", "VW200"));
list.add(new ItemDto(item_to_command, "下发命令", "VW202"));
list.add(new ItemDto(item_to_feeding, "下发命令", "VW204"));
list.add(new ItemDto(item_to_task, "任务号", "VW208"));
list.add(new ItemDto(item_to_pause, "生产暂停", "VW212"));
list.add(new ItemDto(item_to_clear, "当前产量清零", "VW216"));
list.add(new ItemDto(item_to_finish, "强制完成", "VW220"));
list.add(new ItemDto(item_to_open, "设备开机", "VW224"));
list.add(new ItemDto(item_to_close, "设备关机", "VW228"));
list.add(new ItemDto(item_to_material, "当前任务生产物料", "VW232"));
list.add(new ItemDto(item_to_qty, "当前任务生产数量", "VW236"));
return list;
}
}