| | |
| | | JSONObject commandObj = JSON.parseObject(command); |
| | | |
| | | HashMap<String, Object> resultData = new HashMap<>(); |
| | | resultData.put("result", "false"); |
| | | resultData.put("result", "success"); |
| | | |
| | | String deviceMsgType = "command"; |
| | | OperateResult result = null; |
| | | OperateResult result2 = null; |
| | | if (commandObj.getInteger("mode") == 3) { |
| | | if (commandObj.getInteger("mode") == 1) { |
| | | //取放货 |
| | | short[] array = new short[4]; |
| | | array[0] = 1;//任务类型 |
| | |
| | | array[3] = commandObj.getShort("taskNo");//任务号 |
| | | resultData.put("commandData", array); |
| | | |
| | | result = siemensS7Net.Write("DB83.0", array); |
| | | OperateResult result = siemensS7Net.Write("DB83.0", array); |
| | | if (result.IsSuccess) { |
| | | resultData.put("result", "success"); |
| | | } |
| | | |
| | | resultData.put("commandResult1", JSON.toJSONString(result)); |
| | | } else if (commandObj.getInteger("mode") == 4) { |
| | | } else if (commandObj.getInteger("mode") == 2) { |
| | | //小车换层 |
| | | short[] array = new short[4]; |
| | | array[0] = 2;//任务类型 |
| | |
| | | array[3] = commandObj.getShort("taskNo");//任务号 |
| | | resultData.put("commandData", array); |
| | | |
| | | result = siemensS7Net.Write("DB83.0", array); |
| | | OperateResult result = siemensS7Net.Write("DB83.0", array); |
| | | if (result.IsSuccess) { |
| | | resultData.put("result", "success"); |
| | | } |
| | | |
| | | resultData.put("commandResult1", JSON.toJSONString(result)); |
| | | } else if (commandObj.getInteger("mode") == 5) { |
| | | } else if (commandObj.getInteger("mode") == 3) { |
| | | //提升机移动 |
| | | short[] array = new short[4]; |
| | | array[0] = 2;//任务类型 |
| | |
| | | array[3] = commandObj.getShort("taskNo");//任务号 |
| | | resultData.put("commandData", array); |
| | | |
| | | result = siemensS7Net.Write("DB83.0", array); |
| | | OperateResult result = siemensS7Net.Write("DB83.0", array); |
| | | if (result.IsSuccess) { |
| | | resultData.put("result", "success"); |
| | | } |
| | | |
| | | resultData.put("commandResult1", JSON.toJSONString(result)); |
| | | } else if (commandObj.getInteger("mode") == 9996) { |
| | | //复位 |
| | | short[] array = new short[1]; |
| | | array[0] = 1; |
| | | resultData.put("commandData", array); |
| | | |
| | | result = siemensS7Net.Write("DB103.10", array); |
| | | OperateResult result = siemensS7Net.Write("DB103.10", array); |
| | | if (result.IsSuccess) { |
| | | resultData.put("result", "success"); |
| | | } |
| | | |
| | | resultData.put("commandResult1", JSON.toJSONString(result)); |
| | | resultData.put("commandResult2", JSON.toJSONString(result2)); |
| | | } else if (commandObj.getInteger("mode") == 9997) { |
| | | //切换入库模式 |
| | | short[] array = new short[1]; |
| | | array[0] = 1; |
| | | resultData.put("commandData", array); |
| | | |
| | | result = siemensS7Net.Write("DB103.12", array); |
| | | OperateResult result = siemensS7Net.Write("DB103.12", array); |
| | | if (result.IsSuccess) { |
| | | resultData.put("result", "success"); |
| | | } |
| | | |
| | | resultData.put("commandResult1", JSON.toJSONString(result)); |
| | | resultData.put("commandResult2", JSON.toJSONString(result2)); |
| | | } else if (commandObj.getInteger("mode") == 9998) { |
| | | //切换出库模式 |
| | | short[] array = new short[1]; |
| | | array[0] = 2; |
| | | resultData.put("commandData", array); |
| | | |
| | | result = siemensS7Net.Write("DB103.12", array); |
| | | OperateResult result = siemensS7Net.Write("DB103.12", array); |
| | | if (result.IsSuccess) { |
| | | resultData.put("result", "success"); |
| | | } |
| | | |
| | | resultData.put("commandResult1", JSON.toJSONString(result)); |
| | | resultData.put("commandResult2", JSON.toJSONString(result2)); |
| | | } else if (commandObj.getInteger("mode") == 9999) { |
| | | //读取状态 |
| | | JSONObject device = new JSONObject(); |
| | |
| | | //模式 |
| | | device.put("model", status1[0] ? 2 : 1); |
| | | //PLC任务号 |
| | | device.put("wrkNo", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 6)); |
| | | device.put("plcTaskNo", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 6)); |
| | | //设备状态 |
| | | device.put("deviceStatus", status1[0] ? 0 : 1); |
| | | device.put("deviceStatus", status1[1] ? 0 : 1); |
| | | //任务模式 |
| | | device.put("taskMode", 0); |
| | | //取货数据 |
| | |
| | | extend.put("overHeight", status2[0] ? 1 : 0); |
| | | //超重 |
| | | extend.put("overWeight", status2[1] ? 1 : 0); |
| | | //PLC已完成任务号 |
| | | extend.put("plcTaskNoComplete", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 10)); |
| | | |
| | | resultData.put("deviceStatus", device); |
| | | } |
| | |
| | | int i = 0; |
| | | for (Integer siteId : staList) { |
| | | //读取4.0-4.7数据 |
| | | boolean[] status1 = siemensS7Net.getByteTransform().TransBool(readResult2.Content, i*26, 1); |
| | | boolean[] status1 = siemensS7Net.getByteTransform().TransBool(readResult2.Content, i * 26, 1); |
| | | //读取5.0-5.7数据 |
| | | boolean[] status2 = siemensS7Net.getByteTransform().TransBool(readResult2.Content, i*26 + 1, 1); |
| | | boolean[] status2 = siemensS7Net.getByteTransform().TransBool(readResult2.Content, i * 26 + 1, 1); |
| | | String barcode = siemensS7Net.getByteTransform().TransString(readResult2.Content, i * 26 + 10, 12, "UTF-8"); |
| | | |
| | | JSONObject station = new JSONObject(); |
| | |
| | | station.put("model", status1[0] ? 1 : 0); |
| | | station.put("busy", status1[1] ? 1 : 0); |
| | | station.put("hasTray", status1[2] ? 1 : 0); |
| | | station.put("inMode", status1[3] ? 1 : 0); |
| | | station.put("outMode", status1[4] ? 1 : 0); |
| | | station.put("allowShuttleTake", status2[5] ? 1 : 0); |
| | | station.put("allowShuttlePut", status2[6] ? 1 : 0); |
| | | station.put("deviceError", status2[7] ? 1 : 0); |
| | | station.put("taskNo", (int) siemensS7Net.getByteTransform().TransInt16(readResult2.Content, i*26 + 2)); |
| | | station.put("staNo", (int) siemensS7Net.getByteTransform().TransInt16(readResult2.Content, i*28 + 2)); |
| | | station.put("taskNo", (int) siemensS7Net.getByteTransform().TransInt16(readResult2.Content, i * 26 + 2)); |
| | | station.put("staNo", (int) siemensS7Net.getByteTransform().TransInt16(readResult2.Content, i * 28 + 2)); |
| | | station.put("barcode", barcode); |
| | | stationList.add(station); |
| | | i++; |
| | | } |
| | | } |
| | | |
| | | device.put("stationList", stationList); |
| | | |
| | | resultData.put("commandResult1", JSON.toJSONString(readResult1.Content)); |
| | | resultData.put("commandResult2", JSON.toJSONString(readResult2.Content)); |
| | | resultData.put("commandResult1", readResult1.Content); |
| | | resultData.put("commandResult2", readResult2.Content); |
| | | |
| | | deviceMsgType = "status"; |
| | | } else if (commandObj.getInteger("mode") == 10000) { |
| | | //写入输送线数据 |
| | | |
| | | JSONObject commandBody = commandObj.getJSONObject("commandBody"); |
| | | Integer siteId = commandBody.getInteger("siteId"); |
| | | Integer staNo = commandBody.getInteger("staNo"); |
| | | Integer taskNo = commandBody.getInteger("taskNo"); |
| | | String address = commandBody.getString("address"); |
| | | Integer siteId = commandObj.getInteger("siteId"); |
| | | Integer staNo = commandObj.getInteger("staNo"); |
| | | Integer taskNo = commandObj.getInteger("taskNo"); |
| | | String address = commandObj.getString("address"); |
| | | |
| | | short[] array = new short[2]; |
| | | array[0] = staNo.shortValue();//目标站 |
| | |
| | | |
| | | resultData.put("commandData", array); |
| | | |
| | | result = siemensS7Net.Write("address", array); |
| | | OperateResult result = siemensS7Net.Write(address, array); |
| | | if (result.IsSuccess) { |
| | | resultData.put("result", "success"); |
| | | } |
| | | |
| | | resultData.put("commandResult1", JSON.toJSONString(result)); |
| | | } |
| | | |
| | | if (deviceMsgType.equals("command")) { |
| | |
| | | DeviceMsgModel deviceMsgModel = new DeviceMsgModel(); |
| | | deviceMsgModel.setDeviceId(deviceConfig.getDeviceNo()); |
| | | deviceMsgModel.setDeviceMsgType(deviceMsgType); |
| | | deviceMsgModel.setDeviceMsg(JSON.toJSONString(resultData)); |
| | | deviceMsgModel.setDeviceMsg(resultData); |
| | | deviceMsgModel.setDeviceOriginMsg(JSON.toJSONString(resultData)); |
| | | deviceMsgModel.setResultKey(deviceCommandMsg.getResultKey()); |
| | | deviceMsgUtils.sendDeviceMsg(SlaveType.Lift, deviceConfig.getDeviceNo(), deviceMsgModel); |