|
|
@ -66,164 +66,169 @@ public class LedScreenDeviceDriver extends AbstractDeviceDriver implements Devic |
|
|
|
|
|
|
|
@Override |
|
|
|
public void execute() throws Exception { |
|
|
|
if (isInitialized.compareAndSet(false, true)) { |
|
|
|
Bx6GEnv.initial(30000); |
|
|
|
} |
|
|
|
//建立连接
|
|
|
|
if (this.screen == null) { |
|
|
|
String ip = Optional.ofNullable(this.getDevice().getExtraValue().get("ip_address")).map(Object::toString).orElse(null); |
|
|
|
int port = Optional.ofNullable(this.getDevice().getExtraValue().get("ip_port")).map(Object::toString).map(Integer::parseInt).orElse(0); |
|
|
|
if (ip == null || port == 0) { |
|
|
|
return; |
|
|
|
try { |
|
|
|
if (isInitialized.compareAndSet(false, true)) { |
|
|
|
Bx6GEnv.initial(30000); |
|
|
|
} |
|
|
|
this.screen = new Bx6GScreenClient(this.getDevice().getDevice_code(), new Bx6E()); |
|
|
|
this.screen.connect(ip, port); |
|
|
|
} |
|
|
|
|
|
|
|
//设置节目
|
|
|
|
DisplayStyle[] styles = DisplayStyleFactory.getStyles().toArray(new DisplayStyle[0]); |
|
|
|
ProgramBxFile pf = new ProgramBxFile(0, this.screen.getProfile()); |
|
|
|
TextCaptionBxArea area = new TextCaptionBxArea(0, 0, 192, 16, this.screen.getProfile()); |
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
//判断是否关联出入库模式
|
|
|
|
boolean inOutFlag = Optional.ofNullable(this.getDevice().getExtraValue().get("inOut")).map(Object::toString).map(Boolean::parseBoolean).orElse(false); |
|
|
|
if (!inOutFlag) { |
|
|
|
String inOutMode = Optional.ofNullable(this.getDevice().getExtraValue().get("inOutMode")).map(Object::toString).orElse(""); |
|
|
|
sb.append(inOutMode); |
|
|
|
} else { |
|
|
|
String linkSSX = Optional.ofNullable(this.getDevice().getExtraValue().get("linkSSX")).map(Object::toString).orElse(null); |
|
|
|
Device device = deviceAppService.findDeviceByCode(linkSSX); |
|
|
|
if (device != null && device.getDeviceDriver() instanceof StripConveyorDeviceDriver) { |
|
|
|
StripConveyorDeviceDriver stripConveyorDeviceDriver = (StripConveyorDeviceDriver) device.getDeviceDriver(); |
|
|
|
if (stripConveyorDeviceDriver.getInOutMode() == 0) { |
|
|
|
sb.append("入库模式"); |
|
|
|
} else { |
|
|
|
sb.append("出库模式"); |
|
|
|
//建立连接
|
|
|
|
if (this.screen == null || !this.screen.isConnected()) { |
|
|
|
String ip = Optional.ofNullable(this.getDevice().getExtraValue().get("ip_address")).map(Object::toString).orElse(null); |
|
|
|
int port = Optional.ofNullable(this.getDevice().getExtraValue().get("ip_port")).map(Object::toString).map(Integer::parseInt).orElse(0); |
|
|
|
if (ip == null || port == 0) { |
|
|
|
return; |
|
|
|
} |
|
|
|
this.screen = new Bx6GScreenClient(this.getDevice().getDevice_code(), new Bx6E()); |
|
|
|
this.screen.connect(ip, port); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!StrUtil.equals(this.modeMsgInfo, sb.toString())) { |
|
|
|
TextBxPage page = new TextBxPage(sb.toString()); |
|
|
|
page.setForeground(Color.green); |
|
|
|
area.addPage(page); |
|
|
|
pf.addArea(area); |
|
|
|
this.screen.writeProgram(pf); |
|
|
|
this.modeMsgInfo = sb.toString(); |
|
|
|
} |
|
|
|
|
|
|
|
//设置动态区1报警信息
|
|
|
|
List<String> errorDevices = this.getExtraDeviceCodes("errorDevices"); |
|
|
|
StringBuilder sbMsg = new StringBuilder(); |
|
|
|
if (CollectionUtil.isNotEmpty(errorDevices)) { |
|
|
|
sbMsg.append("报警信息: "); |
|
|
|
String errorMsg = ""; |
|
|
|
for (int i = 0; i < errorDevices.size(); i++) { |
|
|
|
String deviceCode = errorDevices.get(i); |
|
|
|
Device device = deviceAppService.findDeviceByCode(deviceCode); |
|
|
|
if (device != null && device.getDeviceDriver() instanceof AppearanceInspectionScannerConveyorDeviceDriver) { |
|
|
|
AppearanceInspectionScannerConveyorDeviceDriver appearanceInspectionScannerConveyorDeviceDriver = (AppearanceInspectionScannerConveyorDeviceDriver) device.getDeviceDriver(); |
|
|
|
if (appearanceInspectionScannerConveyorDeviceDriver.getError() > 0) { |
|
|
|
String label = ErrorEnum.getLabel(appearanceInspectionScannerConveyorDeviceDriver.getError()); |
|
|
|
errorMsg = "设备" + deviceCode + " " + label + ","; |
|
|
|
//设置节目
|
|
|
|
DisplayStyle[] styles = DisplayStyleFactory.getStyles().toArray(new DisplayStyle[0]); |
|
|
|
ProgramBxFile pf = new ProgramBxFile(0, this.screen.getProfile()); |
|
|
|
TextCaptionBxArea area = new TextCaptionBxArea(0, 0, 192, 16, this.screen.getProfile()); |
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
//判断是否关联出入库模式
|
|
|
|
boolean inOutFlag = Optional.ofNullable(this.getDevice().getExtraValue().get("inOut")).map(Object::toString).map(Boolean::parseBoolean).orElse(false); |
|
|
|
if (!inOutFlag) { |
|
|
|
String inOutMode = Optional.ofNullable(this.getDevice().getExtraValue().get("inOutMode")).map(Object::toString).orElse(""); |
|
|
|
sb.append(inOutMode); |
|
|
|
} else { |
|
|
|
String linkSSX = Optional.ofNullable(this.getDevice().getExtraValue().get("linkSSX")).map(Object::toString).orElse(null); |
|
|
|
Device device = deviceAppService.findDeviceByCode(linkSSX); |
|
|
|
if (device != null && device.getDeviceDriver() instanceof StripConveyorDeviceDriver) { |
|
|
|
StripConveyorDeviceDriver stripConveyorDeviceDriver = (StripConveyorDeviceDriver) device.getDeviceDriver(); |
|
|
|
if (stripConveyorDeviceDriver.getInOutMode() == 0) { |
|
|
|
sb.append("入库模式"); |
|
|
|
} else { |
|
|
|
sb.append("出库模式"); |
|
|
|
} |
|
|
|
} else if (device != null && device.getDeviceDriver() instanceof StandardStackerDeviceDriver) { |
|
|
|
StandardStackerDeviceDriver standardStackerDeviceDriver = (StandardStackerDeviceDriver) device.getDeviceDriver(); |
|
|
|
if (standardStackerDeviceDriver.getFront_Zerror() > 0 || standardStackerDeviceDriver.getBack_Zerror() > 0) { |
|
|
|
errorMsg = deviceCode + " "; |
|
|
|
if (standardStackerDeviceDriver.getFront_Zerror() > 0) { |
|
|
|
errorMsg = "设备" + deviceCode + " 前叉报警 " + org.nl.acs.device.driver.stacker.double_stacker.enums.ErrorEnum.getDesc(standardStackerDeviceDriver.getFront_Zerror()) + ","; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!StrUtil.equals(this.modeMsgInfo, sb.toString())) { |
|
|
|
TextBxPage page = new TextBxPage(sb.toString()); |
|
|
|
page.setForeground(Color.green); |
|
|
|
area.addPage(page); |
|
|
|
pf.addArea(area); |
|
|
|
this.screen.writeProgram(pf); |
|
|
|
this.modeMsgInfo = sb.toString(); |
|
|
|
} |
|
|
|
//设置动态区1报警信息
|
|
|
|
List<String> errorDevices = this.getExtraDeviceCodes("errorDevices"); |
|
|
|
StringBuilder sbMsg = new StringBuilder(); |
|
|
|
if (CollectionUtil.isNotEmpty(errorDevices)) { |
|
|
|
sbMsg.append("报警信息: "); |
|
|
|
String errorMsg = ""; |
|
|
|
for (int i = 0; i < errorDevices.size(); i++) { |
|
|
|
String deviceCode = errorDevices.get(i); |
|
|
|
Device device = deviceAppService.findDeviceByCode(deviceCode); |
|
|
|
if (device != null && device.getDeviceDriver() instanceof AppearanceInspectionScannerConveyorDeviceDriver) { |
|
|
|
AppearanceInspectionScannerConveyorDeviceDriver appearanceInspectionScannerConveyorDeviceDriver = (AppearanceInspectionScannerConveyorDeviceDriver) device.getDeviceDriver(); |
|
|
|
if (appearanceInspectionScannerConveyorDeviceDriver.getError() > 0) { |
|
|
|
String label = ErrorEnum.getLabel(appearanceInspectionScannerConveyorDeviceDriver.getError()); |
|
|
|
errorMsg = "设备" + deviceCode + " " + label + ","; |
|
|
|
} |
|
|
|
if (standardStackerDeviceDriver.getBack_Zerror() > 0) { |
|
|
|
errorMsg = "设备" + deviceCode + " 后叉报警 " + org.nl.acs.device.driver.stacker.double_stacker.enums.ErrorEnum.getDesc(standardStackerDeviceDriver.getFront_Zerror()) + ","; |
|
|
|
} else if (device != null && device.getDeviceDriver() instanceof StandardStackerDeviceDriver) { |
|
|
|
StandardStackerDeviceDriver standardStackerDeviceDriver = (StandardStackerDeviceDriver) device.getDeviceDriver(); |
|
|
|
if (standardStackerDeviceDriver.getFront_Zerror() > 0 || standardStackerDeviceDriver.getBack_Zerror() > 0) { |
|
|
|
errorMsg = deviceCode + " "; |
|
|
|
if (standardStackerDeviceDriver.getFront_Zerror() > 0) { |
|
|
|
errorMsg = "设备" + deviceCode + " 前叉报警 " + org.nl.acs.device.driver.stacker.double_stacker.enums.ErrorEnum.getDesc(standardStackerDeviceDriver.getFront_Zerror()) + ","; |
|
|
|
} |
|
|
|
if (standardStackerDeviceDriver.getBack_Zerror() > 0) { |
|
|
|
errorMsg = "设备" + deviceCode + " 后叉报警 " + org.nl.acs.device.driver.stacker.double_stacker.enums.ErrorEnum.getDesc(standardStackerDeviceDriver.getFront_Zerror()) + ","; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (StrUtil.isEmpty(errorMsg)) { |
|
|
|
sbMsg.append("无报警!"); |
|
|
|
} else { |
|
|
|
sbMsg.append(errorMsg); |
|
|
|
if (sbMsg.length() > 0 && sbMsg.charAt(sbMsg.length() - 1) == ',') { |
|
|
|
sbMsg.deleteCharAt(sbMsg.length() - 1); |
|
|
|
if (StrUtil.isEmpty(errorMsg)) { |
|
|
|
sbMsg.append("无报警!"); |
|
|
|
} else { |
|
|
|
sbMsg.append(errorMsg); |
|
|
|
if (sbMsg.length() > 0 && sbMsg.charAt(sbMsg.length() - 1) == ',') { |
|
|
|
sbMsg.deleteCharAt(sbMsg.length() - 1); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (!StrUtil.equals(this.errorMsgInfo, sbMsg.toString())) { |
|
|
|
DynamicBxAreaRule rule_2 = new DynamicBxAreaRule(); |
|
|
|
rule_2.setId(0); |
|
|
|
rule_2.setRunMode((byte) 0); |
|
|
|
rule_2.setRelativeAllPrograms(false); |
|
|
|
rule_2.addRelativeProgram(0); |
|
|
|
DynamicBxArea area_2 = new DynamicBxArea(0, 22, 192, 22, screen.getProfile()); |
|
|
|
TextBxPage page_2 = new TextBxPage(sbMsg.toString()); |
|
|
|
boolean flag = getStringWidth(sbMsg.toString()); |
|
|
|
if (flag) { |
|
|
|
page_2.setDisplayStyle(styles[1]); |
|
|
|
} else { |
|
|
|
page_2.setDisplayStyle(styles[4]); |
|
|
|
if (!StrUtil.equals(this.errorMsgInfo, sbMsg.toString())) { |
|
|
|
DynamicBxAreaRule rule_2 = new DynamicBxAreaRule(); |
|
|
|
rule_2.setId(0); |
|
|
|
rule_2.setRunMode((byte) 0); |
|
|
|
rule_2.setRelativeAllPrograms(false); |
|
|
|
rule_2.addRelativeProgram(0); |
|
|
|
DynamicBxArea area_2 = new DynamicBxArea(0, 22, 192, 22, screen.getProfile()); |
|
|
|
TextBxPage page_2 = new TextBxPage(sbMsg.toString()); |
|
|
|
boolean flag = getStringWidth(sbMsg.toString()); |
|
|
|
if (flag) { |
|
|
|
page_2.setDisplayStyle(styles[1]); |
|
|
|
} else { |
|
|
|
page_2.setDisplayStyle(styles[4]); |
|
|
|
} |
|
|
|
page_2.setFont(new Font("Microsoft YaHei", Font.PLAIN, 12)); |
|
|
|
page_2.setForeground(Color.green); |
|
|
|
page_2.setLineHeight(12); |
|
|
|
area_2.addPage(page_2); |
|
|
|
this.screen.writeDynamic(rule_2, area_2); |
|
|
|
this.errorMsgInfo = sbMsg.toString(); |
|
|
|
} |
|
|
|
page_2.setFont(new Font("Microsoft YaHei", Font.PLAIN, 12)); |
|
|
|
page_2.setForeground(Color.green); |
|
|
|
page_2.setLineHeight(12); |
|
|
|
area_2.addPage(page_2); |
|
|
|
this.screen.writeDynamic(rule_2, area_2); |
|
|
|
this.errorMsgInfo = sbMsg.toString(); |
|
|
|
} |
|
|
|
|
|
|
|
//设置动态区2任务信息
|
|
|
|
StringBuilder sb2 = new StringBuilder(); |
|
|
|
sb2.append("任务信息: "); |
|
|
|
List<String> startDevices = this.getExtraDeviceCodes("startDevices"); |
|
|
|
if (CollectionUtil.isNotEmpty(startDevices)) { |
|
|
|
for (int i = 0; i < startDevices.size(); i++) { |
|
|
|
String start_device_code = startDevices.get(i); |
|
|
|
List<TaskDto> taskDtos = taskService.findTasksByStartCode(start_device_code); |
|
|
|
if (ObjectUtil.isNotEmpty(taskDtos)) { |
|
|
|
for (TaskDto taskDto : taskDtos) { |
|
|
|
sb2.append("载具" + taskDto.getVehicle_code() + "由" + taskDto.getStart_point_code() + "->" + taskDto.getNext_point_code() + ","); |
|
|
|
//设置动态区2任务信息
|
|
|
|
StringBuilder sb2 = new StringBuilder(); |
|
|
|
sb2.append("任务信息: "); |
|
|
|
List<String> startDevices = this.getExtraDeviceCodes("startDevices"); |
|
|
|
if (CollectionUtil.isNotEmpty(startDevices)) { |
|
|
|
for (int i = 0; i < startDevices.size(); i++) { |
|
|
|
String start_device_code = startDevices.get(i); |
|
|
|
List<TaskDto> taskDtos = taskService.findTasksByStartCode(start_device_code); |
|
|
|
if (ObjectUtil.isNotEmpty(taskDtos)) { |
|
|
|
for (TaskDto taskDto : taskDtos) { |
|
|
|
sb2.append("载具" + taskDto.getVehicle_code() + "由" + taskDto.getStart_point_code() + "->" + taskDto.getNext_point_code() + ","); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
List<String> nextDevices = this.getExtraDeviceCodes("nextDevices"); |
|
|
|
if (CollectionUtil.isNotEmpty(nextDevices)) { |
|
|
|
for (int i = 0; i < nextDevices.size(); i++) { |
|
|
|
String next_device_code = nextDevices.get(i); |
|
|
|
List<TaskDto> taskDtos = taskService.findTasksByNextCode(next_device_code); |
|
|
|
if (ObjectUtil.isNotEmpty(taskDtos)) { |
|
|
|
for (TaskDto taskDto : taskDtos) { |
|
|
|
sb2.append("载具" + taskDto.getVehicle_code() + "由" + taskDto.getStart_point_code() + "->" + taskDto.getNext_point_code() + ","); |
|
|
|
List<String> nextDevices = this.getExtraDeviceCodes("nextDevices"); |
|
|
|
if (CollectionUtil.isNotEmpty(nextDevices)) { |
|
|
|
for (int i = 0; i < nextDevices.size(); i++) { |
|
|
|
String next_device_code = nextDevices.get(i); |
|
|
|
List<TaskDto> taskDtos = taskService.findTasksByNextCode(next_device_code); |
|
|
|
if (ObjectUtil.isNotEmpty(taskDtos)) { |
|
|
|
for (TaskDto taskDto : taskDtos) { |
|
|
|
sb2.append("载具" + taskDto.getVehicle_code() + "由" + taskDto.getStart_point_code() + "->" + taskDto.getNext_point_code() + ","); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (sb2.length() > 0 && sb2.charAt(sb2.length() - 1) == ',') { |
|
|
|
sb2.deleteCharAt(sb2.length() - 1); |
|
|
|
} else { |
|
|
|
sb2.append("无任务!"); |
|
|
|
} |
|
|
|
if (!StrUtil.equals(this.taskMsgInfo, sb2.toString())) { |
|
|
|
DynamicBxAreaRule rule = new DynamicBxAreaRule(); |
|
|
|
rule.setId(1); |
|
|
|
rule.setRunMode((byte) 0); |
|
|
|
rule.setRelativeAllPrograms(false); |
|
|
|
rule.addRelativeProgram(0); |
|
|
|
DynamicBxArea dArea = new DynamicBxArea(0, 37, 192, 37, screen.getProfile()); |
|
|
|
TextBxPage dPage = new TextBxPage(sb2.toString()); |
|
|
|
boolean flag = getStringWidth(sb2.toString()); |
|
|
|
if (flag) { |
|
|
|
dPage.setDisplayStyle(styles[1]); |
|
|
|
if (sb2.length() > 0 && sb2.charAt(sb2.length() - 1) == ',') { |
|
|
|
sb2.deleteCharAt(sb2.length() - 1); |
|
|
|
} else { |
|
|
|
dPage.setDisplayStyle(styles[4]); |
|
|
|
sb2.append("无任务!"); |
|
|
|
} |
|
|
|
if (!StrUtil.equals(this.taskMsgInfo, sb2.toString())) { |
|
|
|
DynamicBxAreaRule rule = new DynamicBxAreaRule(); |
|
|
|
rule.setId(1); |
|
|
|
rule.setRunMode((byte) 0); |
|
|
|
rule.setRelativeAllPrograms(false); |
|
|
|
rule.addRelativeProgram(0); |
|
|
|
DynamicBxArea dArea = new DynamicBxArea(0, 37, 192, 37, screen.getProfile()); |
|
|
|
TextBxPage dPage = new TextBxPage(sb2.toString()); |
|
|
|
boolean flag = getStringWidth(sb2.toString()); |
|
|
|
if (flag) { |
|
|
|
dPage.setDisplayStyle(styles[1]); |
|
|
|
} else { |
|
|
|
dPage.setDisplayStyle(styles[4]); |
|
|
|
} |
|
|
|
dPage.setFont(new Font("Microsoft YaHei", Font.PLAIN, 12)); |
|
|
|
dPage.setForeground(Color.green); |
|
|
|
dPage.setLineHeight(12); |
|
|
|
dArea.addPage(dPage); |
|
|
|
screen.writeDynamic(rule, dArea); |
|
|
|
this.taskMsgInfo = sb2.toString(); |
|
|
|
} |
|
|
|
dPage.setFont(new Font("Microsoft YaHei", Font.PLAIN, 12)); |
|
|
|
dPage.setForeground(Color.green); |
|
|
|
dPage.setLineHeight(12); |
|
|
|
dArea.addPage(dPage); |
|
|
|
screen.writeDynamic(rule, dArea); |
|
|
|
this.taskMsgInfo = sb2.toString(); |
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
if (this.screen != null) { |
|
|
|
this.screen.disconnect(); |
|
|
|
System.out.println(this.getDevice().getDevice_code() + "关闭Screen连接!"); |
|
|
|
Thread.sleep(60000); |
|
|
|
} |
|
|
|
} |
|
|
|
Integer upTime = Optional.ofNullable(this.getDevice().getExtraValue().get("upTime")).map(Object::toString).map(Integer::parseInt).orElse(60); |
|
|
|
Thread.sleep(upTime * 1000); |
|
|
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> { |
|
|
|