| | |
| | | import HslCommunication.Core.Types.OperateResultExOne; |
| | | import HslCommunication.Profinet.Siemens.SiemensPLCS; |
| | | import HslCommunication.Profinet.Siemens.SiemensS7Net; |
| | | import com.core.common.DateUtils; |
| | | import com.zy.common.utils.DateUtils; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.News; |
| | | import com.zy.core.ThreadHandler; |
| | | import com.zy.core.cache.OutputQueue; |
| | | import com.zy.core.model.ForkLiftSlave; |
| | | import com.zy.core.model.protocol.ForkLiftProtocol; |
| | | import com.zy.core.properties.DeviceConfig; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.text.MessageFormat; |
| | |
| | | @SuppressWarnings("all") |
| | | public class LfdZyForkLiftMasterThread implements ThreadHandler { |
| | | |
| | | private ForkLiftSlave slave; |
| | | private ForkLiftProtocol forkLiftProtocol; |
| | | private DeviceConfig deviceConfig; |
| | | private RedisUtil redisUtil; |
| | | private SiemensS7Net siemensS7Net; |
| | | private List<HashMap<String,Object>> slaveAddressList = null; |
| | | private boolean connect = false; |
| | | |
| | | public LfdZyForkLiftMasterThread(ForkLiftSlave slave, RedisUtil redisUtil) { |
| | | this.slave = slave; |
| | | public LfdZyForkLiftMasterThread(DeviceConfig deviceConfig, RedisUtil redisUtil) { |
| | | this.deviceConfig = deviceConfig; |
| | | this.redisUtil = redisUtil; |
| | | ArrayList<HashMap<String, Object>> addressList = new ArrayList<>(); |
| | | |
| | | HashMap<String, Object> lift1 = new HashMap<>(); |
| | | lift1.put("status", new DbData("DB101.0", (short) 16));//提升机数据 |
| | | lift1.put("staStatus", new DbData("DB102.0", (short) 14));//站点数据 |
| | | lift1.put("status", new DbData("DB101.0", (short) 18));//提升机数据 |
| | | lift1.put("staStatusTray", new DbData("DB102.0", (short) 14));//站点数据 |
| | | lift1.put("staStatusCar", new DbData("DB102.50", (short) 14));//站点数据 |
| | | lift1.put("write", new DbData("DB103.0", null));//写入数据 |
| | | lift1.put("writeConfirm", new DbData("DB103.8", null));//写入确认数据 |
| | | lift1.put("confirm", new DbData("DB103.10", null));//确认命令 |
| | | lift1.put("switchIOMode", new DbData("DB103.12", null));//出入库模式 |
| | | |
| | | HashMap<String, Object> lift2 = new HashMap<>(); |
| | | lift2.put("status", new DbData("DB104.0", (short) 16));//提升机数据 |
| | | lift2.put("staStatus", new DbData("DB105.0", (short) 14));//站点数据 |
| | | lift2.put("status", new DbData("DB104.0", (short) 18));//提升机数据 |
| | | lift2.put("staStatusTray", new DbData("DB105.0", (short) 14));//站点数据 |
| | | lift2.put("staStatusCar", new DbData("DB105.50", (short) 14));//站点数据 |
| | | lift2.put("write", new DbData("DB106.0", null));//写入数据 |
| | | lift2.put("writeConfirm", new DbData("DB106.8", null));//写入确认数据 |
| | | lift2.put("confirm", new DbData("DB106.10", null));//确认命令 |
| | |
| | | @Override |
| | | public boolean connect() { |
| | | boolean result = false; |
| | | siemensS7Net = new SiemensS7Net(SiemensPLCS.S1200, slave.getIp()); |
| | | siemensS7Net.setRack(slave.getRack().byteValue()); |
| | | siemensS7Net.setSlot(slave.getSlot().byteValue()); |
| | | siemensS7Net = new SiemensS7Net(SiemensPLCS.S1200, deviceConfig.getIp()); |
| | | siemensS7Net.setRack(Integer.valueOf(0).byteValue()); |
| | | siemensS7Net.setSlot(Integer.valueOf(0).byteValue()); |
| | | OperateResult connect = siemensS7Net.ConnectServer(); |
| | | if(connect.IsSuccess){ |
| | | result = true; |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format( "【{0}】货叉提升机连接成功 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); |
| | | News.info("货叉提升机连接成功 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format( "【{0}】货叉提升机连接成功 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort(), 0, 0)); |
| | | News.info("货叉提升机连接成功 ===>> [id:{}] [ip:{}] [port:{}]", deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort()); |
| | | } else { |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format( "【{0}】货叉提升机连接失败!!! ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot())); |
| | | News.error("货叉提升机连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format( "【{0}】货叉提升机连接失败!!! ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort(), 0, 0)); |
| | | News.error("货叉提升机连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort()); |
| | | } |
| | | // siemensS7Net.ConnectClose(); |
| | | this.connect = result; |
| | |
| | | |
| | | @Override |
| | | public void run() { |
| | | News.info("{}号货叉提升机Master线程启动", slave.getId()); |
| | | News.info("{}号货叉提升机Master线程启动", deviceConfig.getDeviceNo()); |
| | | this.connect(); |
| | | while (true) { |
| | | try { |
| | |
| | | OperateResultExOne<byte[]> result = siemensS7Net.Read(dbData.dbAddress, dbData.dbAddressLength); |
| | | return result; |
| | | } catch (Exception e) { |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format("【{0}】读取提升机状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format("【{0}】读取提升机状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort())); |
| | | } |
| | | return null; |
| | | } |
| | |
| | | OperateResult result = siemensS7Net.Write(dbData.dbAddress, array); |
| | | return result; |
| | | } catch (Exception e) { |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format("【{0}】写入提升机状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format("【{0}】写入提升机状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort())); |
| | | } |
| | | return null; |
| | | } |
| | |
| | | OperateResult result = siemensS7Net.Write(dbData.dbAddress, val); |
| | | return result; |
| | | } catch (Exception e) { |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format("【{0}】写入提升机状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | | OutputQueue.FORKLIFT.offer(MessageFormat.format("【{0}】写入提升机状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort())); |
| | | } |
| | | return null; |
| | | } |