| | |
| | | package com.zy.core.thread; |
| | | |
| | | import com.zy.common.model.MatDto; |
| | | import com.zy.common.utils.News; |
| | | import com.zy.core.Slave; |
| | | import com.zy.core.ThreadHandler; |
| | | import com.zy.core.cache.MessageQueue; |
| | |
| | | import com.zy.core.model.command.LedCommand; |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import onbon.bx05.Bx5GEnv; |
| | | import onbon.bx05.Bx5GException; |
| | | import onbon.bx05.Bx5GScreenClient; |
| | | import onbon.bx05.area.TextCaptionBxArea; |
| | | import onbon.bx05.area.page.TextBxPage; |
| | | import onbon.bx05.file.ProgramBxFile; |
| | | import onbon.bx05.utils.DisplayStyleFactory; |
| | | |
| | | import java.awt.*; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | |
| | | @Slf4j |
| | | public class LedThread implements Runnable, ThreadHandler { |
| | | |
| | | private Bx5GScreenClient screen; |
| | | private ProgramBxFile pf; |
| | | private TextCaptionBxArea area; |
| | | DisplayStyleFactory.DisplayStyle[] styles = DisplayStyleFactory.getStyles().toArray(new DisplayStyleFactory.DisplayStyle[0]); |
| | | private Slave slave; |
| | | private Set<Integer> workNos = new HashSet<>(); |
| | | private boolean ledMk = false; |
| | | private boolean resetStatus = false; // 复位状态 |
| | | |
| | | // 显示器 |
| | | private StringBuffer stringBuffer = new StringBuffer(); |
| | |
| | | } |
| | | } |
| | | |
| | | private void write(List<LedCommand> list) throws Bx5GException { |
| | | if (!connect()) { |
| | | return; |
| | | } |
| | | private void write(List<LedCommand> list) { |
| | | commandList = list; |
| | | |
| | | pf = new ProgramBxFile( 0, screen.getProfile()); |
| | | pf.setFrameShow(false); |
| | | // 分别输入X,Y,width,height |
| | | area = new TextCaptionBxArea( 0,0,96,48, screen.getProfile()); |
| | | // 创建一个数据页 |
| | | TextBxPage page = new TextBxPage(); |
| | | StringBuilder sb = new StringBuilder(); |
| | | for (LedCommand command : list) { |
| | | page.newLine(command.getTitle() +"("+command.getWorkNo()+")"); |
| | | page.newLine("库位:"+ (command.getIoType() < 100 ? command.getLocNo() : command.getSourceLocNo())); |
| | | page.newLine("目标站:"+command.getStaNo()); |
| | | sb.append(command.getTitle()).append("(").append(command.getWorkNo()).append(")").append("\n"); |
| | | sb.append("源库位:").append(command.getSourceLocNo()).append("\n"); |
| | | sb.append("目标站:").append(command.getStaNo()).append("\n"); |
| | | if (!command.isEmptyMk()) { |
| | | for (MatDto matDto : command.getMatDtos()) { |
| | | //去掉小数点 |
| | | String strQty = matDto.getCount().toString(); |
| | | int idx = strQty.lastIndexOf("."); |
| | | if(idx >= 0){ |
| | | strQty.substring(0,idx); |
| | | } |
| | | page.newLine(matDto.getMaknx() + "[数量" + strQty +"]"); |
| | | // page.newLine(matDto.getMaknx() + "【数量" + matDto.getCount() +"】"); |
| | | sb.append(matDto.getMatnr()).append("-").append(matDto.getBatch()).append("\n"); |
| | | } |
| | | } |
| | | page.newLine("\n"); |
| | | sb.append("\n"); |
| | | } |
| | | stringBuffer.delete(0, stringBuffer.length()); |
| | | stringBuffer.append(sb.toString()); |
| | | |
| | | // 设置字体 |
| | | page.setFont(new Font("宋体",Font.PLAIN,12)); |
| | | // 设置文本颜色 |
| | | page.setForeground(Color.red); |
| | | // 设置显示特技为快速打出 |
| | | page.setDisplayStyle(styles[6]); |
| | | area.clearPages(); |
| | | area.addPage(page); |
| | | pf.addArea(area); |
| | | if (pf.validate() != null) { |
| | | News.info("Led"+" - 2"+" - pf out of range"); |
| | | } else { |
| | | // 更新节目 |
| | | screen.writeProgram(pf); |
| | | // resetStatus = false; |
| | | } |
| | | close(); |
| | | errorReset(); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | @Override |
| | | public boolean connect() { |
| | | boolean connRes = false; |
| | | try { |
| | | connRes = screen.connect(slave.getIp(),slave.getPort()); |
| | | screen.turnOn(); |
| | | } catch (Exception ignore) { |
| | | } |
| | | if (connRes) { |
| | | News.info("Led"+" - 4"+" - led连接成功 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } else { |
| | | News.error("Led"+" - 5"+" - led连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } |
| | | return connRes; |
| | | return true; |
| | | } |
| | | |
| | | @Override |