| | |
| | | package com.zy.core.thread; |
| | | |
| | | import HslCommunication.Core.Types.OperateResult; |
| | | import HslCommunication.Profinet.Siemens.SiemensPLCS; |
| | | import HslCommunication.Profinet.Siemens.SiemensS7Net; |
| | | 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.protocol.CrnProtocol; |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | /** |
| | | * 堆垛机线程 |
| | | * Created by vincent on 2020/8/4 |
| | | */ |
| | | @Data |
| | | @Slf4j |
| | | public class CrnThread implements Runnable, ThreadHandler { |
| | | |
| | | SiemensS7Net siemensNet; |
| | | private Slave slave; |
| | | private CrnProtocol crnProtocol; |
| | | |
| | | public CrnThread(Slave slave) { |
| | | this.slave = slave; |
| | |
| | | public void run() { |
| | | while (true) { |
| | | try { |
| | | System.out.println("线程"+slave.getId()+"正在运行"); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | Thread.sleep(1000); |
| | | int step = 1; |
| | | Task task = MessageQueue.poll(SlaveType.Devp, slave.getId()); |
| | | if (task != null) { |
| | | step = task.getStep(); |
| | | } |
| | | switch (step) { |
| | | // 读数据 |
| | | case 1: |
| | | readStatus(); // 读取状态 |
| | | break; |
| | | case 2: |
| | | break; |
| | | case 3: |
| | | break; |
| | | case 4: |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | Thread.sleep(3000); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public boolean connect() { |
| | | boolean result = false; |
| | | siemensNet = new SiemensS7Net(SiemensPLCS.S1200,slave.getIp()); |
| | | siemensNet.setRack((byte) 0); |
| | | siemensNet.setSlot((byte) 1); |
| | | OperateResult connect = siemensNet.ConnectServer(); |
| | | if(connect.IsSuccess){ |
| | | result = true; |
| | | log.info("堆垛机plc连接成功 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } else { |
| | | log.info("堆垛机plc连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | } |
| | | siemensNet.ConnectClose(); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 读取状态 |
| | | */ |
| | | private void readStatus(){ |
| | | CrnProtocol protocol = new CrnProtocol(); |
| | | protocol.setMode(siemensNet.ReadInt16("D2231").Content); |
| | | protocol.setEStop(siemensNet.ReadInt16("D2232").Content); |
| | | protocol.setTaskNo(siemensNet.ReadInt16("D2233").Content); |
| | | protocol.setStatus(siemensNet.ReadInt16("D2234").Content); |
| | | protocol.setBay(siemensNet.ReadInt16("D2235").Content); |
| | | protocol.setLevel(siemensNet.ReadInt16("D2236").Content); |
| | | protocol.setForkPos(siemensNet.ReadInt16("D2237").Content); |
| | | protocol.setLiftPos(siemensNet.ReadInt16("D2238").Content); |
| | | protocol.setWalkPos(siemensNet.ReadInt16("D2239").Content); |
| | | protocol.setTaskFinish(siemensNet.ReadInt16("D2240").Content); |
| | | protocol.setLoaded(siemensNet.ReadInt16("D2241").Content); |
| | | protocol.setAlarm(siemensNet.ReadInt16("D2242").Content); |
| | | protocol.setXDistance(siemensNet.ReadInt32("D2251").Content); |
| | | protocol.setYDistance(siemensNet.ReadInt32("D2253").Content); |
| | | protocol.setDuration(siemensNet.ReadInt32("D2255").Content); |
| | | this.crnProtocol = protocol; |
| | | } |
| | | |
| | | /** |
| | | * 写入数据 |
| | | */ |
| | | private void write(){ |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void close() { |
| | | |
| | | |
| | | |
| | | } |
| | | } |