File was renamed from src/main/java/com/zy/core/thread/DevpThread.java |
| | |
| | | import com.core.common.SpringUtils; |
| | | import com.zy.asrs.entity.BasDevp; |
| | | import com.zy.asrs.service.BasDevpService; |
| | | import com.zy.core.ThreadHandler; |
| | | import com.zy.core.DevpThread; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.cache.OutputQueue; |
| | | import com.zy.core.enums.SlaveType; |
| | |
| | | */ |
| | | @Data |
| | | @Slf4j |
| | | public class DevpThread implements Runnable, ThreadHandler { |
| | | public class SiemensDevpThread implements Runnable, DevpThread { |
| | | |
| | | private DevpSlave slave; |
| | | private SiemensS7Net siemensS7Net; |
| | | private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>(); |
| | | private short heartBeatVal = 1; |
| | | |
| | | public DevpThread(DevpSlave slave) { |
| | | public SiemensDevpThread(DevpSlave slave) { |
| | | this.slave = slave; |
| | | } |
| | | |
| | |
| | | // 写数据 ID+目标站 |
| | | case 2: |
| | | write((StaProtocol)task.getData()); |
| | | break; |
| | | // 写数据 ID |
| | | case 3: |
| | | writeId((StaProtocol)task.getData()); |
| | | break; |
| | | // 写数据 目标站 |
| | | case 4: |
| | | writeStaNo((StaProtocol)task.getData()); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 写入 ID =====> 单站点写入 |
| | | */ |
| | | private void writeId(StaProtocol staProtocol){ |
| | | if (null == staProtocol) { |
| | | return; |
| | | } |
| | | OperateResult write = siemensS7Net.Write("DB100." + (staProtocol.getSiteId() - 1) * 2, staProtocol.getWorkNo()); // 工作号 |
| | | if (!write.IsSuccess ) { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线站点数据失败。输送线plc编号={1},站点数据={2}", slave.getId(), JSON.toJSON(staProtocol))); |
| | | log.error("写入输送线站点数据失败。输送线plc编号={},站点数据={}", slave.getId(), JSON.toJSON(staProtocol)); |
| | | } else { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(staProtocol))); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 写入 目标站 =====> 单站点写入 |
| | | */ |
| | | private void writeStaNo(StaProtocol staProtocol){ |
| | | if (null == staProtocol) { |
| | | return; |
| | | } |
| | | OperateResult write = siemensS7Net.Write("DB100." + ((staProtocol.getSiteId() - 1) * 2 + 20), staProtocol.getStaNo()); // 目标站 |
| | | if (!write.IsSuccess ) { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】写入输送线站点数据失败。输送线plc编号={1},站点数据={2}", slave.getId(), JSON.toJSON(staProtocol))); |
| | | log.error("写入输送线站点数据失败。输送线plc编号={},站点数据={}", slave.getId(), JSON.toJSON(staProtocol)); |
| | | } else { |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(staProtocol))); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 心跳 |
| | | */ |
| | | private void heartbeat(){ |
| | |
| | | /** |
| | | * 设置入库标记 |
| | | */ |
| | | @Override |
| | | public void setPakMk(Integer siteId, boolean pakMk) { |
| | | StaProtocol staProtocol = station.get(siteId); |
| | | if (null != staProtocol) { |
| | |
| | | public static void main(String[] args) throws Exception { |
| | | DevpSlave slave = new DevpSlave(); |
| | | slave.setIp("192.168.2.125"); |
| | | DevpThread devpThread = new DevpThread(slave); |
| | | SiemensDevpThread devpThread = new SiemensDevpThread(slave); |
| | | devpThread.connect(); |
| | | devpThread.read(); |
| | | // 写 |