|
|
@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil; |
|
|
|
import io.swagger.models.auth.In; |
|
|
|
import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; |
|
|
|
import org.nl.acs.device_driver.standard_conveyor_line.ItemProtocol; |
|
|
|
import org.nl.acs.device_driver.standard_conveyor_line.StandardConveyorLineDeviceDriver; |
|
|
|
import org.nl.acs.opc.OpcConfig; |
|
|
|
import org.nl.modules.udw.UnifiedDataAccessor; |
|
|
|
import org.nl.modules.udw.UnifiedDataAccessorFactory; |
|
|
@ -28,7 +29,7 @@ public class AbstractOpcDeviceDriver<T> extends AbstractDeviceDriver implements |
|
|
|
} |
|
|
|
|
|
|
|
//信号值与上次值不一致时的日志
|
|
|
|
public void writeLogInfo(String device_code,String name, int lastNumber, int nowNumber) { |
|
|
|
public void writeLogInfo(String device_code, String name, int lastNumber, int nowNumber) { |
|
|
|
if (lastNumber != nowNumber) { |
|
|
|
this.execute_log.setResource(device_code, this.device.getDevice_name()); |
|
|
|
this.execute_log.log("设备:" + device_code + ",last_'" + name + "' -> '" + name + "':" + lastNumber + "->" + nowNumber); |
|
|
@ -36,7 +37,7 @@ public class AbstractOpcDeviceDriver<T> extends AbstractDeviceDriver implements |
|
|
|
} |
|
|
|
|
|
|
|
//判断信号是否异常
|
|
|
|
public synchronized void signalIsException(T sonDriver){ |
|
|
|
public synchronized void signalIsException(T sonDriver) { |
|
|
|
Class<?> sonDriverClass = sonDriver.getClass(); |
|
|
|
try { |
|
|
|
Method methodItemProtocol = sonDriverClass.getMethod("getItemProtocol"); |
|
|
@ -48,31 +49,31 @@ public class AbstractOpcDeviceDriver<T> extends AbstractDeviceDriver implements |
|
|
|
for (Field field : fields) { |
|
|
|
//获取属性名字
|
|
|
|
String fieldName = field.getName(); |
|
|
|
if (fieldName.contains("item_")){ |
|
|
|
if (!fieldName.contains("to_")){ |
|
|
|
if (fieldName.contains("item_")) { |
|
|
|
if (!fieldName.contains("to_")) { |
|
|
|
String fieldValue = (String) field.get(fieldName); |
|
|
|
Method methodGet = null; |
|
|
|
try { |
|
|
|
methodGet = itemProtocol.getClass().getMethod("get" + initialUpperCase(fieldValue)); |
|
|
|
}catch (Exception e){ |
|
|
|
} catch (Exception e) { |
|
|
|
} |
|
|
|
Integer itemValue = 0; |
|
|
|
if (ObjectUtil.isNotEmpty(methodGet)){ |
|
|
|
if (ObjectUtil.isNotEmpty(methodGet)) { |
|
|
|
itemValue = (Integer) methodGet.invoke(itemProtocol); |
|
|
|
} |
|
|
|
if (!fieldValue.equals("heartbeat")){ |
|
|
|
Method methodSet =null; |
|
|
|
if (!fieldValue.equals("heartbeat")) { |
|
|
|
Method methodSet = null; |
|
|
|
try { |
|
|
|
methodSet = sonDriverClass.getMethod("set" + initialUpperCase(fieldValue), int.class); |
|
|
|
} catch (Exception e){ |
|
|
|
} catch (Exception e) { |
|
|
|
} |
|
|
|
if (ObjectUtil.isNotEmpty(methodSet)){ |
|
|
|
if (ObjectUtil.isNotEmpty(methodSet)) { |
|
|
|
try { |
|
|
|
methodSet.invoke(sonDriver,itemValue); |
|
|
|
methodSet.invoke(sonDriver, itemValue); |
|
|
|
Integer last_Number = (Integer) sonDriverClass.getMethod("getLast_" + fieldValue).invoke(sonDriver); |
|
|
|
Method writeLogInfo = sonDriverClass.getMethod("writeLogInfo", String.class, String.class, int.class, int.class); |
|
|
|
writeLogInfo.invoke(sonDriver,deviceCode,fieldValue,last_Number,itemValue); |
|
|
|
}catch (Exception e){ |
|
|
|
writeLogInfo.invoke(sonDriver, deviceCode, fieldValue, last_Number, itemValue); |
|
|
|
} catch (Exception e) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -80,41 +81,41 @@ public class AbstractOpcDeviceDriver<T> extends AbstractDeviceDriver implements |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Method methodIsonline = sonDriverClass.getMethod("setIsonline",Boolean.class); |
|
|
|
Method methodIserror = sonDriverClass.getMethod("setIserror",Boolean.class); |
|
|
|
Method methodMessage = sonDriverClass.getMethod("setMessage",String.class); |
|
|
|
Method methodIsonline = sonDriverClass.getMethod("setIsonline", Boolean.class); |
|
|
|
Method methodIserror = sonDriverClass.getMethod("setIserror", Boolean.class); |
|
|
|
Method methodMessage = sonDriverClass.getMethod("setMessage", String.class); |
|
|
|
Method methodMode = sonDriverClass.getMethod("getMode"); |
|
|
|
Method methodError = sonDriverClass.getMethod("getError"); |
|
|
|
Integer mode = (Integer) methodMode.invoke(sonDriver); |
|
|
|
Integer error = (Integer) methodError.invoke(sonDriver); |
|
|
|
Boolean isonline = (Boolean) itemProtocol.getClass().getMethod("getIsonline").invoke(itemProtocol); |
|
|
|
|
|
|
|
if (!isonline){ |
|
|
|
methodIsonline.invoke(sonDriver,false); |
|
|
|
methodIserror.invoke(sonDriver,true); |
|
|
|
methodMessage.invoke(sonDriver,"信号量同步异常"); |
|
|
|
}else if (mode == 0){ |
|
|
|
methodIsonline.invoke(sonDriver,false); |
|
|
|
methodIserror.invoke(sonDriver,true); |
|
|
|
methodMessage.invoke(sonDriver,"未联机"); |
|
|
|
}else if (error != 0){ |
|
|
|
methodIsonline.invoke(sonDriver,false); |
|
|
|
methodIserror.invoke(sonDriver,true); |
|
|
|
methodMessage.invoke(sonDriver,"有报警"); |
|
|
|
if (!isonline) { |
|
|
|
methodIsonline.invoke(sonDriver, false); |
|
|
|
methodIserror.invoke(sonDriver, true); |
|
|
|
methodMessage.invoke(sonDriver, "信号量同步异常"); |
|
|
|
} else if (mode == 0) { |
|
|
|
methodIsonline.invoke(sonDriver, false); |
|
|
|
methodIserror.invoke(sonDriver, true); |
|
|
|
methodMessage.invoke(sonDriver, "未联机"); |
|
|
|
} else if (error != 0) { |
|
|
|
methodIsonline.invoke(sonDriver, false); |
|
|
|
methodIserror.invoke(sonDriver, true); |
|
|
|
methodMessage.invoke(sonDriver, "有报警"); |
|
|
|
} else { |
|
|
|
methodIsonline.invoke(sonDriver,true); |
|
|
|
methodIserror.invoke(sonDriver,false); |
|
|
|
methodIsonline.invoke(sonDriver, true); |
|
|
|
methodIserror.invoke(sonDriver, false); |
|
|
|
//判断是否符合生成任务的条件
|
|
|
|
Method methodIsSatisfyCreateTask = sonDriverClass.getMethod("isSatisfyCreateTask"); |
|
|
|
String methodName = (String) methodIsSatisfyCreateTask.invoke(sonDriver); |
|
|
|
if (StrUtil.isNotEmpty(methodName)){ |
|
|
|
if (StrUtil.isNotEmpty(methodName)) { |
|
|
|
Method methodTask = null; |
|
|
|
try { |
|
|
|
methodTask = sonDriverClass.getMethod(methodName); |
|
|
|
}catch (Exception e){ |
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
} |
|
|
|
if (ObjectUtil.isNotEmpty(methodTask)){ |
|
|
|
if (ObjectUtil.isNotEmpty(methodTask)) { |
|
|
|
methodTask.invoke(sonDriver); |
|
|
|
} |
|
|
|
//sonDriverClass.getMethod(methodName).invoke(sonDriver);
|
|
|
@ -125,12 +126,12 @@ public class AbstractOpcDeviceDriver<T> extends AbstractDeviceDriver implements |
|
|
|
for (Field declaredField : declaredFields) { |
|
|
|
String fieldName = declaredField.getName(); |
|
|
|
Class<?> fieldType = declaredField.getType(); |
|
|
|
if (fieldType == int.class || fieldType == Integer.class){ |
|
|
|
if (fieldName.contains("last_")){ |
|
|
|
if (fieldType == int.class || fieldType == Integer.class) { |
|
|
|
if (fieldName.contains("last_")) { |
|
|
|
Method method = null; |
|
|
|
try { |
|
|
|
method = sonDriverClass.getMethod("set" + initialUpperCase(fieldName),int.class); |
|
|
|
}catch(Exception e){ |
|
|
|
method = sonDriverClass.getMethod("set" + initialUpperCase(fieldName), int.class); |
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
} |
|
|
|
int index = fieldName.indexOf("last_"); |
|
|
@ -138,15 +139,15 @@ public class AbstractOpcDeviceDriver<T> extends AbstractDeviceDriver implements |
|
|
|
Method methodSub = null; |
|
|
|
try { |
|
|
|
methodSub = sonDriverClass.getMethod("get" + initialUpperCase(subName)); |
|
|
|
}catch(Exception e){ |
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
} |
|
|
|
int nowItemValue = 0; |
|
|
|
if (ObjectUtil.isNotEmpty(methodSub)){ |
|
|
|
if (ObjectUtil.isNotEmpty(methodSub)) { |
|
|
|
nowItemValue = (int) methodSub.invoke(sonDriver); |
|
|
|
} |
|
|
|
if (ObjectUtil.isNotEmpty(method)){ |
|
|
|
method.invoke(sonDriver,nowItemValue); |
|
|
|
if (ObjectUtil.isNotEmpty(method)) { |
|
|
|
method.invoke(sonDriver, nowItemValue); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -156,46 +157,8 @@ public class AbstractOpcDeviceDriver<T> extends AbstractDeviceDriver implements |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void commonCreateTask(T driver){ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//首字母转大写
|
|
|
|
public String initialUpperCase(String str){ |
|
|
|
return str.substring(0,1).toUpperCase() + str.substring(1,str.length()); |
|
|
|
} |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public void writing(int type, int command) { |
|
|
|
String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|
|
|
+ "." + ItemProtocol.item_to_command; |
|
|
|
String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|
|
|
+ "." + ItemProtocol.item_to_target; |
|
|
|
String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|
|
|
+ "." + ItemProtocol.item_to_task; |
|
|
|
String opcservcerid = this.getDevice().getOpc_server_id(); |
|
|
|
Server server = ReadUtil.getServer(opcservcerid); |
|
|
|
Map<String, Object> itemMap = new HashMap<String, Object>(); |
|
|
|
if (type == 1) { |
|
|
|
itemMap.put(to_command, command); |
|
|
|
} else if (type == 2) { |
|
|
|
itemMap.put(to_target, command); |
|
|
|
|
|
|
|
} else if (type == 3) { |
|
|
|
itemMap.put(to_task, command); |
|
|
|
} |
|
|
|
ReadUtil.write(itemMap, server); |
|
|
|
|
|
|
|
public String initialUpperCase(String str) { |
|
|
|
return str.substring(0, 1).toUpperCase() + str.substring(1, str.length()); |
|
|
|
} |
|
|
|
} |
|
|
|