From e83761d390b593cff8b7c17144529e92eb482bd6 Mon Sep 17 00:00:00 2001 From: zhangc <zc@123> Date: 星期三, 16 四月 2025 16:38:04 +0800 Subject: [PATCH] 1 --- src/main/java/com/zy/core/thread/LedThread.java | 165 ++---------------------------------------------------- 1 files changed, 8 insertions(+), 157 deletions(-) diff --git a/src/main/java/com/zy/core/thread/LedThread.java b/src/main/java/com/zy/core/thread/LedThread.java index 9b2d11e..ffb06ab 100644 --- a/src/main/java/com/zy/core/thread/LedThread.java +++ b/src/main/java/com/zy/core/thread/LedThread.java @@ -1,172 +1,23 @@ 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.enums.SlaveType; -import com.zy.core.model.Task; 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; -/** - * Created by vincent on 2020/9/1 - */ -@Data -@Slf4j -public class LedThread implements Runnable, ThreadHandler { +public interface LedThread extends 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; // 澶嶄綅鐘舵�� + void write(List<LedCommand> commands); - // 鏄剧ず鍣� - private StringBuffer stringBuffer = new StringBuffer(); - private List<LedCommand> commandList; + void reset(); - private StringBuffer errorMsg = new StringBuffer(); + void error(String error); - public LedThread(Slave slave) { - this.slave = slave; - } + void errorReset(); - @Override - @SuppressWarnings({"InfiniteLoopStatement", "unchecked"}) - public void run() { -// connect(); - while (true) { - try { - Task task = MessageQueue.poll(SlaveType.Led, slave.getId()); - if (task != null) { - switch (task.getStep()) { - // 鍐欐暟鎹� - case 1: - write((List<LedCommand>)task.getData()); - break; - // 澶嶄綅 - case 2: - reset(); - break; - case 3: - error((String) task.getData()); - break; - case 4: - errorReset(); - break; - default: - break; - } - } - Thread.sleep(1000); - } catch (Exception e) { - e.printStackTrace(); - } - } - } + void setLedMk(boolean mk); - private void write(List<LedCommand> list) throws Bx5GException { - if (!connect()) { - return; - } - - pf = new ProgramBxFile( 0, screen.getProfile()); - pf.setFrameShow(false); - // 鍒嗗埆杈撳叆X锛孻锛寃idth锛宧eight - area = new TextCaptionBxArea( 0,0,96,48, screen.getProfile()); - // 鍒涘缓涓�涓暟鎹〉 - TextBxPage page = new TextBxPage(); - for (LedCommand command : list) { - page.newLine(command.getTitle() +"锛�"+command.getWorkNo()+")"); - page.newLine("搴撲綅锛�"+ (command.getIoType() < 100 ? command.getLocNo() : command.getSourceLocNo())); - page.newLine("鐩爣绔欙細"+command.getStaNo()); - 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() +"銆�"); - } - } - page.newLine("\n"); - } - - // 璁剧疆瀛椾綋 - 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(); - } - - - private void reset() { - commandList = null; - - stringBuffer.delete(0, stringBuffer.length()); - } - - - private void error(String msg) { - errorMsg.delete(0, errorMsg.length()); - errorMsg.append(msg); - } - - public void errorReset() { - this.errorMsg.delete(0, errorMsg.length()); - } - - @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; - } - - @Override - public void close() { - } + boolean isLedMk(); } -- Gitblit v1.9.1