| src/main/java/com/zy/core/ServerBootstrap.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| src/main/java/com/zy/core/controller/OpenController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| src/main/java/com/zy/core/enums/RedisKeyType.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| src/main/java/com/zy/core/thread/ForkLiftThread.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| src/main/java/com/zy/core/thread/fake/FakeZyForkLiftThread.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| src/main/java/com/zy/core/thread/impl/NyShuttleThread.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| src/main/java/com/zy/core/thread/impl/ZyForkLiftThread.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| src/main/resources/application.yml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/zy/core/ServerBootstrap.java
@@ -7,6 +7,7 @@ import com.zy.core.enums.SlaveType; import com.zy.core.properties.DeviceConfig; import com.zy.core.thread.fake.FakeNyShuttleThread; import com.zy.core.thread.fake.FakeZyForkLiftThread; import com.zy.core.thread.impl.LfdZyForkLiftMasterThread; import com.zy.core.thread.impl.NyShuttleThread; import com.zy.core.utils.DeviceMsgUtils; @@ -75,6 +76,9 @@ private void initFakeThread(){ ThreadHandler thread = new FakeNyShuttleThread(redisUtil, gatewayPort); new Thread(thread).start(); ThreadHandler thread2 = new FakeZyForkLiftThread(redisUtil); new Thread(thread2).start(); } src/main/java/com/zy/core/controller/OpenController.java
@@ -6,6 +6,7 @@ import com.zy.core.model.param.AddFakeDeviceParam; import com.zy.core.model.param.DeleteDeviceParam; import com.zy.core.properties.DeviceConfig; import com.zy.core.thread.ForkLiftThread; import com.zy.core.thread.ShuttleThread; import com.zy.core.utils.DeviceMsgUtils; import com.zy.core.utils.FakeDeviceUtils; @@ -48,6 +49,12 @@ continue; } deviceList.add(shuttleThread.getDeviceConfig()); } else if (slaveType.equals(SlaveType.ForkLift)) { ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(slaveType, config.getDeviceNo()); if(forkLiftThread == null){ continue; } deviceList.add(forkLiftThread.getDeviceConfig()); } } src/main/java/com/zy/core/enums/RedisKeyType.java
@@ -10,6 +10,9 @@ DEVICE_SHUTTLE_COMMAND_MSG_KEY("deviceShuttleCommandMsgKey_"), DEVICE_FORK_LIFT_COMMAND_MSG_KEY("deviceForkLiftCommandMsgKey_"), //虚拟设备指令消息KEY FAKE_DEVICE_FORK_LIFT_COMMAND_MSG_KEY("fakeDeviceForkLiftCommandMsgKey_"), //设备配置文件 DEVICE_CONFIG("deviceConfig"), //虚拟设备配置文件 src/main/java/com/zy/core/thread/ForkLiftThread.java
@@ -1,7 +1,10 @@ package com.zy.core.thread; import com.zy.core.ThreadHandler; import com.zy.core.properties.DeviceConfig; public interface ForkLiftThread extends ThreadHandler { DeviceConfig getDeviceConfig(); } src/main/java/com/zy/core/thread/fake/FakeZyForkLiftThread.java
New file @@ -0,0 +1,364 @@ package com.zy.core.thread.fake; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.zy.common.Cools; import com.zy.common.SpringUtils; import com.zy.common.utils.RedisUtil; import com.zy.core.News; import com.zy.core.ThreadHandler; import com.zy.core.cache.SlaveConnection; import com.zy.core.enums.RedisKeyType; import com.zy.core.enums.SlaveType; import com.zy.core.model.DeviceCommandMsgModel; import com.zy.core.model.DeviceMsgModel; import com.zy.core.properties.DeviceConfig; import com.zy.core.thread.impl.ZyForkLiftThread; import com.zy.core.utils.DeviceMsgUtils; import com.zy.core.utils.FakeDeviceUtils; import lombok.extern.slf4j.Slf4j; import java.io.*; import java.util.*; @Slf4j @SuppressWarnings("all") public class FakeZyForkLiftThread implements ThreadHandler { private RedisUtil redisUtil; private JSONObject fakeStatusDemo = JSONObject.parseObject("{\"model\":2,\"wrkNo\":0,\"lev\":1,\"protocolStatus\":0,\"taskMode\":0,\"pick\":0,\"put\":0,\"iOMode\":0,\"errorCode\":0,\"trayList\":[0,0,0,0],\"carList\":[0,0,0,0]}"); private HashMap<String, Thread> fakeThreadMap = new HashMap(); private HashMap<String, JSONObject> fakeStatusMap = new HashMap(); private HashMap<String, JSONObject> fakeCommandMap = new HashMap(); private boolean fake = false; public FakeZyForkLiftThread(RedisUtil redisUtil) { this.redisUtil = redisUtil; } @Override public void run() { News.info("Fake Server is Started"); Thread fakeCommandThread = new Thread(() -> { while (true) { try { FakeDeviceUtils fakeDeviceUtils = null; try { fakeDeviceUtils = SpringUtils.getBean(FakeDeviceUtils.class); }catch (Exception e){} if(fakeDeviceUtils == null){ continue; } List<DeviceConfig> deviceConfigs = fakeDeviceUtils.getFakeDeviceConfig(); for (DeviceConfig device : deviceConfigs) { excuteFakeCommand(String.valueOf(SlaveType.ForkLift) + device.getDeviceNo()); } }catch (Exception e){ e.printStackTrace(); } } }); fakeCommandThread.start(); while (true) { try { initFakeDeviceServer(); }catch (Exception e){ e.printStackTrace(); } } } private synchronized void initFakeDeviceServer() { FakeDeviceUtils fakeDeviceUtils = null; try { fakeDeviceUtils = SpringUtils.getBean(FakeDeviceUtils.class); }catch (Exception e){} if(fakeDeviceUtils == null){ return; } List<DeviceConfig> deviceConfigs = fakeDeviceUtils.getFakeDeviceConfig(); for (DeviceConfig device : deviceConfigs) { if (!device.getDeviceType().equals(String.valueOf(SlaveType.ForkLift))) { continue; } if (!device.getThreadImpl().equals("ZyForkLiftThread")) { continue; } if (fakeThreadMap.containsKey(String.valueOf(SlaveType.ForkLift) + device.getDeviceNo())) { continue; } Thread fakeThread = new Thread(() -> { log.info("{}:device is start handle client", device.getDeviceNo()); try { while (true) { handleClient(device); } }catch (Exception e){ e.printStackTrace(); } }); fakeThread.start(); String fakeStatus = JSON.toJSONString(fakeStatusDemo); if (!Cools.isEmpty(device.getFakeInitStatus())) { fakeStatus = device.getFakeInitStatus(); } fakeThreadMap.put(String.valueOf(SlaveType.ForkLift) + device.getDeviceNo(), fakeThread); fakeStatusMap.put(String.valueOf(SlaveType.ForkLift) + device.getDeviceNo(), JSON.parseObject(fakeStatus)); // init ThreadHandler thread = new ZyForkLiftThread(device, redisUtil);; new Thread(thread).start(); SlaveConnection.put(SlaveType.ForkLift, device.getDeviceNo(), thread); } } private void excuteFakeCommand(String key) { if (!fakeCommandMap.containsKey(key)) { return; } JSONObject command = fakeCommandMap.get(key); JSONObject commandBody = command.getJSONObject("commandBody"); fakeCommandMap.remove(key); new Thread(() -> { try { JSONObject fakeStatus = fakeStatusMap.get(key); Integer commandType = command.getInteger("commandType"); if (commandType == null) { return; } if (commandType == 3) { //取放货 fakeStatus.put("wrkNo", commandBody.getInteger("taskNo"));//任务号 fakeStatus.put("protocolStatus", 1);//取货中 fakeStatus.put("taskMode", commandType);//任务类型 fakeStatus.put("pick", commandBody.getInteger("pick"));//取货数据 fakeStatus.put("put", commandBody.getInteger("put"));//放货数据 fakeStatusMap.put(key, fakeStatus); //delay Thread.sleep(5000); fakeStatus.put("protocolStatus", 2);//放货中 fakeStatusMap.put(key, fakeStatus); //delay Thread.sleep(5000); fakeStatus.put("protocolStatus", 98);//等待确认 fakeStatus.put("lev", command.getInteger("put")); fakeStatusMap.put(key, fakeStatus); } else if (commandType == 4) { //小车换层 fakeStatus.put("wrkNo", commandBody.getInteger("taskNo"));//任务号 fakeStatus.put("protocolStatus", 1);//取货中 fakeStatus.put("taskMode", commandType);//任务类型 fakeStatus.put("pick", commandBody.getInteger("pick"));//取货数据 fakeStatus.put("put", commandBody.getInteger("put"));//放货数据 fakeStatusMap.put(key, fakeStatus); //delay Thread.sleep(5000); fakeStatus.put("protocolStatus", 2);//放货中 fakeStatusMap.put(key, fakeStatus); //delay Thread.sleep(5000); fakeStatus.put("protocolStatus", 98);//等待确认 fakeStatus.put("lev", commandBody.getInteger("put")); fakeStatusMap.put(key, fakeStatus); } else if (commandType == 5) { //提升机移动 fakeStatus.put("wrkNo", commandBody.getInteger("taskNo"));//任务号 fakeStatus.put("protocolStatus", 3);//移动中 fakeStatus.put("taskMode", commandType);//任务类型 fakeStatus.put("pick", commandBody.getInteger("pick"));//取货数据 fakeStatus.put("put", commandBody.getInteger("put"));//放货数据 fakeStatusMap.put(key, fakeStatus); //delay Thread.sleep(5000); fakeStatus.put("protocolStatus", 98);//等待确认 fakeStatus.put("lev", commandBody.getInteger("pick")); fakeStatusMap.put(key, fakeStatus); } else if (commandType == 9996) { //复位 fakeStatus.put("wrkNo", 0);//任务号 fakeStatus.put("protocolStatus", 0); fakeStatus.put("taskMode", 0);//任务类型 fakeStatus.put("pick", 0);//取货数据 fakeStatus.put("put", 0);//放货数据 fakeStatusMap.put(key, fakeStatus); } else if (commandType == 9997) { //切换入库模式 fakeStatus.put("iOMode", 1);//出入库模式 fakeStatusMap.put(key, fakeStatus); } else if (commandType == 9998) { //切换出库模式 fakeStatus.put("iOMode", 2);//出入库模式 fakeStatusMap.put(key, fakeStatus); } }catch (Exception e){ e.printStackTrace(); } }).start(); } private void handleClient(DeviceConfig device) throws IOException { try { Set<String> keys = redisUtil.searchKeys(RedisKeyType.FAKE_DEVICE_FORK_LIFT_COMMAND_MSG_KEY.key + device.getDeviceNo()); if (keys.isEmpty()) { return; } TreeSet<String> treeSet = new TreeSet<>(); for (String key : keys) { treeSet.add(key); } String first = treeSet.first(); DeviceCommandMsgModel deviceCommandMsgModel = (DeviceCommandMsgModel) redisUtil.get(first); redisUtil.del(first); // log.info("收到Client Data: {}", JSON.toJSONString(result)); processCommand(deviceCommandMsgModel, device); } catch (Exception e) { e.printStackTrace(); } } private void removeFake(DeviceConfig device) { Thread thread = fakeThreadMap.get(String.valueOf(SlaveType.ForkLift) + device.getDeviceNo()); if (thread != null) { thread.interrupt(); } fakeThreadMap.remove(String.valueOf(SlaveType.ForkLift) + device.getDeviceNo()); fakeStatusMap.remove(String.valueOf(SlaveType.ForkLift) + device.getDeviceNo()); fakeCommandMap.remove(String.valueOf(SlaveType.ForkLift) + device.getDeviceNo()); } public void processCommand(DeviceCommandMsgModel deviceCommandMsgModel, DeviceConfig device) throws IOException { DeviceMsgUtils deviceMsgUtils = SpringUtils.getBean(DeviceMsgUtils.class); if (deviceMsgUtils == null) { return; } HashMap<String, Object> response = null; JSONObject fakeStatus = fakeStatusMap.get(String.valueOf(SlaveType.ForkLift) + device.getDeviceNo()); String command = JSON.toJSONString(deviceCommandMsgModel.getCommand()); JSONObject commandObj = JSON.parseObject(command); Integer mode = commandObj.getInteger("mode"); String deviceMsgType = "command"; JSONObject fakeCommand = new JSONObject(); fakeCommand.put("deviceNo", device.getDeviceNo()); fakeCommand.put("deviceType", device.getDeviceType()); fakeCommand.put("commandType", commandObj.getInteger("mode")); fakeCommand.put("commandBody", command); if (mode == 3) { //取放货 fakeCommandMap.put(String.valueOf(SlaveType.ForkLift) + device.getDeviceNo(), fakeCommand); response = genereateFakeCommandResponse(); } else if (mode == 4) { //小车换层 fakeCommandMap.put(String.valueOf(SlaveType.ForkLift) + device.getDeviceNo(), fakeCommand); response = genereateFakeCommandResponse(); } else if (mode == 5) { //提升机移动 fakeCommandMap.put(String.valueOf(SlaveType.ForkLift) + device.getDeviceNo(), fakeCommand); response = genereateFakeCommandResponse(); } else if (mode == 9996) { //复位 fakeCommandMap.put(String.valueOf(SlaveType.ForkLift) + device.getDeviceNo(), fakeCommand); response = genereateFakeCommandResponse(); } else if (mode == 9997) { //切换入库模式 fakeCommandMap.put(String.valueOf(SlaveType.ForkLift) + device.getDeviceNo(), fakeCommand); response = genereateFakeCommandResponse(); } else if (mode == 9998) { //切换出库模式 fakeCommandMap.put(String.valueOf(SlaveType.ForkLift) + device.getDeviceNo(), fakeCommand); response = genereateFakeCommandResponse(); } else if (mode == 9999) { //读取状态 response = genereateFakeStatusResponse(fakeStatus); deviceMsgType = "status"; } fakeStatusMap.put(String.valueOf(SlaveType.ForkLift) + device.getDeviceNo(), fakeStatus); if (deviceMsgType.equals("command")) { log.info("收到Rcs ForkLift Command Data: {}", JSON.toJSONString(deviceCommandMsgModel)); } DeviceMsgModel deviceMsgModel = new DeviceMsgModel(); deviceMsgModel.setDeviceId(device.getDeviceNo()); deviceMsgModel.setDeviceMsgType(deviceMsgType); deviceMsgModel.setDeviceMsg(response); deviceMsgModel.setDeviceOriginMsg(JSON.toJSONString(response)); deviceMsgModel.setResultKey(deviceCommandMsgModel.getResultKey()); deviceMsgUtils.sendDeviceMsg(SlaveType.ForkLift, device.getDeviceNo(), deviceMsgModel); } public HashMap<String, Object> genereateFakeStatusResponse(JSONObject fakeStatus) { JSONObject device = new JSONObject(); HashMap<String, Object> resultData = new HashMap<>(); resultData.put("result", "success"); resultData.put("deviceStatus", device); device.put("model", fakeStatus.getInteger("model")); device.put("wrkNo", fakeStatus.getInteger("wrkNo")); device.put("protocolStatus", fakeStatus.getInteger("protocolStatus")); device.put("taskMode", fakeStatus.getInteger("taskMode")); device.put("pick", fakeStatus.getInteger("pick")); device.put("put", fakeStatus.getInteger("put")); device.put("iOMode", fakeStatus.getInteger("iOMode")); device.put("errorCode", fakeStatus.getInteger("errorCode")); device.put("lev", fakeStatus.getInteger("lev")); Object trayListObj = fakeStatus.get("trayList"); List<Integer> trayList = new ArrayList<>(); if (trayListObj != null) { trayList = JSON.parseArray(JSON.toJSONString(trayListObj), Integer.class); } Object carListObj = fakeStatus.get("carList"); List<Integer> carList = new ArrayList<>(); if (carListObj != null) { carList = JSON.parseArray(JSON.toJSONString(carListObj), Integer.class); } device.put("trayList", trayList); device.put("carList", carList); return resultData; } public HashMap<String, Object> genereateFakeCommandResponse() { HashMap<String, Object> resultData = new HashMap<>(); resultData.put("result", "success"); return resultData; } @Override public boolean connect() { return true; } @Override public void close() { } } src/main/java/com/zy/core/thread/impl/NyShuttleThread.java
@@ -165,7 +165,7 @@ deviceMsgModel.setResultKey(resultKey); deviceMsgUtils.sendDeviceMsg(SlaveType.Shuttle, deviceConfig.getDeviceNo(), deviceMsgModel); }else { log.info("收到Server Command Data: {}", JSON.toJSONString(result)); log.info("收到Rcs Shuttle Command Data: {}", JSON.toJSONString(result)); DeviceMsgModel deviceMsgModel = new DeviceMsgModel(); deviceMsgModel.setDeviceId(deviceConfig.getDeviceNo()); deviceMsgModel.setDeviceMsgType("command"); @@ -175,7 +175,7 @@ deviceMsgUtils.sendDeviceMsg(SlaveType.Shuttle, deviceConfig.getDeviceNo(), deviceMsgModel); } } else if ("requestMsg".equals(msgType)) { log.info("收到Server Init Data: {}", JSON.toJSONString(result)); log.info("收到Shuttle Init Data: {}", JSON.toJSONString(result)); String requestType = body.getString("requestType"); if (requestType.equals("init")) { DeviceMsgModel deviceMsgModel = new DeviceMsgModel(); src/main/java/com/zy/core/thread/impl/ZyForkLiftThread.java
New file @@ -0,0 +1,274 @@ package com.zy.core.thread.impl; import HslCommunication.Core.Types.OperateResult; import HslCommunication.Core.Types.OperateResultExOne; import HslCommunication.Profinet.Siemens.SiemensPLCS; import HslCommunication.Profinet.Siemens.SiemensS7Net; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.zy.common.SpringUtils; import com.zy.common.utils.DateUtils; import com.zy.common.utils.RedisUtil; import com.zy.core.News; import com.zy.core.cache.OutputQueue; import com.zy.core.enums.*; import com.zy.core.model.DeviceCommandMsgModel; import com.zy.core.model.DeviceMsgModel; import com.zy.core.properties.DeviceConfig; import com.zy.core.thread.ForkLiftThread; import com.zy.core.utils.DeviceMsgUtils; import lombok.Data; import lombok.extern.slf4j.Slf4j; import java.text.MessageFormat; import java.util.*; @Slf4j @SuppressWarnings("all") public class ZyForkLiftThread implements ForkLiftThread { private DeviceConfig deviceConfig; private RedisUtil redisUtil; private SiemensS7Net siemensS7Net; private boolean connect = false; public ZyForkLiftThread(DeviceConfig deviceConfig, RedisUtil redisUtil) { this.deviceConfig = deviceConfig; this.redisUtil = redisUtil; } @Override public boolean connect() { if (deviceConfig.getFake()) { this.connect = true; 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:{}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort()); return true; } boolean result = false; 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()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort(), 0, 0)); News.info("【{}】货叉提升机连接成功 ===>> [id:{}] [ip:{}] [port:{}]", DateUtils.convert(new Date()), 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()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort(), 0, 0)); News.error("【{}】货叉提升机连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort()); } // siemensS7Net.ConnectClose(); this.connect = result; return result; } @Override public void close() { } @Override public void run() { News.info("{}号货叉提升机线程启动", deviceConfig.getDeviceNo()); this.connect(); while (true) { try { DeviceMsgUtils deviceMsgUtils = null; try { deviceMsgUtils = SpringUtils.getBean(DeviceMsgUtils.class); }catch (Exception e){} if (deviceMsgUtils == null) { continue; } DeviceCommandMsgModel deviceCommandMsg = deviceMsgUtils.getDeviceCommandMsg(SlaveType.ForkLift, deviceConfig.getDeviceNo()); if (deviceCommandMsg == null) { continue; } executeCommand(deviceCommandMsg, deviceMsgUtils); Thread.sleep(200); } catch (Exception e) { e.printStackTrace(); } } } private void executeCommand(DeviceCommandMsgModel deviceCommandMsg, DeviceMsgUtils deviceMsgUtils) { if (deviceConfig.getFake()) { redisUtil.set(RedisKeyType.FAKE_DEVICE_FORK_LIFT_COMMAND_MSG_KEY.key + deviceConfig.getDeviceNo(), deviceCommandMsg, 60 * 60); return; } String command = JSON.toJSONString(deviceCommandMsg.getCommand()); JSONObject commandObj = JSON.parseObject(command); HashMap<String, Object> resultData = new HashMap<>(); resultData.put("result", "false"); String deviceMsgType = "command"; OperateResult result = null; OperateResult result2 = null; if (commandObj.getInteger("mode") == 3) { //取放货 short[] array = new short[4]; array[0] = commandObj.getShort("taskNO");//任务号 array[1] = commandObj.getShort("mode");//任务模式 array[2] = commandObj.getShort("pick");//取货数据 array[3] = commandObj.getShort("put");//放货数据 resultData.put("commandData", array); result = siemensS7Net.Write("DB103.0", array); if (result.IsSuccess) { result2 = siemensS7Net.Write("DB103.8", (short) 1); if (result2.IsSuccess) { resultData.put("result", "success"); } } } else if (commandObj.getInteger("mode") == 4) { //小车换层 short[] array = new short[4]; array[0] = commandObj.getShort("taskNO");//任务号 array[1] = commandObj.getShort("mode");//任务模式 array[2] = commandObj.getShort("pick");//取货数据 array[3] = commandObj.getShort("put");//放货数据 resultData.put("commandData", array); result = siemensS7Net.Write("DB103.0", array); if (result.IsSuccess) { result2 = siemensS7Net.Write("DB103.8", (short) 1); if (result2.IsSuccess) { resultData.put("result", "success"); } } } else if (commandObj.getInteger("mode") == 5) { //提升机移动 short[] array = new short[4]; array[0] = commandObj.getShort("taskNO");//任务号 array[1] = commandObj.getShort("mode");//任务模式 array[2] = commandObj.getShort("pick");//取货数据 array[3] = commandObj.getShort("put");//放货数据 resultData.put("commandData", array); result = siemensS7Net.Write("DB103.0", array); if (result.IsSuccess) { result2 = siemensS7Net.Write("DB103.8", (short) 1); if (result2.IsSuccess) { resultData.put("result", "success"); } } } else if (commandObj.getInteger("mode") == 9996) { //复位 short[] array = new short[1]; array[0] = 1; resultData.put("commandData", array); result = siemensS7Net.Write("DB103.10", array); if (result.IsSuccess) { resultData.put("result", "success"); } } else if (commandObj.getInteger("mode") == 9997) { //切换入库模式 short[] array = new short[1]; array[0] = 1; resultData.put("commandData", array); result = siemensS7Net.Write("DB103.12", array); if (result.IsSuccess) { resultData.put("result", "success"); } } else if (commandObj.getInteger("mode") == 9998) { //切换出库模式 short[] array = new short[1]; array[0] = 2; resultData.put("commandData", array); result = siemensS7Net.Write("DB103.12", array); if (result.IsSuccess) { resultData.put("result", "success"); } } else if (commandObj.getInteger("mode") == 9999) { //读取状态 JSONObject device = new JSONObject(); OperateResultExOne<byte[]> readResult1 = siemensS7Net.Read("DB101.0", (short) 18); if (readResult1.IsSuccess) { //模式 device.put("model", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 0)); //PLC任务号 device.put("wrkNo", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 2)); //任务状态 device.put("protocolStatus", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 4)); //任务模式 device.put("taskMode", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 6)); //取货数据 device.put("pick", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 8)); //放货数据 device.put("put", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 10)); //出入库模式 device.put("iOMode", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 12)); //故障码 device.put("errorCode", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 14)); //层 device.put("lev", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 16)); resultData.put("deviceStatus", device); } //站点个数 int staCount = 4; //读取托盘数据 List<Integer> trayList = new ArrayList<>(); OperateResultExOne<byte[]> readResult2 = siemensS7Net.Read("DB102.0", (short) (staCount * 2)); if(readResult2.IsSuccess) { for (int i = 0; i < staCount; i++) { short val = siemensS7Net.getByteTransform().TransInt16(readResult2.Content, i * 2); trayList.add((int) val); } } //读取小车数据 OperateResultExOne<byte[]> readResult3 = siemensS7Net.Read("DB102.50", (short) (staCount * 2)); List<Integer> carList = new ArrayList<>(); if(readResult3.IsSuccess) { for (int i = 0; i < staCount; i++) { short val = siemensS7Net.getByteTransform().TransInt16(readResult3.Content, i * 2); carList.add((int) val); } } device.put("trayList", trayList); device.put("carList", carList); deviceMsgType = "status"; } resultData.put("commandResult1", JSON.toJSONString(result)); resultData.put("commandResult2", JSON.toJSONString(result2)); if (deviceMsgType.equals("command")) { log.info("收到Rcs ForkLift Command Data: {}", JSON.toJSONString(deviceCommandMsg)); } DeviceMsgModel deviceMsgModel = new DeviceMsgModel(); deviceMsgModel.setDeviceId(deviceConfig.getDeviceNo()); deviceMsgModel.setDeviceMsgType(deviceMsgType); deviceMsgModel.setDeviceMsg(JSON.toJSONString(resultData)); deviceMsgModel.setDeviceOriginMsg(JSON.toJSONString(resultData)); deviceMsgModel.setResultKey(deviceCommandMsg.getResultKey()); deviceMsgUtils.sendDeviceMsg(SlaveType.ForkLift, deviceConfig.getDeviceNo(), deviceMsgModel); } @Override public DeviceConfig getDeviceConfig() { return this.deviceConfig; } /** * 扩展字段 */ @Data private class InnerForkLiftExtend { } } src/main/resources/application.yml
@@ -1,5 +1,5 @@ server: port: 9099 port: 9098 servlet: context-path: /@pom.build.finalName@