Commit 2d47c04f authored by wanghao's avatar wanghao

1 指令指令完成,但是 没有检测到机械臂完成。

parent 3214dfa3
......@@ -105,6 +105,12 @@ public class RobotArmCommandController extends BaseController
return AjaxResult.success("上电操作成功");
}
@GetMapping("/sureCompletedCommand/{robotArmCommandId}")
public AjaxResult sureCompletedCommand(@PathVariable("robotArmCommandId") Long robotArmCommandId) {
return robotArmCommandService.sureCompletedCommand(robotArmCommandId);
}
/**
* 修改机械臂指令
*/
......
......@@ -125,6 +125,28 @@ public class NettyUdpServerHandler extends SimpleChannelInboundHandler<DatagramP
}
}
/**
* 仅处理已完成的指令
*/
public void onlyCompleted() {
CommandExecution execution = currentCommands.get("127.0.0.1");
// 如果指令追踪为空,则可能是 刚启动,再去 查一下有没有正在执行的任务
if(execution == null) {
List<RobotArmCommand> robotArmCommands = robotArmCommandService.selectTopRunningRobotArmCommands();
if(robotArmCommands != null && !robotArmCommands.isEmpty()) {
// 注册指令跟踪
execution = new CommandExecution();
execution.commandId = robotArmCommands.get(0).getRobotArmCommandId();
}
}
if (execution != null) {
robotArmCommandService.completeCommand(execution.commandId);
currentCommands.remove("127.0.0.1");
log.info("指令完成: {}", execution.commandId);
}
}
private void processStatusMessage(RobotArmMessageParser.RobotArmStatus status, SocketAddress sender) {
// 更新前端状态
if (status.isBusy()) {
......
package com.zehong.system.service;
import java.util.List;
import com.zehong.common.core.domain.AjaxResult;
import com.zehong.system.domain.RobotArmCommand;
/**
......@@ -42,6 +44,13 @@ public interface IRobotArmCommandService
public int insertRobotArmCommand(RobotArmCommand robotArmCommand);
public void powerOnCommand(Long commandId);
/**
* 确认完成指令
* @param commandId c
* @return r
*/
public AjaxResult sureCompletedCommand(Long commandId);
/**
* 修改机械臂指令
*
......
......@@ -10,6 +10,7 @@ import java.util.List;
import com.serotonin.modbus4j.ModbusMaster;
import com.serotonin.modbus4j.exception.ModbusInitException;
import com.serotonin.modbus4j.exception.ModbusTransportException;
import com.zehong.common.core.domain.AjaxResult;
import com.zehong.common.utils.DateUtils;
import com.zehong.common.utils.StringUtils;
import com.zehong.system.domain.TEquipmentInfo;
......@@ -71,7 +72,6 @@ public class RobotArmCommandServiceImpl implements IRobotArmCommandService
@Value("${robot.arm.udp.port}")
private int robotArmPort;
@Resource
private ApplicationEventPublisher eventPublisher; // 新增事件发布器
......@@ -383,6 +383,34 @@ public class RobotArmCommandServiceImpl implements IRobotArmCommandService
return i;
}
/**
* 修改机械臂指令
*
* @param commandId 机械臂指令
* @return 结果
*/
@Override
public AjaxResult sureCompletedCommand(Long commandId) {
if(commandId == null) {
return AjaxResult.error("参数错误");
}
RobotArmCommand command = robotArmCommandMapper.selectRobotArmCommandById(commandId);
if (command == null) {
return AjaxResult.error("指令不存在");
}
if(!"1".equals(command.getStatus())) {
return AjaxResult.error("只有待执行状态的指令才能确认完成");
}
try {
nettyUdpServerHandler.onlyCompleted();
} catch (Exception e) {
return AjaxResult.error("执行确认完成指令时发生异常: " + e.getMessage());
}
return AjaxResult.success();
}
@Override
@Transactional
public void powerOnCommand(Long commandId) {
......
......@@ -62,6 +62,13 @@ export function powerOnCommand(commandId) {
})
}
export function sureCompletedCommand(commandId) {
return request({
url: '/robotArm/command/sureCompletedCommand/' + commandId,
method: 'get'
})
}
// 修改机械臂指令
export function updateCommand(data) {
return request({
......
......@@ -147,12 +147,32 @@
</div>
</div>
</div>
<!-- 确认执行完成对话框 -->
<div class="dialog-mask" v-if="showSureCompleteDialog" @click.self="closePowerOnDialog">
<div class="dialog-container">
<div class="dialog-header">确认执行完成</div>
<div class="dialog-body">
<div class="dialog-content">
<div class="scan-prompt">确认此条指令执行完成?</div>
<div class="power-on-info">
<div><span class="label">托盘编号:</span> {{ selectedCommand.trayCode }}</div>
<div><span class="label">位置:</span> {{ selectedCommand.position }}</div>
</div>
</div>
</div>
<div class="dialog-footer">
<button class="cancel-button" @click="closeSureCompleteDialog">取消</button>
<button class="confirm-button" @click="confirmSureComplete">确认上电</button>
</div>
</div>
</div>
</div>
</template>
<script>
import {addCommand,powerOnCommand,sendHomeCommand,sendStopCommand} from "@/api/robotArm/robotArmCommand"
import {addCommand,powerOnCommand,sendHomeCommand,sendStopCommand,sureCompletedCommand} from "@/api/robotArm/robotArmCommand"
export default {
name: 'RoboticArm',
......@@ -168,6 +188,7 @@ export default {
websocket: null,
reconnectInterval: null,
showPowerOnDialog: false,
showSureCompleteDialog: false,
selectedCommand: null
};
},
......@@ -368,14 +389,34 @@ export default {
if (cmd.status === '3') {
this.selectedCommand = cmd;
this.showPowerOnDialog = true;
} else if(cmd.status === '2') {
this.selectedCommand = cmd;
this.showSureCompleteDialog = true;
}
},
closeSureCompleteDialog() {
this.showSureCompleteDialog = false;
this.selectedCommand = null;
},
closePowerOnDialog() {
this.showPowerOnDialog = false;
this.selectedCommand = null;
},
confirmSureComplete() {
if (!this.selectedCommand) return;
sureCompletedCommand(this.selectedCommand.robotArmCommandId).then(res => {
if(res.code === 200) {
this.msgSuccess("确认完成成功");
this.closeSureCompleteDialog();
} else {
this.msgError("确认完成失败");
}
}).catch(err => {
this.msgError("确认完成失败");
})
},
confirmPowerOn() {
if (!this.selectedCommand) return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment