21 changed files with 954 additions and 94 deletions
@ -0,0 +1,156 @@ |
|||
package org.nl.acs.device_driver.lnsh.lnsh_material_distribution; |
|||
|
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.nl.acs.device.device_driver.standard_inspect.ItemDto; |
|||
|
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
@Slf4j |
|||
@Getter |
|||
@Setter |
|||
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_error = "error"; |
|||
public static String item_action = "action"; |
|||
public static String item_open_time = "open_time"; |
|||
public static String item_standby_time = "standby_time"; |
|||
public static String item_production_time = "production_time"; |
|||
public static String item_error_time = "error_time"; |
|||
public static String item_slip = "slip"; |
|||
public static String item_set_weight = "set_weight"; |
|||
public static String item_weight = "weight"; |
|||
public static String item_to_command = "to_command"; |
|||
public static String item_to_error = "to_error"; |
|||
public static String item_to_slip = "to_slip"; |
|||
private LnshMaterialDistributionDeviceDriver driver; |
|||
|
|||
public ItemProtocol(LnshMaterialDistributionDeviceDriver driver) { |
|||
this.driver = driver; |
|||
} |
|||
|
|||
public int getHeartbeat() { |
|||
return this.getOpcIntegerValue(item_heartbeat); |
|||
} |
|||
|
|||
public int getStatus() { |
|||
return this.getOpcIntegerValue(item_status); |
|||
} |
|||
|
|||
public int getMode() { |
|||
return this.getOpcIntegerValue(item_mode); |
|||
} |
|||
|
|||
public int getAction() { |
|||
return this.getOpcIntegerValue(item_action); |
|||
} |
|||
|
|||
public int getError() { |
|||
return this.getOpcIntegerValue(item_error); |
|||
} |
|||
|
|||
public String getOpen_time() { |
|||
return this.getOpcStringValue(item_open_time); |
|||
} |
|||
|
|||
public int getStandby_time() { |
|||
return this.getOpcIntegerValue(item_standby_time); |
|||
} |
|||
|
|||
public int getProduction_time() { |
|||
return this.getOpcIntegerValue(item_production_time); |
|||
} |
|||
|
|||
public int getError_time() { |
|||
return this.getOpcIntegerValue(item_error_time); |
|||
} |
|||
|
|||
public String getSlip() { return this.getOpcStringValue(item_slip); } |
|||
|
|||
public Float getSetWeight() { return this.getFloatValue(item_set_weight); } |
|||
|
|||
public Float getWeight() { return this.getFloatValue(item_weight); } |
|||
|
|||
public int getTo_command() { |
|||
return this.getOpcIntegerValue(item_to_command); |
|||
} |
|||
|
|||
public int getTo_error() { |
|||
return this.getOpcIntegerValue(item_to_error); |
|||
} |
|||
|
|||
public int getTo_slip() { |
|||
return this.getOpcIntegerValue(item_to_slip); |
|||
} |
|||
//是否有货
|
|||
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 Float getFloatValue(String protocol) { |
|||
Float value = this.driver.getFloatValue(protocol); |
|||
if (value == null) { |
|||
// log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
|
|||
setIsonline(false); |
|||
} else { |
|||
setIsonline(true); |
|||
return value; |
|||
} |
|||
return 0f; |
|||
} |
|||
|
|||
public String getOpcStringValue(String protocol) { |
|||
String value = this.driver.getStringValue(protocol); |
|||
if (value == null) { |
|||
// log.error("读取错误!");
|
|||
} else { |
|||
return value; |
|||
} |
|||
return ""; |
|||
} |
|||
|
|||
public static List<ItemDto> getReadableItemDtos() { |
|||
ArrayList list = new ArrayList(); |
|||
list.add(new ItemDto(item_heartbeat, "心跳", "DB200.B0")); |
|||
list.add(new ItemDto(item_mode, "工作模式", "DB200.B1", Boolean.valueOf(true))); |
|||
list.add(new ItemDto(item_status, "设备状态", "DB200.B2")); |
|||
list.add(new ItemDto(item_action, "动作", "DB200.B3")); |
|||
list.add(new ItemDto(item_error, "故障", "DB200.B4")); |
|||
list.add(new ItemDto(item_open_time, "开机时间", "DB200.STRING6.50")); |
|||
list.add(new ItemDto(item_standby_time, "待机时间", "DB200.D58")); |
|||
list.add(new ItemDto(item_production_time, "生产时间", "DB200.D62")); |
|||
list.add(new ItemDto(item_error_time, "故障时间", "DB200.D66")); |
|||
list.add(new ItemDto(item_slip, "泥料批次", "DB200.STRING70.50")); |
|||
list.add(new ItemDto(item_set_weight, "设定重量", "DB200.REAL122")); |
|||
list.add(new ItemDto(item_weight, "称重重量", "DB200.REAL126")); |
|||
return list; |
|||
} |
|||
|
|||
public static List<ItemDto> getWriteableItemDtos() { |
|||
ArrayList list = new ArrayList(); |
|||
list.add(new ItemDto(item_to_command, "反馈", "DB201.W0", Boolean.valueOf(true))); |
|||
list.add(new ItemDto(item_to_error, "物料不一致", "DB200.B2")); |
|||
list.add(new ItemDto(item_to_slip, "下发泥料批次", "DB201.STRING4.50")); |
|||
return list; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,58 @@ |
|||
package org.nl.acs.device_driver.lnsh.lnsh_material_distribution; |
|||
|
|||
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 LnshMaterialDistributionDefination implements OpcDeviceDriverDefination { |
|||
@Override |
|||
public String getDriverCode() { |
|||
return "lnsh_material_distribution"; |
|||
} |
|||
|
|||
@Override |
|||
public String getDriverName() { |
|||
return "标准版-布料机"; |
|||
} |
|||
|
|||
@Override |
|||
public String getDriverDescription() { |
|||
return "标准版-布料机"; |
|||
} |
|||
|
|||
@Override |
|||
public DeviceDriver getDriverInstance(Device device) { |
|||
return (new LnshMaterialDistributionDeviceDriver()).setDevice(device).setDriverDefination(this); |
|||
|
|||
} |
|||
|
|||
@Override |
|||
public Class<? extends DeviceDriver> getDeviceDriverType() { |
|||
return LnshMaterialDistributionDeviceDriver.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(); |
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,491 @@ |
|||
package org.nl.acs.device_driver.lnsh.lnsh_material_distribution; |
|||
import cn.hutool.core.util.ObjectUtil; |
|||
import cn.hutool.core.util.StrUtil; |
|||
import com.alibaba.fastjson.JSON; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import lombok.Getter; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.Setter; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.nl.acs.AcsConfig; |
|||
import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; |
|||
import org.nl.acs.device.service.DeviceService; |
|||
import org.nl.acs.device_driver.*; |
|||
import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; |
|||
import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; |
|||
import org.nl.acs.device_driver.lnsh.conveyor_press_station.ConveyorPressStationDeviceDriver; |
|||
import org.nl.acs.device_driver.lnsh.lnsh_palletizing_manipulator_site.LnshPalletizingManipulatorSiteDeviceDriver; |
|||
import org.nl.acs.ext.wms.data.AcsToWmsData.applyTask.ApplyDeviceDto; |
|||
import org.nl.acs.ext.wms.data.AcsToWmsData.applyTask.ApplyTaskRequest; |
|||
import org.nl.acs.ext.wms.data.AcsToWmsData.applyTask.ApplyTaskResponse; |
|||
import org.nl.acs.ext.wms.data.AcsToWmsData.cloth.ClothRequest; |
|||
import org.nl.acs.ext.wms.data.AcsToWmsData.grab.GrabRequest; |
|||
import org.nl.acs.ext.wms.service.AcsToWmsService; |
|||
import org.nl.acs.heartbeat.HeartbeatEvent; |
|||
import org.nl.acs.heartbeat.dto.HeartbeatManageDto; |
|||
import org.nl.acs.heartbeat.enums.HeartbeatType; |
|||
import org.nl.acs.heartbeat.service.HeartbeatUnifiedService; |
|||
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.ObjectUtl; |
|||
import org.nl.acs.order.service.ProduceshiftorderService; |
|||
import org.nl.acs.route.service.RouteLineService; |
|||
import org.nl.acs.task.service.TaskService; |
|||
import org.nl.modules.lucene.service.LuceneExecuteLogService; |
|||
import org.nl.modules.lucene.service.dto.LuceneLogDto; |
|||
import org.nl.modules.system.service.ParamService; |
|||
import org.nl.modules.system.service.impl.ParamServiceImpl; |
|||
import org.nl.modules.wql.util.SpringContextHolder; |
|||
import org.openscada.opc.lib.da.Server; |
|||
|
|||
import java.lang.reflect.Field; |
|||
import java.lang.reflect.Method; |
|||
import java.util.*; |
|||
@Slf4j |
|||
@Getter |
|||
@Setter |
|||
@RequiredArgsConstructor |
|||
public class LnshMaterialDistributionDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor { |
|||
protected ItemProtocol itemProtocol=new ItemProtocol(this); |
|||
|
|||
InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); |
|||
|
|||
DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); |
|||
|
|||
RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); |
|||
|
|||
TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); |
|||
|
|||
DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); |
|||
|
|||
AcsToWmsService acsToWmsService = SpringContextHolder.getBean("acsToWmsServiceImpl"); |
|||
|
|||
ProduceshiftorderService produceshiftorderService = SpringContextHolder.getBean("produceshiftorderServiceImpl"); |
|||
|
|||
LuceneExecuteLogService lucene = SpringContextHolder.getBean("luceneExecuteLogServiceImpl"); |
|||
|
|||
DeviceAppService deviceAppService = SpringContextHolder.getBean("deviceAppServiceImpl"); |
|||
//放货准备锁
|
|||
String putReadyLock = null; |
|||
//有货标记
|
|||
protected boolean has_goods_tag = false; |
|||
|
|||
int mode = 0; |
|||
int error = 0; |
|||
int last_mode = 0; |
|||
int last_error = 0; |
|||
Boolean isonline = true; |
|||
int hasGoods = 0; |
|||
String message = null; |
|||
Boolean iserror = false; |
|||
|
|||
private Date instruction_require_time = new Date(); |
|||
private Date instruction_finished_time = new Date(); |
|||
|
|||
private int instruction_require_time_out = 3000; |
|||
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; |
|||
int status = 0; |
|||
int last_status = 0; |
|||
String slip=null; |
|||
String last_slip=null; |
|||
String open_time = null; |
|||
String last_open_time = null; |
|||
|
|||
int standby_time = 0; |
|||
int last_standby_time = 0; |
|||
int production_time = 0; |
|||
int last_production_time = 0; |
|||
int error_time = 0; |
|||
int last_error_time = 0; |
|||
float set_weight=0f; |
|||
float weight=0f; |
|||
float last_set_weight=0f; |
|||
float last_weight=0f; |
|||
|
|||
@Override |
|||
public Device getDevice() { |
|||
return this.device; |
|||
} |
|||
|
|||
|
|||
@Override |
|||
public void execute() { |
|||
String message = null; |
|||
try { |
|||
device_code = this.getDeviceCode(); |
|||
mode = this.itemProtocol.getMode(); |
|||
error = this.itemProtocol.getError(); |
|||
status = this.itemProtocol.getStatus(); |
|||
open_time = this.itemProtocol.getOpen_time(); |
|||
standby_time = this.itemProtocol.getStandby_time(); |
|||
production_time = this.itemProtocol.getProduction_time(); |
|||
error_time = this.itemProtocol.getError_time(); |
|||
slip=this.itemProtocol.getSlip(); |
|||
set_weight=this.itemProtocol.getSetWeight(); |
|||
weight = this.itemProtocol.getWeight(); |
|||
|
|||
if (mode != last_mode) { |
|||
this.setRequireSucess(false); |
|||
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 (!open_time.equals(last_open_time)) { |
|||
logServer.deviceItemValue(this.device_code, "open_time", String.valueOf(open_time)); |
|||
logServer.deviceExecuteLog(this.device_code, "", "", "信号open_time:" + last_open_time + " -> " + open_time); |
|||
} |
|||
if (standby_time != last_standby_time) { |
|||
logServer.deviceItemValue(this.device_code, "standby_time", String.valueOf(standby_time)); |
|||
logServer.deviceExecuteLog(this.device_code, "", "", "信号standby_time:" + last_standby_time + " -> " + standby_time); |
|||
} |
|||
if (production_time != last_production_time) { |
|||
logServer.deviceItemValue(this.device_code, "production_time", String.valueOf(production_time)); |
|||
logServer.deviceExecuteLog(this.device_code, "", "", "信号production_time:" + last_production_time + " -> " + production_time); |
|||
} |
|||
if (error_time != last_error_time) { |
|||
logServer.deviceItemValue(this.device_code, "error_time", String.valueOf(error_time)); |
|||
logServer.deviceExecuteLog(this.device_code, "", "", "信号error_time:" + last_error_time + " -> " + error_time); |
|||
} |
|||
if (weight != last_weight) { |
|||
logServer.deviceItemValue(this.device_code, "weight", String.valueOf(weight)); |
|||
logServer.deviceExecuteLog(this.device_code, "", "", "信号weight:" + last_weight + " -> " + weight); |
|||
} |
|||
if (set_weight != last_set_weight) { |
|||
logServer.deviceItemValue(this.device_code, "set_weight", String.valueOf(set_weight)); |
|||
logServer.deviceExecuteLog(this.device_code, "", "", "信号set_weight:" + last_set_weight + " -> " + set_weight); |
|||
} |
|||
|
|||
if (slip != last_slip) { |
|||
logServer.deviceItemValue(this.device_code, "slip", String.valueOf(slip)); |
|||
logServer.deviceExecuteLog(this.device_code, "", "", "信号slip:" + last_slip + " -> " + slip); |
|||
} |
|||
|
|||
} catch (Exception var17) { |
|||
log.info(var17.getMessage()); |
|||
message = "错误:" + var17.getMessage(); |
|||
return; |
|||
} |
|||
|
|||
//未联机
|
|||
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; |
|||
|
|||
|
|||
if (mode > 2 && !requireSucess) { |
|||
if (ObjectUtil.isNotEmpty(this.device.getExtraValue().get(String.valueOf(mode)))) { |
|||
String modethod = this.device.getExtraValue().get(String.valueOf(mode)).toString(); |
|||
try { |
|||
applyRequest(modethod); |
|||
} catch (Exception e) { |
|||
message = "错误:" + e.getMessage(); |
|||
this.setIserror(true); |
|||
} |
|||
} else { |
|||
message = "无效模式请求,驱动未配置此请求方法"; |
|||
} |
|||
} else { |
|||
message = "无请求"; |
|||
} |
|||
|
|||
} |
|||
last_mode = mode; |
|||
last_status = status; |
|||
last_error = error; |
|||
last_open_time = open_time; |
|||
last_standby_time = standby_time; |
|||
last_production_time = production_time; |
|||
last_error_time = error_time; |
|||
last_weight = weight; |
|||
last_set_weight=set_weight; |
|||
last_slip=slip; |
|||
} |
|||
|
|||
|
|||
public boolean exe_error() { |
|||
if (this.error == 0) { |
|||
return true; |
|||
} else { |
|||
log.debug("设备报警"); |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 请求 |
|||
* |
|||
* @param |
|||
*/ |
|||
public synchronized boolean applyRequest(String modethod) throws Exception { |
|||
Object obj1 = this; |
|||
Date date = new Date(); |
|||
if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { |
|||
log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); |
|||
return false; |
|||
} else { |
|||
this.instruction_require_time = date; |
|||
Object obj = this.getClass().getDeclaredConstructor().newInstance(); |
|||
Method method1 = this.getClass().getMethod(modethod, null); |
|||
method1.invoke(this, null); |
|||
return true; |
|||
} |
|||
} |
|||
/** |
|||
* 布料机反馈重量和泥料 |
|||
* @return |
|||
*/ |
|||
public boolean apply_one_cloth() { |
|||
ClothRequest request = new ClothRequest(); |
|||
request.setDevice_code(this.getDevice_code()); |
|||
request.setRequest_medthod_code(Thread.currentThread().getStackTrace()[1].getMethodName()); |
|||
request.setRequest_medthod_name(RequestMethodEnum.getName(Thread.currentThread().getStackTrace()[1].getMethodName())); |
|||
List<String> LinkDeviceCodeList = this.getExtraDeviceCodes1("link_device_code"); |
|||
LnshMaterialDistributionDeviceDriver lnshMaterialDistributionDeviceDriver; |
|||
for (int i = 0; i < LinkDeviceCodeList.size(); i++) { |
|||
Device getDevice = deviceAppService.findDeviceByCode(LinkDeviceCodeList.get(i).toString()); |
|||
if(ObjectUtil.isEmpty(getDevice)){ |
|||
continue; |
|||
} |
|||
ConveyorPressStationDeviceDriver conveyorPressStationDeviceDriver; |
|||
if(getDevice.getDeviceDriver() instanceof ConveyorPressStationDeviceDriver){ |
|||
conveyorPressStationDeviceDriver=(ConveyorPressStationDeviceDriver) getDevice.getDeviceDriver(); |
|||
request.setSlip(conveyorPressStationDeviceDriver.getTo_mix_num()); |
|||
} |
|||
} |
|||
request.setSet_weight(set_weight); |
|||
request.setWeight(weight); |
|||
message = RequestMethodEnum.getName("apply_one_cloth") + "apply_one_cloth 接口请求LMS..."; |
|||
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request))); |
|||
logServer.deviceExecuteLog(this.device_code, "", "", "参数:" + JSON.toJSONString(request)); |
|||
ApplyTaskResponse resp = JSON.toJavaObject(JSONObject.parseObject(acsToWmsService.applyTask(request)),ApplyTaskResponse.class); |
|||
if (resp.getCode() == 200) { |
|||
this.writing(200); |
|||
this.setRequireSucess(true); |
|||
message = RequestMethodEnum.getName("apply_one_cloth") + "apply_one_cloth 接口请求成功" + resp.getMessage(); |
|||
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "返回参数:" + JSON.toJSONString(resp))); |
|||
} else { |
|||
this.writing(400); |
|||
message = RequestMethodEnum.getName("apply_one_cloth") + "apply_one_cloth 接口请求失败" + resp.getMessage(); |
|||
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "返回参数:" + JSON.toJSONString(resp))); |
|||
} |
|||
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message)); |
|||
return true; |
|||
|
|||
} |
|||
|
|||
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 to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|||
+ "." + ItemProtocol.item_to_command; |
|||
if (appendMessage == null) { |
|||
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); |
|||
server.disconnect(); |
|||
|
|||
} |
|||
|
|||
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); |
|||
server.disconnect(); |
|||
logServer.deviceExecuteLog(this.device_code, "", "", param + " 写入 " + value); |
|||
} |
|||
/** |
|||
* 多个信号一起下发电气 |
|||
* |
|||
* @param map |
|||
*/ |
|||
|
|||
public void writing(Map<String, Object> map) { |
|||
LuceneExecuteLogService lucene = SpringContextHolder.getBean(LuceneExecuteLogService.class); |
|||
DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); |
|||
Map<String, Object> itemMap = new LinkedHashMap<>(); |
|||
map.forEach((key, value) -> { |
|||
if (ObjectUtil.isNotEmpty(value)) { |
|||
itemMap.put(getToParam() + key, value); |
|||
} |
|||
}); |
|||
if (ObjectUtil.isNotEmpty(itemMap)) { |
|||
try { |
|||
this.checkcontrol(itemMap); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
try{ |
|||
this.checkcontrol(itemMap); |
|||
} catch (Exception e1){ |
|||
e1.printStackTrace(); |
|||
} |
|||
} |
|||
logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); |
|||
lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap)); |
|||
} |
|||
} |
|||
/** |
|||
* 抽取统一下发电气信号前缀 |
|||
* |
|||
* @return |
|||
*/ |
|||
public String getToParam() { |
|||
return this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "."; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
public void executing(Server server, Map<String, Object> itemMap) { |
|||
ReadUtil.write(itemMap, server); |
|||
server.disconnect(); |
|||
} |
|||
|
|||
|
|||
public void writing(int command) { |
|||
String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|||
+ "." + ItemProtocol.item_to_command; |
|||
|
|||
String opcservcerid = this.getDevice().getOpc_server_id(); |
|||
Server server = ReadUtil.getServer(opcservcerid); |
|||
Map<String, Object> itemMap = new HashMap<String, Object>(); |
|||
itemMap.put(to_command, command); |
|||
ReadUtil.write(itemMap, server); |
|||
ReadUtil.write(itemMap, server); |
|||
server.disconnect(); |
|||
logServer.deviceExecuteLog(this.device_code, "", "", "to_command 写入 " + command); |
|||
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, "to_command 写入 " + command)); |
|||
} |
|||
|
|||
public static Boolean isExistFieldName(String fieldName, Object obj) throws NoSuchFieldException { |
|||
if (obj == null || StrUtil.isBlank(fieldName)) { |
|||
return null; |
|||
} |
|||
//获取这个类的所有属性
|
|||
Field[] fields = obj.getClass().getDeclaredFields(); |
|||
boolean flag = false; |
|||
//循环遍历所有的fields
|
|||
for (int i = 0; i < fields.length; i++) { |
|||
if (fields[i].getName().equals("item_" + fieldName)) { |
|||
flag = true; |
|||
break; |
|||
} |
|||
} |
|||
return flag; |
|||
} |
|||
|
|||
@Override |
|||
public JSONObject getDeviceStatusName() throws Exception { |
|||
String status; |
|||
switch (this.status) { |
|||
case 1: |
|||
status = "待机"; |
|||
break; |
|||
case 2: |
|||
status = "生产中"; |
|||
break; |
|||
case 3: |
|||
status = "故障"; |
|||
break; |
|||
default: |
|||
status = String.valueOf(this.status); |
|||
} |
|||
|
|||
String error; |
|||
switch (this.error) { |
|||
case 1: |
|||
error = "急停中"; |
|||
break; |
|||
case 2: |
|||
error = "光幕报警"; |
|||
break; |
|||
case 3: |
|||
error = "本体报警"; |
|||
break; |
|||
case 4: |
|||
error = "未排产报警"; |
|||
break; |
|||
case 5: |
|||
error = "扫码故障"; |
|||
break; |
|||
default: |
|||
error = String.valueOf(this.error); |
|||
} |
|||
|
|||
JSONObject jo = new JSONObject(); |
|||
jo.put("device_name", this.getDevice().getDevice_name()); |
|||
jo.put("mode", mode); |
|||
Object requestNo = this.getExtraValue().get(String.valueOf(this.mode)); |
|||
if(ObjectUtil.isNotEmpty(requestNo)){ |
|||
jo.put("modeName", this.getModeName(String.valueOf(requestNo))); |
|||
} else { |
|||
jo.put("modeName", "无效的请求,驱动中未配置"); |
|||
} |
|||
jo.put("status", status); |
|||
jo.put("error", error); |
|||
jo.put("open_time", open_time); |
|||
jo.put("standby_time", standby_time); |
|||
jo.put("production_time", production_time); |
|||
jo.put("error_time", error_time); |
|||
jo.put("weight", weight); |
|||
jo.put("isError", iserror); |
|||
jo.put("isOnline", isonline); |
|||
jo.put("message", message); |
|||
return jo; |
|||
} |
|||
|
|||
@Override |
|||
public void setDeviceStatus(JSONObject data) { |
|||
|
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,26 @@ |
|||
package org.nl.acs.ext.wms.data.AcsToWmsData.cloth; |
|||
|
|||
import lombok.Data; |
|||
import org.nl.acs.ext.wms.data.AcsToWmsData.applyTask.ApplyDeviceDto; |
|||
import org.nl.acs.ext.wms.data.BaseRequest; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Data |
|||
public class ClothRequest extends BaseRequest { |
|||
/** |
|||
* 泥料批次 |
|||
*/ |
|||
private String slip; |
|||
|
|||
/** |
|||
* 设定重量 |
|||
*/ |
|||
private Float set_weight; |
|||
|
|||
/** |
|||
* 称量重量 |
|||
*/ |
|||
private Float weight; |
|||
|
|||
} |
@ -0,0 +1,7 @@ |
|||
package org.nl.acs.ext.wms.data.AcsToWmsData.cloth; |
|||
|
|||
import org.nl.acs.ext.wms.data.BaseResponse; |
|||
|
|||
public class ClothResponse extends BaseResponse { |
|||
|
|||
} |
Loading…
Reference in new issue