| | |
| | | package com.zy.core.thread; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.core.common.Cools; |
| | | import com.zy.common.entity.Parameter; |
| | | import com.zy.common.model.MatDto; |
| | | import com.zy.core.Slave; |
| | | import com.zy.core.ThreadHandler; |
| | |
| | | TextCaptionBxArea area; |
| | | DisplayStyleFactory.DisplayStyle[] styles = DisplayStyleFactory.getStyles().toArray(new DisplayStyleFactory.DisplayStyle[0]); |
| | | private Set<Integer> workNos = new HashSet<>(); |
| | | private boolean ledMk = true; |
| | | // private boolean resetStatus = false; // 复位状态 |
| | | |
| | | public LedThread(Slave slave) { |
| | | this.slave = slave; |
| | | try { |
| | | Bx5GEnv.initial(3000); |
| | | screen = new Bx5GScreenClient("my"); |
| | | screen.turnOn(); |
| | | pf = new ProgramBxFile( 0, screen.getProfile()); |
| | | pf.setFrameShow(false); |
| | | // 分别输入X,Y,width,height |
| | | area = new TextCaptionBxArea( 0,0,192,128,screen.getProfile()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.info("led连接构造器错误 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | |
| | | @SuppressWarnings({"InfiniteLoopStatement", "unchecked"}) |
| | | public void run() { |
| | | connect(); |
| | | close(); |
| | | while (true) { |
| | | try { |
| | | Task task = MessageQueue.poll(SlaveType.Led, slave.getId()); |
| | |
| | | case 1: |
| | | write((List<LedCommand>)task.getData()); |
| | | break; |
| | | // 复位 |
| | | case 2: |
| | | reset(); |
| | | break; |
| | | // 警告信息 |
| | | case 3: |
| | | write(String.valueOf(task.getData())); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | |
| | | Thread.sleep(3000); |
| | | Thread.sleep(400); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public boolean connect() { |
| | | boolean connRes = false; |
| | | try { |
| | | connRes = screen.connect(slave.getIp(),slave.getPort()); |
| | | } catch (Exception ignore) { |
| | | } |
| | | if (connRes) { |
| | | log.info("led连接成功 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } else { |
| | | log.error("led连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } |
| | | return connRes; |
| | | } |
| | | |
| | | @Override |
| | | public void close() { |
| | | screen.disconnect(); |
| | | } |
| | | |
| | | |
| | | private void write(List<LedCommand> list) throws Bx5GException { |
| | | // if (!connect()) { |
| | | // return; |
| | | // } |
| | | pf = new ProgramBxFile( 0, screen.getProfile()); |
| | | pf.setFrameShow(false); |
| | | // 分别输入X,Y,width,height |
| | | area = new TextCaptionBxArea( 0,0,192,128, screen.getProfile()); |
| | | // 创建一个数据页 |
| | | TextBxPage page = new TextBxPage(); |
| | | for (LedCommand command : list) { |
| | |
| | | } |
| | | |
| | | // 设置字体 |
| | | page.setFont(new Font("宋体",Font.PLAIN,12)); |
| | | page.setFont(new Font("宋体",Font.PLAIN,14)); |
| | | // 设置文本颜色 |
| | | page.setForeground(Color.red); |
| | | // 设置显示特技为快速打出 |
| | | page.setDisplayStyle(styles[6]); |
| | | area.clearPages(); |
| | | area.addPage(page); |
| | | pf.addArea(area); |
| | | // 更新节目 |
| | | screen.writeProgram(pf); |
| | | // resetStatus = false; |
| | | close(); |
| | | } |
| | | |
| | | private void write(String str) throws Bx5GException { |
| | | // if (!connect() || Cools.isEmpty(str)) { |
| | | // return; |
| | | // } |
| | | pf = new ProgramBxFile( 0, screen.getProfile()); |
| | | pf.setFrameShow(false); |
| | | // 分别输入X,Y,width,height |
| | | area = new TextCaptionBxArea( 0,0,192,128, screen.getProfile()); |
| | | // 创建一个数据页 |
| | | TextBxPage page = new TextBxPage(); |
| | | page.newLine(str); |
| | | page.newLine("\n"); |
| | | // 设置字体 |
| | | page.setFont(new Font("宋体",Font.PLAIN,14)); |
| | | // 设置文本颜色 |
| | | page.setForeground(Color.red); |
| | | // 设置显示特技为快速打出 |
| | | page.setDisplayStyle(styles[6]); |
| | | area.clearPages(); |
| | | area.addPage(page); |
| | | pf.addArea(area); |
| | | // 更新节目 |
| | | screen.writeProgram(pf); |
| | | // resetStatus = false; |
| | | close(); |
| | | } |
| | | |
| | | private void reset() throws Bx5GException { |
| | | // if (!connect()) { |
| | | // return; |
| | | // } |
| | | pf = new ProgramBxFile( 0, screen.getProfile()); |
| | | pf.setFrameShow(false); |
| | | // 分别输入X,Y,width,height |
| | | area = new TextCaptionBxArea( 0,0,192,128, screen.getProfile()); |
| | | // 创建一个数据页 |
| | | TextBxPage page = new TextBxPage(); |
| | | |
| | | List<String> list = null; |
| | | try { |
| | | String ledDefaultMsg = Parameter.get().getLedDefaultMsg(); |
| | | list = JSON.parseArray(ledDefaultMsg, String.class); |
| | | } catch (Exception ignore) { |
| | | } |
| | | if (!Cools.isEmpty(list)) { |
| | | for (String str : list) { |
| | | page.newLine(str); |
| | | } |
| | | } else { |
| | | page.newLine("自动化立体仓库"); |
| | | page.newLine("浙江中扬立库技术有限公司"); |
| | | } |
| | | |
| | | // 设置字体 |
| | | page.setFont(new Font("宋体",Font.PLAIN,15)); |
| | | // 设置文本颜色 |
| | | page.setForeground(Color.red); |
| | | // 设置显示特技为快速打出 |
| | | page.setDisplayStyle(styles[6]); |
| | | area.clearPages(); |
| | | area.addPage(page); |
| | | pf.addArea(area); |
| | | // 更新节目 |
| | | screen.writeProgram(pf); |
| | | close(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean connect() { |
| | | boolean connRes = false; |
| | | try { |
| | | connRes = screen.connect(slave.getIp(),slave.getPort()); |
| | | screen.turnOn(); |
| | | if (connRes) { |
| | | log.info("led连接成功 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | reset(); |
| | | } else { |
| | | log.error("led连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } |
| | | } catch (Exception ignore) { } |
| | | return connRes; |
| | | } |
| | | |
| | | @Override |
| | | public void close() { |
| | | screen.disconnect(); |
| | | } |
| | | |
| | | |
| | | |
| | |
| | | return; |
| | | } |
| | | screen.turnOn(); |
| | | ProgramBxFile pf = new ProgramBxFile( 0, screen.getProfile()); |
| | | pf.setFrameShow(false); |
| | | // 分别输入X,Y,width,heigth |
| | | TextCaptionBxArea area = new TextCaptionBxArea( 0,0,192,128,screen.getProfile()); |
| | | // 创建一个数据页 |
| | | // 第一行数据 |
| | | TextBxPage page = new TextBxPage("全板入库"); |
| | | page.newLine("目标库位:0100204"); |
| | | // 第二行数据 |
| | | page.newLine("接收器 RX18 XH 6V 【数量:2】"); |
| | | page.newLine("中控 BM蓝牙 英文 6V 【数量:1】"); |
| | | page.newLine("线束 S2588-1-XX 无实物【数量:5】"); |
| | | page.newLine("接收器 RX18 XH 6V 【数量:2】"); |
| | | page.newLine("中控 BM蓝牙 英文 6V 【数量:1】"); |
| | | page.newLine("线束 S2588-1-XX 无实物【数量:5】"); |
| | | page.newLine("接收器 RX18 XH 6V 【数量:2】"); |
| | | page.newLine("中控 BM蓝牙 英文 6V 【数量:1】"); |
| | | page.newLine("线束 S2588-1-XX 无实物【数量:5】"); |
| | | // 设置字体 |
| | | page.setFont( new Font("宋体",Font.PLAIN,12)); |
| | | // 设置显示特技为快速打出 |
| | | page.setDisplayStyle(styles[6]); |
| | | area.addPage(page); |
| | | pf.addArea( area ); |
| | | // 更新节目 |
| | | screen.writeProgram(pf); |
| | | |
| | | |
| | | while (true) { |
| | | Thread.sleep(5000L); |
| | | |
| | | ProgramBxFile pf = new ProgramBxFile( 0, screen.getProfile()); |
| | | pf.setFrameShow(false); |
| | | // 分别输入X,Y,width,heigth |
| | | TextCaptionBxArea area = new TextCaptionBxArea( 0,0,192,128,screen.getProfile()); |
| | | |
| | | // 创建一个数据页 |
| | | // 第一行数据 |
| | | TextBxPage page = new TextBxPage("出库任务(303)"); |
| | | page.newLine("源库位:0100204"); |
| | | page.newLine("目标站:1000"); |
| | | // 设置字体 |
| | | page.setFont( new Font("宋体",Font.PLAIN,12)); |
| | | // 设置显示特技为快速打出 |
| | | page.setDisplayStyle(styles[6]); |
| | | area.clearPages(); |
| | | area.addPage(page); |
| | | pf.addArea( area ); |
| | | |
| | | // 更新节目 |
| | | screen.writeProgram(pf); |
| | | } |
| | | |
| | | // 继开与控制器之间的链接 |
| | | screen.disconnect(); |
| | | // screen.disconnect(); |
| | | } |
| | | |
| | | |